move accelerometer and light to sensor, not demo folder
This commit is contained in:
130
watch-faces/sensor/accelerometer_status_face.c
Normal file
130
watch-faces/sensor/accelerometer_status_face.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Joey Castillo
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "accelerometer_status_face.h"
|
||||
#include "lis2dw.h"
|
||||
#include "tc.h"
|
||||
#include "watch.h"
|
||||
|
||||
static void _accelerometer_status_face_update_display(accel_interrupt_count_state_t *state) {
|
||||
(void) state;
|
||||
|
||||
// Accelerometer title
|
||||
watch_display_text_with_fallback(WATCH_POSITION_TOP, "ACCEL", "AC");
|
||||
|
||||
// sensing is live!
|
||||
watch_set_indicator(WATCH_INDICATOR_SIGNAL);
|
||||
|
||||
// Sleep/active state
|
||||
if (HAL_GPIO_A4_read()) watch_display_text(WATCH_POSITION_BOTTOM, "Still ");
|
||||
else watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, "Active", " ACtiv");
|
||||
}
|
||||
|
||||
void accelerometer_status_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(accel_interrupt_count_state_t));
|
||||
memset(*context_ptr, 0, sizeof(accel_interrupt_count_state_t));
|
||||
}
|
||||
}
|
||||
|
||||
void accelerometer_status_face_activate(void *context) {
|
||||
accel_interrupt_count_state_t *state = (accel_interrupt_count_state_t *)context;
|
||||
|
||||
// never in settings mode at the start
|
||||
state->is_setting = false;
|
||||
|
||||
// update more quickly to catch changes, also to blink setting
|
||||
movement_request_tick_frequency(4);
|
||||
|
||||
// fetch current threshold from accelerometer
|
||||
state->threshold = lis2dw_get_wakeup_threshold();
|
||||
}
|
||||
|
||||
bool accelerometer_status_face_loop(movement_event_t event, void *context) {
|
||||
accel_interrupt_count_state_t *state = (accel_interrupt_count_state_t *)context;
|
||||
|
||||
if (state->is_setting) {
|
||||
watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
|
||||
switch (event.event_type) {
|
||||
case EVENT_LIGHT_BUTTON_DOWN:
|
||||
state->new_threshold = (state->new_threshold + 1) % 64;
|
||||
// fall through
|
||||
case EVENT_TICK:
|
||||
{
|
||||
char buf[11];
|
||||
if (event.subsecond % 2) {
|
||||
watch_display_text(WATCH_POSITION_BOTTOM, " ");
|
||||
} else {
|
||||
watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
|
||||
watch_display_text_with_fallback(WATCH_POSITION_TOP, "WAKth", "TH");
|
||||
watch_display_float_with_best_effort(state->new_threshold * 0.03125, " G");
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
lis2dw_configure_wakeup_threshold(state->new_threshold);
|
||||
state->threshold = state->new_threshold;
|
||||
state->is_setting = false;
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
movement_move_to_face(0);
|
||||
break;
|
||||
default:
|
||||
movement_default_loop_handler(event);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
case EVENT_TICK:
|
||||
_accelerometer_status_face_update_display(state);
|
||||
break;
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
// start tick animation if necessary
|
||||
if (!watch_sleep_animation_is_running()) watch_start_sleep_animation(1000);
|
||||
// update the display
|
||||
_accelerometer_status_face_update_display(state);
|
||||
// on classic LCD, clear seconds since they interfere with the sleep animation.
|
||||
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CLASSIC) watch_display_text(WATCH_POSITION_SECONDS, " ");
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
state->new_threshold = state->threshold;
|
||||
state->is_setting = true;
|
||||
return false;
|
||||
default:
|
||||
movement_default_loop_handler(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void accelerometer_status_face_resign(void *context) {
|
||||
(void) context;
|
||||
}
|
||||
55
watch-faces/sensor/accelerometer_status_face.h
Normal file
55
watch-faces/sensor/accelerometer_status_face.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2022 Joey Castillo
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Accelerometer Interrupt Counter
|
||||
*
|
||||
* This is an experimental watch face for counting the number of interrupts that
|
||||
* the Sensor Watch Motion acceleromoeter board fires. I expect it will be removed
|
||||
* once we integrate accelerometer functionality more deeply into Movement.
|
||||
*/
|
||||
|
||||
#include "movement.h"
|
||||
#include "watch.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t new_threshold;
|
||||
uint8_t threshold;
|
||||
bool is_setting;
|
||||
} accel_interrupt_count_state_t;
|
||||
|
||||
void accelerometer_status_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void accelerometer_status_face_activate(void *context);
|
||||
bool accelerometer_status_face_loop(movement_event_t event, void *context);
|
||||
void accelerometer_status_face_resign(void *context);
|
||||
|
||||
#define accelerometer_status_face ((const watch_face_t){ \
|
||||
accelerometer_status_face_setup, \
|
||||
accelerometer_status_face_activate, \
|
||||
accelerometer_status_face_loop, \
|
||||
accelerometer_status_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
96
watch-faces/sensor/light_sensor_face.c
Normal file
96
watch-faces/sensor/light_sensor_face.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2024 Joey Castillo
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "light_sensor_face.h"
|
||||
#include "tc.h"
|
||||
#include "eic.h"
|
||||
#include "usb.h"
|
||||
#include "adc.h"
|
||||
|
||||
#ifdef HAS_IR_SENSOR
|
||||
|
||||
void light_sensor_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(light_sensor_state_t));
|
||||
memset(*context_ptr, 0, sizeof(light_sensor_state_t));
|
||||
// Do any one-time tasks in here; the inside of this conditional happens only at boot.
|
||||
}
|
||||
}
|
||||
|
||||
void light_sensor_face_activate(void *context) {
|
||||
light_sensor_state_t *state = (light_sensor_state_t *)context;
|
||||
(void) state;
|
||||
HAL_GPIO_IR_ENABLE_out();
|
||||
HAL_GPIO_IR_ENABLE_clr();
|
||||
HAL_GPIO_IRSENSE_pmuxen(HAL_GPIO_PMUX_ADC);
|
||||
adc_init();
|
||||
adc_enable();
|
||||
movement_request_tick_frequency(8);
|
||||
}
|
||||
|
||||
bool light_sensor_face_loop(movement_event_t event, void *context) {
|
||||
light_sensor_state_t *state = (light_sensor_state_t *)context;
|
||||
(void) state;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_NONE:
|
||||
case EVENT_ACTIVATE:
|
||||
case EVENT_TICK:
|
||||
{
|
||||
char buf[14];
|
||||
uint16_t light_level = adc_get_analog_value(HAL_GPIO_IRSENSE_pin());
|
||||
snprintf(buf, 14, "LL %-6d", light_level);
|
||||
watch_display_text(WATCH_POSITION_FULL, buf);
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
break;
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
watch_display_text(WATCH_POSITION_TOP_RIGHT, " <");
|
||||
break;
|
||||
default:
|
||||
return movement_default_loop_handler(event);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void light_sensor_face_resign(void *context) {
|
||||
(void) context;
|
||||
|
||||
adc_disable();
|
||||
HAL_GPIO_IRSENSE_pmuxdis();
|
||||
HAL_GPIO_IRSENSE_off();
|
||||
HAL_GPIO_IR_ENABLE_off();
|
||||
}
|
||||
|
||||
#endif // HAS_IR_SENSOR
|
||||
56
watch-faces/sensor/light_sensor_face.h
Normal file
56
watch-faces/sensor/light_sensor_face.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2024 Joey Castillo
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
#ifdef HAS_IR_SENSOR
|
||||
|
||||
/*
|
||||
* LIGHT SENSOR PLAYGROUND
|
||||
*
|
||||
* Temporary watch face for playing with the light sensor.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
// Anything you need to keep track of, put it here!
|
||||
uint8_t unused;
|
||||
} light_sensor_state_t;
|
||||
|
||||
void light_sensor_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void light_sensor_face_activate(void *context);
|
||||
bool light_sensor_face_loop(movement_event_t event, void *context);
|
||||
void light_sensor_face_resign(void *context);
|
||||
|
||||
#define light_sensor_face ((const watch_face_t){ \
|
||||
light_sensor_face_setup, \
|
||||
light_sensor_face_activate, \
|
||||
light_sensor_face_loop, \
|
||||
light_sensor_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // HAS_IR_SENSOR
|
||||
Reference in New Issue
Block a user