Added and initialized the altimeter screen object

This commit is contained in:
anschrammh 2024-01-16 12:55:27 +01:00
parent f31f8895a0
commit 05e50c9eb2

View File

@ -11,6 +11,7 @@
#include "watch_face.h"
#include "menu_screen.h"
#include "compass_screen.h"
#include "altimeter_screen.h"
#include "find_my_phone_screen.h"
#include "music_player_screen.h"
#include "settings_screen.h"
@ -38,6 +39,7 @@ static void _perform_deferred_display_wake_up(uint8_t deferred_time_in_ms);
WatchFace_t watchFace;
MenuScreen_t menuScreen;
CompassScreen_t compassScreen;
AltimeterScreen_t altimeterScreen;
FindMyPhoneScreen_t findMyPhoneScreen;
MusicPlayerScreen_t musicPlayerScreen;
NotificationScreen_t notificationScreen;
@ -150,6 +152,7 @@ static void setTimeFormatCb(bool *hour_24H_format, SettingMode_e mode)
else
{
watch_settings_time_and_date_set_hour_format(*hour_24H_format);
notification_screen_set_displayed_hour_format(&notificationScreen, *hour_24H_format);
}
}
@ -644,6 +647,23 @@ static void settings_screen_on_state_change_cb(SettingsScreenState_e settingsScr
}
}
static void altimeter_screen_on_state_change_cb(AltimeterScreenState_e altimeterScreenState)
{
switch(altimeterScreenState)
{
case ALTIMETER_SCREEN_STATE_OPENED:
if(!watch_peripherals_pressure_sensor_select_profile(WATCH_PERIPHERALS_PRESSURE_SENSOR_PROFILE_HIGH_PRECISION))
APP_LOG_ERROR("Failed to change pressure sensor profile to high precision");
break;
case ALTIMETER_SCREEN_STATE_CLOSED:
if(!watch_peripherals_pressure_sensor_select_profile(WATCH_PERIPHERALS_PRESSURE_SENSOR_PROFILE_LOW_POWER))
APP_LOG_ERROR("Failed to change pressure sensor profile to low power");
break;
default:
break;
}
}
static float bmp_temperature = 0;
static void compass_screen_azimuth_and_temperature_cb(uint16_t *azimuth, bool *refreshAzimuth, float *temperature, bool *refreshTemperature)
@ -653,6 +673,23 @@ static void compass_screen_azimuth_and_temperature_cb(uint16_t *azimuth, bool *r
*temperature = bmp_temperature;
}
#include "BMP280.h"
static void altimeter_screen_measurement_cb(float * const temperature, float * const pressure, float * const altitude)
{
float _pressure, _temperature;
BMP280_trigger_measurement();
while(BMP280_is_measuring());
float _altitude = BMP280_get_altitude(0, &_pressure, &_temperature);
if(temperature)*temperature = _temperature;
if(pressure)*pressure = _pressure/100.0;
if(altitude)*altitude = _altitude;
}
static void sendFindMyPhoneBLECommandCb(bool findMyPhone)
{
gadget_bridge_send_find_phone(findMyPhone);
@ -660,7 +697,7 @@ static void sendFindMyPhoneBLECommandCb(bool findMyPhone)
static void sendMusicPlaybackBLECommandCb(MusicPlaybackCtrlAction_e musicPlaybackCtrlAction)
{
gadget_bridge_send_music_control(musicPlaybackCtrlAction);
gadget_bridge_send_music_control((gadget_bridge_music_control_e) musicPlaybackCtrlAction);
}
static void notification_on_state_change_cb(NotificationState_e notificationState, uint32_t notification_handle)
@ -676,7 +713,6 @@ static void notification_on_state_change_cb(NotificationState_e notificationStat
case NOTIFICATION_STATE_CLEARED:
// Let's restore MCU clocks to it's default
watch_power_management_restore_default_cpu_clocks(true, true);
// Don't forget to tell GadgetBridge that the notification was dismissed
gadget_bridge_send_notification_action(GADGET_BRIDGE_NOTIFICATION_ACTION_DISMISS, notification_handle, NULL, NULL);
default:
@ -751,6 +787,11 @@ void gfx_task(void *param)
compass_screen_register_on_state_change_cb(&compassScreen, &(compass_screen_on_state_change_cb));
compass_screen_register_azimuth_and_temperature_cb(&compassScreen, &(compass_screen_azimuth_and_temperature_cb));
altimeter_screen_init(&altimeterScreen);
altimeter_screen_register_on_state_change_cb(&altimeterScreen, &(altimeter_screen_on_state_change_cb));
altimeter_screen_register_user_feedback_cb(&altimeterScreen, &(watch_peripherals_vibrate_on_item_click));
altimeter_screen_register_measurement_cb(&altimeterScreen, &(altimeter_screen_measurement_cb));
find_my_phone_screen_init(&findMyPhoneScreen);
find_my_phone_screen_register_BLE_command_send_cb(&findMyPhoneScreen, &(sendFindMyPhoneBLECommandCb));
@ -760,6 +801,7 @@ void gfx_task(void *param)
music_player_screen_register_user_feedback_cb(&musicPlayerScreen, &(watch_peripherals_vibrate_on_item_click));
notification_screen_init(&notificationScreen);
notification_screen_set_displayed_hour_format(&notificationScreen, persistency_get_settings()->timeAndDate.time_and_date_hour_format);
notification_screen_register_on_state_change_cb(&notificationScreen, &(notification_on_state_change_cb));
settings_screen_init(&settingsScreen);
@ -879,7 +921,7 @@ void gfx_task(void *param)
_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 %%",
bmp_temperature,
pressure/100,
pressure/100.0,
battery_controller_status_2_str(watch_peripherals_get_battery_controller_status()),
_battery_stats.battery_voltage,
_battery_stats.battery_percentage);