diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-08 19:27:41 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-08 19:27:41 -0500 |
commit | 496530c85c3848c04fcafa912d11b0f1991777c1 (patch) | |
tree | 646ff12f0d9091f66560c84c69964219796a34ec /apps/accelerometer-test | |
parent | 6be308f88dbb55a93b9ca2ab7a2a0fbdc5198324 (diff) | |
download | Sensor-Watch-496530c85c3848c04fcafa912d11b0f1991777c1.tar.gz Sensor-Watch-496530c85c3848c04fcafa912d11b0f1991777c1.tar.bz2 Sensor-Watch-496530c85c3848c04fcafa912d11b0f1991777c1.zip |
add driver, test app for LIS2DW accelerometer
Diffstat (limited to 'apps/accelerometer-test')
-rw-r--r-- | apps/accelerometer-test/app.c | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/apps/accelerometer-test/app.c b/apps/accelerometer-test/app.c index 8bd6537e..bfef132c 100644 --- a/apps/accelerometer-test/app.c +++ b/apps/accelerometer-test/app.c @@ -3,21 +3,15 @@ #include <stdlib.h> #include <math.h> #include "watch.h" -#include "lis2dh.h" +#include "lis2dw.h" -// This application displays data from the old Sensor Watch Motion sensor board. -// Note that this board required A0 to be set high to power the sensor. -// Future accelerometer boards will be powered directly from VCC. -// Also note that this board has its INT1 pin wired to A1, which is not an external -// wake pin. Future accelerometer boards will wire interrupt pins to A2 and A4. - -void cb_light_pressed(void) { +static void cb_light_pressed(void) { } -void cb_mode_pressed(void) { +static void cb_mode_pressed(void) { } -void cb_alarm_pressed(void) { +static void cb_alarm_pressed(void) { } uint8_t interrupts = 0; @@ -25,23 +19,16 @@ uint8_t last_interrupts = 0; uint8_t ticks = 0; char buf[13] = {0}; -void cb_interrupt_1(void) { - interrupts++; -} +static void cb_tick(void) { + if (!lis2dw_have_new_data()) return; -void cb_tick(void) { - if (++ticks == 30) { - last_interrupts = interrupts; - interrupts = 0; - ticks = 0; - } + lis2dw_reading raw_reading; + lis2dw_acceleration_measurement measurement = lis2dw_get_acceleration_measurement(&raw_reading); + (void)measurement; + printf("%d, %d, %d\n", raw_reading.x, raw_reading.y, raw_reading.z); } void app_init(void) { - gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT); - gpio_set_pin_function(A0, GPIO_PIN_FUNCTION_OFF); - gpio_set_pin_level(A0, true); - watch_enable_display(); watch_display_string("IN 0 0 0", 0); @@ -51,17 +38,9 @@ void app_init(void) { watch_register_interrupt_callback(BTN_ALARM, cb_alarm_pressed, INTERRUPT_TRIGGER_RISING); watch_enable_i2c(); + lis2dw_begin(); - lis2dh_begin(); - lis2dh_set_data_rate(LIS2DH_DATA_RATE_10_HZ); - lis2dh_configure_aoi_int1( - LIS2DH_INTERRUPT_CONFIGURATION_OR | - LIS2DH_INTERRUPT_CONFIGURATION_X_HIGH_ENABLE | - LIS2DH_INTERRUPT_CONFIGURATION_Y_HIGH_ENABLE | - LIS2DH_INTERRUPT_CONFIGURATION_Z_HIGH_ENABLE, 96, 0, true); - - watch_register_interrupt_callback(A1, cb_interrupt_1, INTERRUPT_TRIGGER_RISING); - watch_rtc_register_tick_callback(cb_tick); + watch_rtc_register_periodic_callback(cb_tick, 16); } void app_wake_from_backup(void) { @@ -77,6 +56,7 @@ void app_wake_from_standby(void) { } bool app_loop(void) { + // TODO: interrupt configuration for LIS2DW sprintf(buf, "IN%2d%3d%3d", ticks, interrupts, last_interrupts); watch_display_string(buf, 0); |