Compare commits
3 Commits
6d26186bd0
...
c26a88d21c
Author | SHA1 | Date | |
---|---|---|---|
c26a88d21c | |||
ad61388bf6 | |||
f2b17bffd3 |
@ -10,14 +10,15 @@
|
||||
//Is needed for the BT off workaround
|
||||
#include "wm_wifi.h"
|
||||
|
||||
bool ble_modem_on(bool startService)
|
||||
bool ble_modem_on(bool bluetoothOnly, bool startService)
|
||||
{
|
||||
int status = BLE_HS_ENOERR;
|
||||
bool serviceStartSuccess = true;
|
||||
uint8_t uart_no = 0xFF;
|
||||
tls_appl_trace_level = TLS_BT_LOG_VERBOSE; //Should be set with a config define
|
||||
|
||||
if(bt_adapter_state == WM_BT_STATE_ON) {
|
||||
if(bt_adapter_state == WM_BT_STATE_ON)
|
||||
{
|
||||
TLS_BT_APPL_TRACE_VERBOSE("ble modem already on"NEW_LINE);
|
||||
return true;
|
||||
}
|
||||
@ -26,9 +27,14 @@ bool ble_modem_on(bool startService)
|
||||
tls_appl_trace_level);
|
||||
status = tls_bt_init(uart_no);
|
||||
|
||||
if((status != BLE_HS_ENOERR) && (status != BLE_HS_EALREADY)) {
|
||||
if((status != BLE_HS_ENOERR) && (status != BLE_HS_EALREADY))
|
||||
{
|
||||
TLS_BT_APPL_TRACE_ERROR("%s, tls_bt_init ret:%s"NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
||||
}
|
||||
else if(bluetoothOnly) // If we successfully started the modem, we can set it's working mode.
|
||||
{
|
||||
tls_rf_bt_mode(true);
|
||||
}
|
||||
|
||||
// Start the ble service if it was asked and if it is not yet started
|
||||
if(startService && !ble_service_is_started())
|
||||
|
@ -10,7 +10,7 @@
|
||||
* @return true on success
|
||||
* @return false on failure
|
||||
*/
|
||||
bool ble_modem_on(bool startService);
|
||||
bool ble_modem_on(bool bluetoothOnly, bool startService);
|
||||
|
||||
/**
|
||||
* @brief Turns the BLE modem off
|
||||
|
@ -58,6 +58,14 @@ static void battery_indicator_cb(uint8_t *levelInPercent, BatteryState_e *batter
|
||||
*batteryState = watch_peripherals_get_battery_controller_status();
|
||||
}
|
||||
|
||||
static void step_count_cb(uint32_t *steps)
|
||||
{
|
||||
if(bma456w_step_counter_output(steps, &bma) != BMA4_OK)
|
||||
APP_LOG_DEBUG("Failed to read step counts");
|
||||
else
|
||||
watch_face_set_step_count_indicator(&watchFace, *steps);
|
||||
}
|
||||
|
||||
static void battery_controller_status_on_change_cb(battery_controller_status_e old, battery_controller_status_e new)
|
||||
{
|
||||
_interrupts_statuses.battery_controller_status = true;
|
||||
@ -182,7 +190,7 @@ static void setBLEEnabledCb(bool *enabled, SettingMode_e mode)
|
||||
//Let's turn the BLE on or OFF here
|
||||
if(*enabled)
|
||||
{
|
||||
if(!ble_modem_on(true))
|
||||
if(!ble_modem_on(true, true))
|
||||
APP_LOG_ERROR("Failed to start BLE modem with service");
|
||||
else
|
||||
watch_face_set_bluetooth_indicator(&watchFace, BLUETOOTH_STATE_ON);
|
||||
@ -415,6 +423,7 @@ void gfx_task(void *param)
|
||||
|
||||
watch_face_register_date_time_cb(&watchFace, &(date_time_cb));
|
||||
watch_face_register_battery_indicator_cb(&watchFace, &(battery_indicator_cb));
|
||||
watch_face_register_step_counter_indicator_cb(&watchFace, &(step_count_cb));
|
||||
watch_face_create(&watchFace);
|
||||
|
||||
lv_scr_load(watchFace.display);
|
||||
@ -574,12 +583,6 @@ void gfx_task(void *param)
|
||||
|
||||
if(lv_tick_elaps(update_tick) > 5000)
|
||||
{
|
||||
uint32_t steps = 0;
|
||||
if(bma456w_step_counter_output(&steps, &bma) != BMA4_OK)
|
||||
APP_LOG_DEBUG("Failed to read step counts");
|
||||
|
||||
watch_face_set_step_count_indicator(&watchFace, steps);
|
||||
|
||||
pressure = BMP280_get_pressure(&temperature);
|
||||
BMP280_trigger_measurement();
|
||||
_battery_stats.battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
|
@ -40,6 +40,7 @@ static void gesture_event_cb(lv_event_t * e)
|
||||
// We delete the timer
|
||||
lv_timer_del(watchFace->batteryIndicator.lowBatteryAnimationTimer);
|
||||
lv_timer_del(watchFace->handAnimationTimer);
|
||||
lv_timer_del(watchFace->stepCounterRefreshTimer);
|
||||
// We create the menu screen and switch to it
|
||||
extern MenuScreen_t menuScreen;
|
||||
menu_screen_create(&menuScreen);
|
||||
@ -135,6 +136,18 @@ static void battery_timer_anim_cb(lv_timer_t *timer)
|
||||
}
|
||||
}
|
||||
|
||||
static void step_counter_refresh_cb(lv_timer_t *timer)
|
||||
{
|
||||
WatchFace_t *watchFace = timer->user_data;
|
||||
|
||||
if(watchFace->stepCounterIndicatorCb)
|
||||
{
|
||||
uint32_t steps = 0;
|
||||
watchFace->stepCounterIndicatorCb(&steps);
|
||||
watch_face_set_step_count_indicator(watchFace, steps);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_battery_state_icon(WatchFace_t * const watchFace)
|
||||
{
|
||||
switch(watchFace->batteryIndicator.batteryState)
|
||||
@ -205,6 +218,17 @@ void watch_face_register_battery_indicator_cb(WatchFace_t *const watchFace, Batt
|
||||
watchFace->batteryIndicatorCb = BatteryIndicatorCb;
|
||||
}
|
||||
|
||||
void watch_face_register_step_counter_indicator_cb(WatchFace_t * const watchFace, StepCounterIndicatorCb_t stepCounterIndicatorCb)
|
||||
{
|
||||
if(!watchFace)
|
||||
{
|
||||
LV_LOG_ERROR("NULL pointer given !");
|
||||
return;
|
||||
}
|
||||
|
||||
watchFace->stepCounterIndicatorCb = stepCounterIndicatorCb;
|
||||
}
|
||||
|
||||
void watch_face_create(WatchFace_t * const watchFace)
|
||||
{
|
||||
if(!watchFace)
|
||||
@ -404,8 +428,17 @@ void watch_face_create(WatchFace_t * const watchFace)
|
||||
lv_timer_del(watchFace->handAnimationTimer);
|
||||
watchFace->handAnimationTimer = NULL;
|
||||
}
|
||||
|
||||
watchFace->handAnimationTimer = lv_timer_create(&(hand_timer_anim_cb), 199, watchFace);
|
||||
|
||||
//We create the timer which refreshes the step counter indicator
|
||||
if(watchFace->stepCounterRefreshTimer)
|
||||
{
|
||||
LV_LOG_ERROR("stepCounterRefreshTimer should be NULL here !");
|
||||
lv_timer_del(watchFace->stepCounterRefreshTimer);
|
||||
watchFace->stepCounterRefreshTimer = NULL;
|
||||
}
|
||||
|
||||
watchFace->stepCounterRefreshTimer = lv_timer_create(&(step_counter_refresh_cb), 300, watchFace);
|
||||
}
|
||||
|
||||
void watch_face_set_battery_indicator(WatchFace_t * const watchFace, uint8_t levelInPercent, BatteryState_e batteryState)
|
||||
@ -469,7 +502,7 @@ void watch_face_set_bluetooth_indicator(WatchFace_t * const watchFace, Bluetooth
|
||||
_set_bluetooth_indicator(watchFace);
|
||||
}
|
||||
|
||||
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t step_count)
|
||||
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t stepCount)
|
||||
{
|
||||
if(!watchFace)
|
||||
{
|
||||
@ -477,12 +510,12 @@ void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t
|
||||
return;
|
||||
}
|
||||
|
||||
if(step_count < 1000)
|
||||
sprintf(watchFace->stepCounter.text, "%u", step_count);
|
||||
else if(step_count < 9996)
|
||||
sprintf(watchFace->stepCounter.text, "%.2fk", step_count/1000.0);
|
||||
if(stepCount < 1000)
|
||||
sprintf(watchFace->stepCounter.text, "%u", stepCount);
|
||||
else if(stepCount < 9996)
|
||||
sprintf(watchFace->stepCounter.text, "%.2fk", stepCount/1000.0);
|
||||
else
|
||||
sprintf(watchFace->stepCounter.text, "%.1fk", step_count/1000.0);
|
||||
sprintf(watchFace->stepCounter.text, "%.1fk", stepCount/1000.0);
|
||||
|
||||
if(!watchFace->display) return;
|
||||
|
||||
@ -499,6 +532,7 @@ void watch_face_destroy(WatchFace_t * const watchFace)
|
||||
|
||||
watchFace->display = NULL;
|
||||
watchFace->handAnimationTimer = NULL;
|
||||
watchFace->stepCounterRefreshTimer = NULL;
|
||||
watchFace->dateWindow.dateWindowWidget = NULL;
|
||||
watchFace->hourHand.handImg = NULL;
|
||||
watchFace->minuteHand.handImg = NULL;
|
||||
|
@ -22,6 +22,8 @@ typedef void (*DateTimeCb_t)(struct tm * const dateTime);
|
||||
|
||||
typedef void (*BatteryIndicatorCb_t)(uint8_t *levelInPercent, BatteryState_e *batteryState);
|
||||
|
||||
typedef void (*StepCounterIndicatorCb_t)(uint32_t *stepCount);
|
||||
|
||||
typedef struct DateWindow
|
||||
{
|
||||
lv_obj_t *dateWindowWidget;
|
||||
@ -61,11 +63,13 @@ typedef struct WatchFace
|
||||
{
|
||||
DateTimeCb_t dateTimeCb; //Call back function used to retrieve the date and time needed by the watch face
|
||||
BatteryIndicatorCb_t batteryIndicatorCb; //Call back function used to update the battery level every minute
|
||||
StepCounterIndicatorCb_t stepCounterIndicatorCb;
|
||||
|
||||
WatchHand_t hourHand;
|
||||
WatchHand_t minuteHand;
|
||||
WatchHand_t secondHand;
|
||||
WatchHand_t mediumHand24h;
|
||||
lv_timer_t *handAnimationTimer;
|
||||
lv_timer_t *handAnimationTimer, *stepCounterRefreshTimer;
|
||||
lv_obj_t *display;
|
||||
DateWindow_t dateWindow;
|
||||
BatteryIndicator_t batteryIndicator;
|
||||
@ -94,6 +98,15 @@ void watch_face_register_date_time_cb(WatchFace_t * const watchFace, DateTimeCb_
|
||||
*/
|
||||
void watch_face_register_battery_indicator_cb(WatchFace_t * const watchFace, BatteryIndicatorCb_t BatteryIndicatorCb);
|
||||
|
||||
/**
|
||||
* @brief Registers a call back function used to refresh the step counter indicator located on the watch face.
|
||||
* The refreshing will be done twice a second.
|
||||
*
|
||||
* @param watchFace a pointer to the watch face context structure.
|
||||
* @param StepCounterIndicatorCb a pointer to a function having the right definition.
|
||||
*/
|
||||
void watch_face_register_step_counter_indicator_cb(WatchFace_t * const watchFace, StepCounterIndicatorCb_t stepCounterIndicatorCb);
|
||||
|
||||
/**
|
||||
* @brief Graphically builds the watch face
|
||||
*
|
||||
@ -131,7 +144,7 @@ void watch_face_set_bluetooth_indicator(WatchFace_t * const watchFace, Bluetooth
|
||||
* @param watchFace a pointer to the watch face context structure.
|
||||
* @param step_count the step count to show on the watch face.
|
||||
*/
|
||||
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t step_count);
|
||||
void watch_face_set_step_count_indicator(WatchFace_t * const watchFace, uint32_t stepCount);
|
||||
|
||||
/**
|
||||
* @brief Forces the watch face to sync up with the RTC by calling the provided date_time_cb
|
||||
|
Loading…
Reference in New Issue
Block a user