add movement_get_temperature, works across different sensor boards
This commit is contained in:
parent
80cbb0fe30
commit
47fbaccc77
20
movement.c
20
movement.c
@ -560,13 +560,27 @@ bool movement_disable_tap_detection_if_available(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float movement_get_temperature(void) {
|
||||||
|
float temperature_c = (float)0xFFFFFFFF;
|
||||||
|
|
||||||
|
if (movement_state.has_thermistor) {
|
||||||
|
thermistor_driver_enable();
|
||||||
|
temperature_c = thermistor_driver_get_temperature();
|
||||||
|
thermistor_driver_disable();
|
||||||
|
} else if (movement_state.has_lis2dw) {
|
||||||
|
int16_t val = lis2dw_get_temperature();
|
||||||
|
val = val >> 4;
|
||||||
|
temperature_c = 25 + (float)val / 16.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return temperature_c;
|
||||||
|
}
|
||||||
|
|
||||||
void app_init(void) {
|
void app_init(void) {
|
||||||
_watch_init();
|
_watch_init();
|
||||||
|
|
||||||
filesystem_init();
|
filesystem_init();
|
||||||
|
|
||||||
movement_state.has_thermistor = thermistor_driver_init();
|
|
||||||
|
|
||||||
// check if we are plugged into USB power.
|
// check if we are plugged into USB power.
|
||||||
HAL_GPIO_VBUS_DET_in();
|
HAL_GPIO_VBUS_DET_in();
|
||||||
HAL_GPIO_VBUS_DET_pulldown();
|
HAL_GPIO_VBUS_DET_pulldown();
|
||||||
@ -578,6 +592,8 @@ void app_init(void) {
|
|||||||
|
|
||||||
memset(&movement_state, 0, sizeof(movement_state));
|
memset(&movement_state, 0, sizeof(movement_state));
|
||||||
|
|
||||||
|
movement_state.has_thermistor = thermistor_driver_init();
|
||||||
|
|
||||||
bool settings_file_exists = filesystem_file_exists("settings.u32");
|
bool settings_file_exists = filesystem_file_exists("settings.u32");
|
||||||
movement_settings_t maybe_settings;
|
movement_settings_t maybe_settings;
|
||||||
if (settings_file_exists && maybe_settings.bit.version == 0) {
|
if (settings_file_exists && maybe_settings.bit.version == 0) {
|
||||||
|
|||||||
@ -370,3 +370,8 @@ void movement_set_alarm_enabled(bool value);
|
|||||||
// if the board has an accelerometer, these functions will enable or disable tap detection.
|
// if the board has an accelerometer, these functions will enable or disable tap detection.
|
||||||
bool movement_enable_tap_detection_if_available(void);
|
bool movement_enable_tap_detection_if_available(void);
|
||||||
bool movement_disable_tap_detection_if_available(void);
|
bool movement_disable_tap_detection_if_available(void);
|
||||||
|
|
||||||
|
// If the board has a temperature sensor, this function will give you the temperature in degrees celsius.
|
||||||
|
// If the board has multiple temperature sensors, it will use the most accurate one available.
|
||||||
|
// If the board has no temperature sensors, it will return 0xFFFFFFFF.
|
||||||
|
float movement_get_temperature(void);
|
||||||
|
|||||||
@ -51,9 +51,7 @@ void _movement_log_data(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log the temperature
|
// log the temperature
|
||||||
thermistor_driver_enable();
|
float temperature_c = movement_get_temperature();
|
||||||
float temperature_c = thermistor_driver_get_temperature();
|
|
||||||
thermistor_driver_disable();
|
|
||||||
// offset the temperature by 30, so -30°C is 0, and 72.3°C is 102.3
|
// offset the temperature by 30, so -30°C is 0, and 72.3°C is 102.3
|
||||||
temperature_c = temperature_c + 30;
|
temperature_c = temperature_c + 30;
|
||||||
if (temperature_c < 0) temperature_c = 0;
|
if (temperature_c < 0) temperature_c = 0;
|
||||||
|
|||||||
@ -28,17 +28,13 @@
|
|||||||
#include "thermistor_driver.h"
|
#include "thermistor_driver.h"
|
||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
|
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
|
||||||
|
|
||||||
static void _temperature_display_face_update_display(bool in_fahrenheit) {
|
static void _temperature_display_face_update_display(bool in_fahrenheit) {
|
||||||
thermistor_driver_enable();
|
float temperature_c = movement_get_temperature();
|
||||||
float temperature_c = thermistor_driver_get_temperature();
|
|
||||||
if (in_fahrenheit) {
|
if (in_fahrenheit) {
|
||||||
watch_display_float_with_best_effort(temperature_c * 1.8 + 32.0, "#F");
|
watch_display_float_with_best_effort(temperature_c * 1.8 + 32.0, "#F");
|
||||||
} else {
|
} else {
|
||||||
watch_display_float_with_best_effort(temperature_c, "#C");
|
watch_display_float_with_best_effort(temperature_c, "#C");
|
||||||
}
|
}
|
||||||
thermistor_driver_disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void temperature_display_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
void temperature_display_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||||
@ -96,5 +92,3 @@ bool temperature_display_face_loop(movement_event_t event, void *context) {
|
|||||||
void temperature_display_face_resign(void *context) {
|
void temperature_display_face_resign(void *context) {
|
||||||
(void) context;
|
(void) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* THERMISTOR READOUT (aka Temperature Display)
|
* THERMISTOR READOUT (aka Temperature Display)
|
||||||
*
|
*
|
||||||
@ -65,5 +63,3 @@ void temperature_display_face_resign(void *context);
|
|||||||
temperature_display_face_resign, \
|
temperature_display_face_resign, \
|
||||||
NULL, \
|
NULL, \
|
||||||
})
|
})
|
||||||
|
|
||||||
#endif // HAS_TEMPERATURE_SENSOR
|
|
||||||
|
|||||||
@ -28,18 +28,13 @@
|
|||||||
#include "thermistor_driver.h"
|
#include "thermistor_driver.h"
|
||||||
#include "watch.h"
|
#include "watch.h"
|
||||||
|
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
|
||||||
|
|
||||||
static void _temperature_logging_face_log_data(thermistor_logger_state_t *logger_state) {
|
static void _temperature_logging_face_log_data(thermistor_logger_state_t *logger_state) {
|
||||||
thermistor_driver_enable();
|
|
||||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||||
size_t pos = logger_state->data_points % THERMISTOR_LOGGING_NUM_DATA_POINTS;
|
size_t pos = logger_state->data_points % THERMISTOR_LOGGING_NUM_DATA_POINTS;
|
||||||
|
|
||||||
logger_state->data[pos].timestamp.reg = date_time.reg;
|
logger_state->data[pos].timestamp.reg = date_time.reg;
|
||||||
logger_state->data[pos].temperature_c = thermistor_driver_get_temperature();
|
logger_state->data[pos].temperature_c = movement_get_temperature();
|
||||||
logger_state->data_points++;
|
logger_state->data_points++;
|
||||||
|
|
||||||
thermistor_driver_disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _temperature_logging_face_update_display(thermistor_logger_state_t *logger_state, bool in_fahrenheit, bool clock_mode_24h) {
|
static void _temperature_logging_face_update_display(thermistor_logger_state_t *logger_state, bool in_fahrenheit, bool clock_mode_24h) {
|
||||||
@ -150,5 +145,3 @@ movement_watch_face_advisory_t temperature_logging_face_advise(void *context) {
|
|||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
#ifdef HAS_TEMPERATURE_SENSOR
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* THERMISTOR LOGGING (aka Temperature Log)
|
* THERMISTOR LOGGING (aka Temperature Log)
|
||||||
*
|
*
|
||||||
@ -86,5 +84,3 @@ movement_watch_face_advisory_t temperature_logging_face_advise(void *context);
|
|||||||
temperature_logging_face_resign, \
|
temperature_logging_face_resign, \
|
||||||
temperature_logging_face_advise, \
|
temperature_logging_face_advise, \
|
||||||
})
|
})
|
||||||
|
|
||||||
#endif // HAS_TEMPERATURE_SENSOR
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user