2021-11-28 02:32:15 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "watch.h"
|
2022-01-09 08:27:41 +08:00
|
|
|
#include "lis2dw.h"
|
2021-11-28 02:32:15 +08:00
|
|
|
|
2022-01-09 08:27:41 +08:00
|
|
|
static void cb_light_pressed(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2022-01-09 08:27:41 +08:00
|
|
|
static void cb_mode_pressed(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2022-01-09 08:27:41 +08:00
|
|
|
static void cb_alarm_pressed(void) {
|
2021-12-01 07:53:43 +08:00
|
|
|
}
|
|
|
|
|
2021-12-01 09:20:21 +08:00
|
|
|
uint8_t interrupts = 0;
|
|
|
|
uint8_t last_interrupts = 0;
|
2022-02-18 22:53:22 +08:00
|
|
|
bool tick = false;
|
2021-12-01 09:20:21 +08:00
|
|
|
char buf[13] = {0};
|
2021-12-01 07:53:43 +08:00
|
|
|
|
2022-01-09 08:27:41 +08:00
|
|
|
static void cb_tick(void) {
|
|
|
|
if (!lis2dw_have_new_data()) return;
|
2021-12-01 07:53:43 +08:00
|
|
|
|
2022-02-18 22:53:22 +08:00
|
|
|
tick = true;
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-12-06 13:49:26 +08:00
|
|
|
void app_init(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
watch_enable_display();
|
2022-01-10 04:26:45 +08:00
|
|
|
watch_display_string("AC Strean", 0);
|
2021-11-28 02:32:15 +08:00
|
|
|
|
|
|
|
watch_enable_external_interrupts();
|
|
|
|
watch_register_interrupt_callback(BTN_MODE, cb_mode_pressed, INTERRUPT_TRIGGER_RISING);
|
|
|
|
watch_register_interrupt_callback(BTN_LIGHT, cb_light_pressed, INTERRUPT_TRIGGER_RISING);
|
|
|
|
watch_register_interrupt_callback(BTN_ALARM, cb_alarm_pressed, INTERRUPT_TRIGGER_RISING);
|
|
|
|
|
|
|
|
watch_enable_i2c();
|
2022-01-09 08:27:41 +08:00
|
|
|
lis2dw_begin();
|
2022-02-20 03:03:10 +08:00
|
|
|
lis2dw_set_data_rate(LIS2DW_DATA_RATE_25_HZ);
|
|
|
|
lis2dw_set_range(LIS2DW_RANGE_4_G);
|
|
|
|
lis2dw_set_low_noise_mode(true);
|
|
|
|
lis2dw_enable_fifo();
|
2022-02-18 05:36:21 +08:00
|
|
|
|
|
|
|
lis2dw_enable_fifo();
|
2021-11-28 02:32:15 +08:00
|
|
|
|
2022-02-18 05:36:21 +08:00
|
|
|
watch_rtc_register_periodic_callback(cb_tick, 1);
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-12-06 13:49:26 +08:00
|
|
|
void app_wake_from_backup(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-12-06 13:49:26 +08:00
|
|
|
void app_setup(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-12-06 13:49:26 +08:00
|
|
|
void app_prepare_for_standby(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-12-06 13:49:26 +08:00
|
|
|
void app_wake_from_standby(void) {
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-12-06 13:49:26 +08:00
|
|
|
bool app_loop(void) {
|
2022-02-18 22:53:22 +08:00
|
|
|
if (tick) {
|
|
|
|
tick = false;
|
|
|
|
lis2dw_fifo_t fifo;
|
|
|
|
lis2dw_read_fifo(&fifo);
|
|
|
|
for(int i = 0; i < fifo.count; i++) {
|
|
|
|
printf("%d, %d, %d, %d, %d\n", fifo.readings[i].x, fifo.readings[i].y, fifo.readings[i].z, i, fifo.count);
|
|
|
|
}
|
|
|
|
}
|
2021-11-28 02:32:15 +08:00
|
|
|
|
2021-12-01 07:53:43 +08:00
|
|
|
return true;
|
2021-11-28 02:32:15 +08:00
|
|
|
}
|