Added BLE support to the app, fixed a graphical glitch happening when
waking up the watch by touching the screen where the second hand was jumping from the old time to the new time
This commit is contained in:
parent
3156976f7a
commit
47753131d6
@ -24,10 +24,11 @@ static void date_time_cb(struct tm * const dateTime)
|
||||
{
|
||||
if(!dateTime)return;
|
||||
tls_get_rtc(dateTime);
|
||||
//APP_LOG_DEBUG("RTC time : %d:%d:%d", dateTime->tm_hour, dateTime->tm_min, dateTime->tm_sec);
|
||||
}
|
||||
|
||||
static uint8_t _battery_percentage = 100;
|
||||
static void _perform_deferred_display_wake_up_set_sleeping(void);
|
||||
static void _perform_deferred_display_wake_up_set_timestamp(void);
|
||||
static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms);
|
||||
|
||||
WatchFace_t watchFace;
|
||||
MenuScreen_t menuScreen;
|
||||
@ -39,17 +40,22 @@ struct bma4_accel_config accel_conf;
|
||||
struct bma456w_wrist_wear_wakeup_params setting;
|
||||
struct bma4_int_pin_config pin_config;
|
||||
|
||||
struct
|
||||
static struct
|
||||
{
|
||||
uint16_t int_status;
|
||||
bool battery_controller_status;
|
||||
} _interrupts_statuses = {.int_status = 0, .battery_controller_status = false};
|
||||
|
||||
static struct
|
||||
{
|
||||
uint16_t battery_voltage;
|
||||
uint8_t battery_percentage;
|
||||
} _battery_stats = {.battery_voltage = 0, .battery_percentage = 100};
|
||||
|
||||
/* This call back is automatically called by the watch face when it wants to refresh the battery */
|
||||
static void battery_indicator_cb(uint8_t *levelInPercent, BatteryState_e *batteryState)
|
||||
{
|
||||
*levelInPercent = _battery_percentage;
|
||||
*levelInPercent = _battery_stats.battery_percentage;
|
||||
*batteryState = watch_peripherals_get_battery_controller_status();
|
||||
}
|
||||
|
||||
@ -217,7 +223,17 @@ static void setLanguageCb(uint8_t *language, SettingMode_e mode)
|
||||
}
|
||||
}
|
||||
|
||||
static void saveSettingsToFlash(void)
|
||||
static void getBLEDeviceNameCb(const char **dev_name)
|
||||
{
|
||||
*dev_name = BLE_DEVICE_NAME;
|
||||
}
|
||||
|
||||
static void getBatteryVoltageCb(uint16_t *battery_voltage)
|
||||
{
|
||||
*battery_voltage = _battery_stats.battery_voltage;
|
||||
}
|
||||
|
||||
static void saveSettingsToFlashCb(void)
|
||||
{
|
||||
/*if(!persistency_save_settings_to_flash())
|
||||
{
|
||||
@ -225,7 +241,7 @@ static void saveSettingsToFlash(void)
|
||||
}*/
|
||||
}
|
||||
|
||||
static void performFactoryReset()
|
||||
static void performFactoryResetCb()
|
||||
{
|
||||
// Reload factory settings
|
||||
persistency_factory_reset();
|
||||
@ -251,8 +267,10 @@ SettingsScreenAPIInterface_t settingsScreenAPIInterface =
|
||||
.setBLEEnabledSettingsCb = &(setBLEEnabledCb),
|
||||
.setWiFiEnabledSettingsCb = &(setWiFiEnabledCb),
|
||||
.setLanguageSettingsCb = &(setLanguageCb),
|
||||
.saveSettingsCb = &(saveSettingsToFlash),
|
||||
.factoryResetCb = &(performFactoryReset),
|
||||
.getBLEDeviceNameCb = &(getBLEDeviceNameCb),
|
||||
.getBatteryVoltageCb = &(getBatteryVoltageCb),
|
||||
.saveSettingsCb = &(saveSettingsToFlashCb),
|
||||
.factoryResetCb = &(performFactoryResetCb),
|
||||
};
|
||||
|
||||
static uint16_t angle_with_offset(uint16_t angle, uint16_t offset)
|
||||
@ -284,6 +302,17 @@ static void delay_us(uint32_t period, void *intf_ptr)
|
||||
tls_os_time_delay(pdMS_TO_TICKS(period / 1000));
|
||||
}
|
||||
|
||||
static void ble_service_nus_data_rx_cb(const uint8_t *data, uint16_t length)
|
||||
{
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
if (data[i] < 32)
|
||||
printf("[%u]", data[i]);
|
||||
else
|
||||
printf("%c", data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void ble_service_state_change_cb(ble_service_state_e ble_service_state)
|
||||
{
|
||||
switch(ble_service_state)
|
||||
@ -336,6 +365,8 @@ static void scan_result_cb(void)
|
||||
tls_mem_free(buffer);
|
||||
}
|
||||
|
||||
extern LCDConfig_t LCDConfig;
|
||||
|
||||
void gfx_task(void *param)
|
||||
{
|
||||
APP_LOG_TRACE("GFX task starting");
|
||||
@ -355,8 +386,8 @@ void gfx_task(void *param)
|
||||
watch_peripherals_register_battery_controller_status_change_cb(&(battery_controller_status_on_change_cb));
|
||||
|
||||
/* Make the first battery voltage reading here */
|
||||
uint16_t battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
_battery_percentage = battery_voltage_to_percentage(battery_voltage);
|
||||
_battery_stats.battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
_battery_stats.battery_percentage = battery_voltage_to_percentage(_battery_stats.battery_voltage);
|
||||
|
||||
/* Check whether the RTC is running or not, if not, then the board was reset
|
||||
So we start the RTC */
|
||||
@ -392,8 +423,6 @@ void gfx_task(void *param)
|
||||
/* Let's init the I2C interface */
|
||||
i2c_init(I2C_SDA, I2C_SCL, I2C_CLOCK_SPEED);
|
||||
|
||||
uint8_t aliveCounter = 0;
|
||||
|
||||
/* Init the magnetometer */
|
||||
if(!QMC5883L_init())
|
||||
APP_LOG_INFO("Failed to init QMC5883L");
|
||||
@ -499,6 +528,7 @@ void gfx_task(void *param)
|
||||
APP_LOG_INFO("BMA456 step cnter feature enable failed");
|
||||
|
||||
/* Configure and register BLE stack and services callbacks */
|
||||
ble_service_register_nus_data_rx_cb(&(ble_service_nus_data_rx_cb));
|
||||
ble_service_register_state_change_cb(&(ble_service_state_change_cb));
|
||||
|
||||
/* Once we are done with the initializing steps we
|
||||
@ -508,9 +538,9 @@ void gfx_task(void *param)
|
||||
/* Enable WiFi hotspot scanning for antenna performance test purposes */
|
||||
//tls_wifi_scan_result_cb_register(&(scan_result_cb));
|
||||
|
||||
extern LCDConfig_t LCDConfig;
|
||||
float temperature = 0;
|
||||
float pressure = 0;
|
||||
uint32_t update_tick = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
@ -543,28 +573,27 @@ void gfx_task(void *param)
|
||||
APP_LOG_DEBUG("Wrist tilt");
|
||||
}
|
||||
|
||||
if(++aliveCounter % 200 == 0)
|
||||
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(&watchFace, steps);
|
||||
watch_face_set_step_count_indicator(&watchFace, steps);
|
||||
|
||||
pressure = BMP280_get_pressure(&temperature);
|
||||
BMP280_trigger_measurement();
|
||||
battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
_battery_percentage = battery_voltage_to_percentage(battery_voltage);
|
||||
_battery_stats.battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
_battery_stats.battery_percentage = battery_voltage_to_percentage(_battery_stats.battery_voltage);
|
||||
APP_LOG_DEBUG("GFX thread, temp : %0.2f °C, press : %0.2f hPa, battery(%s) : %u mV <-> %u %%",
|
||||
temperature,
|
||||
pressure/100,
|
||||
battery_controller_status_2_str(watch_peripherals_get_battery_controller_status()),
|
||||
battery_voltage,
|
||||
_battery_percentage);
|
||||
_battery_stats.battery_voltage,
|
||||
_battery_stats.battery_percentage);
|
||||
|
||||
//APP_LOG_DEBUG("Scanning WiFi : %d", tls_wifi_scan());
|
||||
|
||||
aliveCounter = 0;
|
||||
update_tick = lv_tick_get();
|
||||
}
|
||||
|
||||
/* Handle inactivity periods : */
|
||||
@ -589,9 +618,14 @@ void gfx_task(void *param)
|
||||
QMC5883L_set_power_mode(Continuous);
|
||||
//lcd_on(&LCDConfig, true);
|
||||
lcd_sleep(&LCDConfig, false);
|
||||
watch_peripherals_set_brightness(persistency_get_settings()->display.display_brightness);
|
||||
//watch_peripherals_set_brightness(persistency_get_settings()->display.display_brightness);
|
||||
//lcd_on(&LCDConfig, false);
|
||||
_perform_deferred_display_wake_up_set_timestamp();
|
||||
}
|
||||
|
||||
/* Will wake the display up after some ms to avoid seeing the second hand jumping */
|
||||
_perform_deferred_display_wake_up(30);
|
||||
|
||||
/* Throttle CPU freq down when inactive to save power or to increase responsiveness */
|
||||
tls_sys_clk clk;
|
||||
tls_sys_clk_get(&clk);
|
||||
@ -617,9 +651,31 @@ void gfx_task(void *param)
|
||||
{
|
||||
_interrupts_statuses.battery_controller_status = false;
|
||||
//Let's refresh the battery percentage as well:
|
||||
battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
_battery_percentage = battery_voltage_to_percentage(battery_voltage);
|
||||
watch_face_set_battery_indicator(&watchFace, _battery_percentage, watch_peripherals_get_battery_controller_status());
|
||||
_battery_stats.battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||
_battery_stats.battery_percentage = battery_voltage_to_percentage(_battery_stats.battery_voltage);
|
||||
watch_face_set_battery_indicator(&watchFace, _battery_stats.battery_percentage, watch_peripherals_get_battery_controller_status());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* This handling logic should be moved somewhere ! I just don't know where yet ... */
|
||||
static uint32_t _ticks = 0;
|
||||
static bool _was_sleeping = false;
|
||||
|
||||
static void _perform_deferred_display_wake_up_set_timestamp(void)
|
||||
{
|
||||
_ticks = lv_tick_get();
|
||||
_was_sleeping = true;
|
||||
}
|
||||
|
||||
static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms)
|
||||
{
|
||||
if(_was_sleeping && lv_tick_elaps(_ticks) > deferred_time_in_ms)
|
||||
{
|
||||
_was_sleeping = false;
|
||||
lcd_on(&LCDConfig, true);
|
||||
watch_peripherals_set_brightness(persistency_get_settings()->display.display_brightness);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user