diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-10-05 17:58:49 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-10-05 18:03:49 -0400 |
commit | 0f349cb52e7436303f61a3dd2dde2f40d3dc05c3 (patch) | |
tree | 68bf1cbbbeb9f353caed324f603a3dcc82ee93e5 /launcher | |
parent | 8372e37bea5313a131054081e84fe7e9a45f32a9 (diff) | |
download | Sensor-Watch-0f349cb52e7436303f61a3dd2dde2f40d3dc05c3.tar.gz Sensor-Watch-0f349cb52e7436303f61a3dd2dde2f40d3dc05c3.tar.bz2 Sensor-Watch-0f349cb52e7436303f61a3dd2dde2f40d3dc05c3.zip |
add pulseometer widget
Diffstat (limited to 'launcher')
-rw-r--r-- | launcher/launcher_config.h | 1 | ||||
-rwxr-xr-x | launcher/make/Makefile | 2 | ||||
-rw-r--r-- | launcher/widgets/complications/pulseometer_widget.c | 83 | ||||
-rw-r--r-- | launcher/widgets/complications/pulseometer_widget.h | 24 |
4 files changed, 110 insertions, 0 deletions
diff --git a/launcher/launcher_config.h b/launcher/launcher_config.h index ab0f6ea3..5280b989 100644 --- a/launcher/launcher_config.h +++ b/launcher/launcher_config.h @@ -4,6 +4,7 @@ #include "simple_clock_widget.h" #include "preferences_widget.h" #include "set_time_widget.h" +#include "pulseometer_widget.h" #include "fake_widget_1.h" #include "fake_widget_2.h" diff --git a/launcher/make/Makefile b/launcher/make/Makefile index 2f35f58c..c6d18137 100755 --- a/launcher/make/Makefile +++ b/launcher/make/Makefile @@ -13,6 +13,7 @@ INCLUDES += \ -I../widgets/ \ -I../widgets/clock/ \ -I../widgets/settings/ \ + -I../widgets/complications/ \ # If you add any other source files you wish to compile, add them after ../app.c # Note that you will need to add a backslash at the end of any line you wish to continue, i.e. @@ -25,6 +26,7 @@ SRCS += \ ../widgets/clock/simple_clock_widget.c \ ../widgets/settings/preferences_widget.c \ ../widgets/settings/set_time_widget.c \ + ../widgets/complications/pulseometer_widget.c \ ../widgets/fake_widget_1.c \ ../widgets/fake_widget_2.c \ diff --git a/launcher/widgets/complications/pulseometer_widget.c b/launcher/widgets/complications/pulseometer_widget.c new file mode 100644 index 00000000..3df1cb44 --- /dev/null +++ b/launcher/widgets/complications/pulseometer_widget.c @@ -0,0 +1,83 @@ +#include <stdlib.h> +#include <string.h> +#include "pulseometer_widget.h" +#include "watch.h" + +void pulseometer_widget_setup(LauncherSettings *settings, void ** context_ptr) { + (void) settings; + if (*context_ptr == NULL) *context_ptr = malloc(sizeof(PulsometerState)); +} + +void pulseometer_widget_activate(LauncherSettings *settings, void *context) { + (void) settings; + memset(context, 0, sizeof(PulsometerState)); +} + +bool pulseometer_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) { + printf("pulseometer_widget_loop\n"); + (void) settings; + PulsometerState *pulsometer_state = (PulsometerState *)context; + char buf[14]; + // starts at index 15 + const uint8_t pulse_lookup[] = {240, 225, 212, 200, 189, 180, 171, 164, 157, 150, 144, 138, 133, 129, 124, 120, 116, 113, 109, 106, 103, 100, 97, 95, 92, 90, 88, 86, 84, 82, 80, 78, 77, 75, 73, 72, 71, 69, 68, 67, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 55, 54, 53, 52, 51, 51, 50, 49, 49, 48, 47, 47, 46, 46, 45, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 40}; + switch (event.bit.event_type) { + case EVENT_TICK: + if (pulsometer_state->pulse == 0 && !pulsometer_state->measuring) { + switch (pulsometer_state->ticks % 5) { + case 0: + watch_display_string(" Hold ", 2); + break; + case 1: + watch_display_string(" Alarn", 4); + break; + case 2: + watch_display_string("+ Count ", 0); + break; + case 3: + watch_display_string(" 30Beats ", 0); + break; + case 4: + watch_clear_display(); + break; + } + pulsometer_state->ticks++; + } else { + if (pulsometer_state->ticks < 15) { + watch_display_string(" Lo", 0); + } else if (pulsometer_state->ticks > 91) { + watch_display_string(" Hi", 0); + } else { + if (pulsometer_state->measuring) pulsometer_state->pulse = pulse_lookup[pulsometer_state->ticks - 15]; + sprintf(buf, " %-3dbpn", pulsometer_state->pulse); + watch_display_string(buf, 0); + } + if (pulsometer_state->measuring) pulsometer_state->ticks++; + } + return false; + case EVENT_MODE_BUTTON_UP: + launcher_move_to_next_widget(); + return false; + case EVENT_LIGHT_BUTTON_UP: + launcher_illuminate_led(); + break; + case EVENT_ALARM_BUTTON_DOWN: + pulsometer_state->ticks = 0; + pulsometer_state->measuring = true; + launcher_request_tick_frequency(2); + break; + case EVENT_ALARM_BUTTON_UP: + case EVENT_ALARM_LONG_PRESS: + pulsometer_state->measuring = false; + launcher_request_tick_frequency(1); + break; + default: + break; + } + + return true; +} + +void pulseometer_widget_resign(LauncherSettings *settings, void *context) { + (void) settings; + (void) context; +} diff --git a/launcher/widgets/complications/pulseometer_widget.h b/launcher/widgets/complications/pulseometer_widget.h new file mode 100644 index 00000000..5b18d7f3 --- /dev/null +++ b/launcher/widgets/complications/pulseometer_widget.h @@ -0,0 +1,24 @@ +#ifndef PULSEOMETER_WIDGET_H_ +#define PULSEOMETER_WIDGET_H_ + +#include "launcher.h" + +typedef struct { + bool measuring; + int16_t pulse; + int16_t ticks; +} PulsometerState; + +void pulseometer_widget_setup(LauncherSettings *settings, void ** context_ptr); +void pulseometer_widget_activate(LauncherSettings *settings, void *context); +bool pulseometer_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context); +void pulseometer_widget_resign(LauncherSettings *settings, void *context); + +#define pulseometer_widget { \ + pulseometer_widget_setup, \ + pulseometer_widget_activate, \ + pulseometer_widget_loop, \ + pulseometer_widget_resign, \ +} + +#endif // PULSEOMETER_WIDGET_H_
\ No newline at end of file |