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_ble_device_subscribed = false;
|
||||
static void _perform_deferred_display_wake_up_set_timestamp(void);
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
/*if(!persistency_save_settings_to_flash())
|
||||
@ -308,6 +325,8 @@ SettingsScreenAPIInterface_t settingsScreenAPIInterface =
|
||||
.setLanguageSettingsCb = &(setLanguageCb),
|
||||
.getBLEDeviceNameCb = &(getBLEDeviceNameCb),
|
||||
.getBatteryVoltageCb = &(getBatteryVoltageCb),
|
||||
.getMagnetometerRawDataCb = &(getMagnetometerRawDataCb),
|
||||
.getBMP280DataCb = &(getBMP280DataCb),
|
||||
.saveSettingsCb = &(saveSettingsToFlashCb),
|
||||
.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);
|
||||
break;
|
||||
case BLE_SERVICE_MODE_SUBSCRIBED:
|
||||
_is_ble_device_subscribed = true;
|
||||
/* We also set the current watch firmware version */
|
||||
gadget_bridge_send_firmware_version(FIRMWARE_VERSION, NULL);
|
||||
/* 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);
|
||||
break;
|
||||
case BLE_SERVICE_MODE_UNSUBSCRIBED:
|
||||
_is_ble_device_subscribed = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -492,7 +515,9 @@ void gfx_task(void *param)
|
||||
|
||||
float temperature = 0;
|
||||
float pressure = 0;
|
||||
uint32_t update_tick = 0;
|
||||
|
||||
uint32_t ble_info_update_ms = 0;
|
||||
uint32_t main_data_update = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
@ -500,7 +525,6 @@ void gfx_task(void *param)
|
||||
if(!_is_in_ble_sleep_mode)
|
||||
{
|
||||
lv_timer_handler();
|
||||
tls_os_time_delay(5);
|
||||
|
||||
if(compass_screen_is_in_use(&compassScreen))
|
||||
{
|
||||
@ -520,23 +544,6 @@ void gfx_task(void *param)
|
||||
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 */
|
||||
tls_sys_clk 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 */
|
||||
_perform_deferred_display_wake_up(30);
|
||||
|
||||
tls_os_time_delay(pdMS_TO_TICKS(6));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Increase task IDLE time */
|
||||
tls_os_time_delay(50);
|
||||
tls_os_time_delay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
|
||||
|
||||
/* Handle inactivity periods : */
|
||||
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))
|
||||
@ -588,7 +596,7 @@ void gfx_task(void *param)
|
||||
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 */
|
||||
tls_pmu_timer0_start(5);
|
||||
tls_pmu_timer0_start(15*60);
|
||||
|
||||
/* We clear any potentiential user wakeup source */
|
||||
watch_peripherals_wakeup_source_is_user();
|
||||
@ -605,8 +613,7 @@ void gfx_task(void *param)
|
||||
}
|
||||
|
||||
/* Perform the periodic background tasks */
|
||||
ms_delay(5);
|
||||
APP_LOG_INFO("Periodic timer wakeup !");
|
||||
ms_delay(1);APP_LOG_INFO("Periodic timer wakeup !");
|
||||
|
||||
} while (watch_peripherals_wakeup_source_is_timer());
|
||||
|
||||
@ -619,9 +626,27 @@ void gfx_task(void *param)
|
||||
lcd_on(&LCDConfig, false);
|
||||
_perform_deferred_display_wake_up_set_timestamp();
|
||||
}
|
||||
|
||||
// Necessary to not enter the if condition over and over again
|
||||
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 */
|
||||
if(_interrupts_statuses.battery_controller_status)
|
||||
@ -631,9 +656,25 @@ void gfx_task(void *param)
|
||||
_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());
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
bool wrist_tilt = false , touch_screen_touch = false;
|
||||
/* 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;
|
||||
if((wrist_tilt = watch_peripherals_accelerometer_wrist_wakeup_interrupt()) || ((touch_screen_touch = lv_port_indev_touched()) && _is_in_ble_sleep_mode))
|
||||
{
|
||||
if(wrist_tilt)
|
||||
|
Loading…
Reference in New Issue
Block a user