Changed some core logic, now sending the watch's battery information when connected every 5 minutes to the phone so that gadget bridge can draw and update the battery graph. Added annd implemented a few callbacks used by the watch_settings screen
This commit is contained in:
parent
552644a412
commit
fcc152f64d
@ -26,6 +26,7 @@ static void date_time_cb(struct tm * const dateTime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _is_in_ble_sleep_mode = false;
|
bool _is_in_ble_sleep_mode = false;
|
||||||
|
bool _is_ble_device_subscribed = false;
|
||||||
static void _perform_deferred_display_wake_up_set_timestamp(void);
|
static void _perform_deferred_display_wake_up_set_timestamp(void);
|
||||||
static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms);
|
static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms);
|
||||||
|
|
||||||
@ -203,7 +204,7 @@ static void setWristTiltCb(bool *enabled, SettingMode_e mode)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
watch_peripherals_accelerometer_wrist_wakeup_enable(*enabled);
|
watch_peripherals_accelerometer_wrist_wakeup_enable(*enabled);
|
||||||
watch_settings_display_set_wrist_wakeup(*enabled);
|
watch_settings_display_wrist_wakeup_enabled(*enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,6 +270,22 @@ static void getBatteryVoltageCb(uint16_t *battery_voltage)
|
|||||||
*battery_voltage = _battery_stats.battery_voltage;
|
*battery_voltage = _battery_stats.battery_voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void getMagnetometerRawDataCb(int16_t *field_x, int16_t *field_y, int16_t *field_z, float *temperature)
|
||||||
|
{
|
||||||
|
QMC5883L_MData_t raw_data = watch_peripherals_magnetometer_raw_data_read();
|
||||||
|
*field_x = raw_data.MFieldX;
|
||||||
|
*field_y = raw_data.MFieldY;
|
||||||
|
*field_z = raw_data.MFieldZ;
|
||||||
|
|
||||||
|
*temperature = watch_peripherals_magnetometer_temperature_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void getBMP280DataCb(float *temperature, float *pressure)
|
||||||
|
{
|
||||||
|
/* We want hPa's */
|
||||||
|
*pressure = watch_peripherals_pressure_sensor_get_pressure(temperature) / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
static void saveSettingsToFlashCb(void)
|
static void saveSettingsToFlashCb(void)
|
||||||
{
|
{
|
||||||
/*if(!persistency_save_settings_to_flash())
|
/*if(!persistency_save_settings_to_flash())
|
||||||
@ -308,6 +325,8 @@ SettingsScreenAPIInterface_t settingsScreenAPIInterface =
|
|||||||
.setLanguageSettingsCb = &(setLanguageCb),
|
.setLanguageSettingsCb = &(setLanguageCb),
|
||||||
.getBLEDeviceNameCb = &(getBLEDeviceNameCb),
|
.getBLEDeviceNameCb = &(getBLEDeviceNameCb),
|
||||||
.getBatteryVoltageCb = &(getBatteryVoltageCb),
|
.getBatteryVoltageCb = &(getBatteryVoltageCb),
|
||||||
|
.getMagnetometerRawDataCb = &(getMagnetometerRawDataCb),
|
||||||
|
.getBMP280DataCb = &(getBMP280DataCb),
|
||||||
.saveSettingsCb = &(saveSettingsToFlashCb),
|
.saveSettingsCb = &(saveSettingsToFlashCb),
|
||||||
.factoryResetCb = &(performFactoryResetCb),
|
.factoryResetCb = &(performFactoryResetCb),
|
||||||
};
|
};
|
||||||
@ -362,11 +381,15 @@ static void ble_service_state_change_cb(ble_service_state_e ble_service_state)
|
|||||||
watch_face_set_bluetooth_indicator(&watchFace, BLUETOOTH_STATE_ON);
|
watch_face_set_bluetooth_indicator(&watchFace, BLUETOOTH_STATE_ON);
|
||||||
break;
|
break;
|
||||||
case BLE_SERVICE_MODE_SUBSCRIBED:
|
case BLE_SERVICE_MODE_SUBSCRIBED:
|
||||||
|
_is_ble_device_subscribed = true;
|
||||||
/* We also set the current watch firmware version */
|
/* We also set the current watch firmware version */
|
||||||
gadget_bridge_send_firmware_version(FIRMWARE_VERSION, NULL);
|
gadget_bridge_send_firmware_version(FIRMWARE_VERSION, NULL);
|
||||||
/* We send the current battery level and battery state (charging or not)*/
|
/* We send the current battery level and battery state (charging or not)*/
|
||||||
gadget_bridge_send_battery_status(_battery_stats.battery_percentage, _battery_stats.battery_voltage/1000.0, watch_peripherals_get_battery_controller_status() != BATTERY_CONTROLLER_STATUS_DISCHARGING);
|
gadget_bridge_send_battery_status(_battery_stats.battery_percentage, _battery_stats.battery_voltage/1000.0, watch_peripherals_get_battery_controller_status() != BATTERY_CONTROLLER_STATUS_DISCHARGING);
|
||||||
break;
|
break;
|
||||||
|
case BLE_SERVICE_MODE_UNSUBSCRIBED:
|
||||||
|
_is_ble_device_subscribed = false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -492,7 +515,9 @@ void gfx_task(void *param)
|
|||||||
|
|
||||||
float temperature = 0;
|
float temperature = 0;
|
||||||
float pressure = 0;
|
float pressure = 0;
|
||||||
uint32_t update_tick = 0;
|
|
||||||
|
uint32_t ble_info_update_ms = 0;
|
||||||
|
uint32_t main_data_update = 0;
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
@ -500,7 +525,6 @@ void gfx_task(void *param)
|
|||||||
if(!_is_in_ble_sleep_mode)
|
if(!_is_in_ble_sleep_mode)
|
||||||
{
|
{
|
||||||
lv_timer_handler();
|
lv_timer_handler();
|
||||||
tls_os_time_delay(5);
|
|
||||||
|
|
||||||
if(compass_screen_is_in_use(&compassScreen))
|
if(compass_screen_is_in_use(&compassScreen))
|
||||||
{
|
{
|
||||||
@ -520,23 +544,6 @@ void gfx_task(void *param)
|
|||||||
compass_screen_set_temperature(&compassScreen, temperature);
|
compass_screen_set_temperature(&compassScreen, temperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To rework */
|
|
||||||
if(lv_tick_elaps(update_tick) > 5000)
|
|
||||||
{
|
|
||||||
pressure = watch_peripherals_pressure_sensor_get_pressure(&temperature);
|
|
||||||
|
|
||||||
_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_stats.battery_voltage,
|
|
||||||
_battery_stats.battery_percentage);
|
|
||||||
|
|
||||||
update_tick = lv_tick_get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Throttle CPU freq down when inactive to save power or to increase responsiveness */
|
/* Throttle CPU freq down when inactive to save power or to increase responsiveness */
|
||||||
tls_sys_clk clk;
|
tls_sys_clk clk;
|
||||||
tls_sys_clk_get(&clk);
|
tls_sys_clk_get(&clk);
|
||||||
@ -559,14 +566,15 @@ void gfx_task(void *param)
|
|||||||
|
|
||||||
/* Will wake the display up after some ms to avoid seeing the second hand jumping */
|
/* Will wake the display up after some ms to avoid seeing the second hand jumping */
|
||||||
_perform_deferred_display_wake_up(30);
|
_perform_deferred_display_wake_up(30);
|
||||||
|
|
||||||
|
tls_os_time_delay(pdMS_TO_TICKS(6));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Increase task IDLE time */
|
/* Increase task IDLE time */
|
||||||
tls_os_time_delay(50);
|
tls_os_time_delay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Handle inactivity periods : */
|
/* Handle inactivity periods : */
|
||||||
if( persistency_get_settings()->display.display_delay_before_sleep != 0 &&
|
if( persistency_get_settings()->display.display_delay_before_sleep != 0 &&
|
||||||
lv_disp_get_inactive_time(NULL) > (persistency_get_settings()->display.display_delay_before_sleep * 5 * 1000))
|
lv_disp_get_inactive_time(NULL) > (persistency_get_settings()->display.display_delay_before_sleep * 5 * 1000))
|
||||||
@ -588,7 +596,7 @@ void gfx_task(void *param)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* We set the pmu timer 0 to wake up every now and then to perform some background tasks before we go back to sleep again */
|
/* We set the pmu timer 0 to wake up every now and then to perform some background tasks before we go back to sleep again */
|
||||||
tls_pmu_timer0_start(5);
|
tls_pmu_timer0_start(15*60);
|
||||||
|
|
||||||
/* We clear any potentiential user wakeup source */
|
/* We clear any potentiential user wakeup source */
|
||||||
watch_peripherals_wakeup_source_is_user();
|
watch_peripherals_wakeup_source_is_user();
|
||||||
@ -605,8 +613,7 @@ void gfx_task(void *param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the periodic background tasks */
|
/* Perform the periodic background tasks */
|
||||||
ms_delay(5);
|
ms_delay(1);APP_LOG_INFO("Periodic timer wakeup !");
|
||||||
APP_LOG_INFO("Periodic timer wakeup !");
|
|
||||||
|
|
||||||
} while (watch_peripherals_wakeup_source_is_timer());
|
} while (watch_peripherals_wakeup_source_is_timer());
|
||||||
|
|
||||||
@ -619,9 +626,27 @@ void gfx_task(void *param)
|
|||||||
lcd_on(&LCDConfig, false);
|
lcd_on(&LCDConfig, false);
|
||||||
_perform_deferred_display_wake_up_set_timestamp();
|
_perform_deferred_display_wake_up_set_timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Necessary to not enter the if condition over and over again
|
||||||
lv_disp_trig_activity(NULL);
|
lv_disp_trig_activity(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(elapsed_ms() - main_data_update > 10000)
|
||||||
|
{
|
||||||
|
main_data_update = elapsed_ms();
|
||||||
|
|
||||||
|
pressure = watch_peripherals_pressure_sensor_get_pressure(&temperature);
|
||||||
|
|
||||||
|
_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_stats.battery_voltage,
|
||||||
|
_battery_stats.battery_percentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Handle any interrupts status */
|
/* Handle any interrupts status */
|
||||||
if(_interrupts_statuses.battery_controller_status)
|
if(_interrupts_statuses.battery_controller_status)
|
||||||
@ -631,6 +656,22 @@ void gfx_task(void *param)
|
|||||||
_battery_stats.battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
_battery_stats.battery_voltage = watch_peripherals_get_battery_voltage(battery_unit_mv);
|
||||||
_battery_stats.battery_percentage = battery_voltage_to_percentage(_battery_stats.battery_voltage);
|
_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());
|
watch_face_set_battery_indicator(&watchFace, _battery_stats.battery_percentage, watch_peripherals_get_battery_controller_status());
|
||||||
|
|
||||||
|
// Also send the information over BLE to GadgetBridge
|
||||||
|
if(_is_ble_device_subscribed)
|
||||||
|
{
|
||||||
|
gadget_bridge_send_battery_status(_battery_stats.battery_percentage, _battery_stats.battery_voltage/1000.0, watch_peripherals_get_battery_controller_status() != BATTERY_CONTROLLER_STATUS_DISCHARGING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send battery voltage and current charging state to gadget bridge every 5 minutes */
|
||||||
|
if(elapsed_ms() - ble_info_update_ms > 5 * 60 * 1000)
|
||||||
|
{
|
||||||
|
ble_info_update_ms = elapsed_ms();
|
||||||
|
if(_is_ble_device_subscribed)
|
||||||
|
{
|
||||||
|
gadget_bridge_send_battery_status(_battery_stats.battery_percentage, _battery_stats.battery_voltage/1000.0, watch_peripherals_get_battery_controller_status() != BATTERY_CONTROLLER_STATUS_DISCHARGING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wrist_tilt = false ,touch_screen_touch = false;
|
bool wrist_tilt = false ,touch_screen_touch = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user