kopia lustrzana https://github.com/OpenRTX/OpenRTX
Move settings from UI to State
rodzic
d66b59694a
commit
66af402e83
|
@ -25,6 +25,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <interfaces/rtc.h>
|
||||
#include <cps.h>
|
||||
#include <settings.h>
|
||||
|
||||
/**
|
||||
* Data structure representing a single satellite as part of a GPS fix.
|
||||
|
@ -93,6 +94,7 @@ typedef struct
|
|||
|
||||
bool emergency;
|
||||
gps_t gps_data;
|
||||
settings_t settings;
|
||||
}
|
||||
state_t;
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <stdint.h>
|
||||
#include <event.h>
|
||||
#include <hwconfig.h>
|
||||
#include <settings.h>
|
||||
|
||||
// Maximum menu entry length
|
||||
#define MAX_ENTRY_LEN 16
|
||||
|
@ -119,7 +118,6 @@ typedef struct ui_state_t
|
|||
extern layout_t layout;
|
||||
// Copy of the radio state
|
||||
extern state_t last_state;
|
||||
extern settings_t settings;
|
||||
extern const char *menu_items[];
|
||||
extern const char *settings_items[];
|
||||
extern const char *display_items[];
|
||||
|
|
|
@ -68,4 +68,9 @@ void state_init()
|
|||
state.voxLevel = 0;
|
||||
|
||||
state.emergency = false;
|
||||
// Initialize settings_t
|
||||
// TODO: settings_t should be read from flash memory or from a factory default
|
||||
state.settings = (settings_t){ 0 };
|
||||
state.settings.brightness = 255;
|
||||
state.settings.contrast = 84;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,6 @@ const color_t yellow_fab413 = {250, 180, 19, 255};
|
|||
layout_t layout;
|
||||
state_t last_state;
|
||||
ui_state_t ui_state;
|
||||
settings_t settings;
|
||||
bool macro_menu = false;
|
||||
bool layout_ready = false;
|
||||
bool redraw_needed = true;
|
||||
|
@ -313,11 +312,6 @@ void ui_init()
|
|||
// This syntax is called compound literal
|
||||
// https://stackoverflow.com/questions/6891720/initialize-reset-struct-to-zero-null
|
||||
ui_state = (const struct ui_state_t){ 0 };
|
||||
settings = (settings_t){ 0 };
|
||||
// Initialize settings_t
|
||||
// TODO: settings_t should be read from flash memory or from a factory default
|
||||
settings.brightness = 255;
|
||||
settings.contrast = 84;
|
||||
}
|
||||
|
||||
void ui_drawSplashScreen(bool centered)
|
||||
|
@ -554,19 +548,23 @@ void _ui_fsm_insertVFONumber(kbd_msg_t msg, bool *sync_rtx) {
|
|||
void _ui_changeBrightness(int variation)
|
||||
{
|
||||
if(variation >= 0)
|
||||
settings.brightness = (255 - settings.brightness < variation) ? 255 : settings.brightness + variation;
|
||||
state.settings.brightness =
|
||||
(255 - state.settings.brightness < variation) ? 255 : state.settings.brightness + variation;
|
||||
else
|
||||
settings.brightness = (settings.brightness < -variation) ? 0 : settings.brightness + variation;
|
||||
platform_setBacklightLevel(settings.brightness);
|
||||
state.settings.brightness =
|
||||
(state.settings.brightness < -variation) ? 0 : state.settings.brightness + variation;
|
||||
platform_setBacklightLevel(state.settings.brightness);
|
||||
}
|
||||
|
||||
void _ui_changeContrast(int variation)
|
||||
{
|
||||
if(variation >= 0)
|
||||
settings.contrast = (255 - settings.contrast < variation) ? 255 : settings.contrast + variation;
|
||||
state.settings.contrast =
|
||||
(255 - state.settings.contrast < variation) ? 255 : state.settings.contrast + variation;
|
||||
else
|
||||
settings.contrast = (settings.contrast < -variation) ? 0 : settings.contrast + variation;
|
||||
display_setContrast(settings.contrast);
|
||||
state.settings.contrast =
|
||||
(state.settings.contrast < -variation) ? 0 : state.settings.contrast + variation;
|
||||
display_setContrast(state.settings.contrast);
|
||||
}
|
||||
|
||||
void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) {
|
||||
|
@ -1071,20 +1069,20 @@ void ui_updateFSM(event_t event, bool *sync_rtx)
|
|||
if(msg.keys & KEY_LEFT)
|
||||
{
|
||||
if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Enabled") == 0)
|
||||
settings.gps_enabled = !settings.gps_enabled;
|
||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Set Time") == 0)
|
||||
settings.gps_set_time = !settings.gps_set_time;
|
||||
state.settings.gps_set_time = !state.settings.gps_set_time;
|
||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "UTC Timezone") == 0)
|
||||
settings.utc_timezone -= 1;
|
||||
state.settings.utc_timezone -= 1;
|
||||
}
|
||||
else if(msg.keys & KEY_RIGHT)
|
||||
{
|
||||
if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Enabled") == 0)
|
||||
settings.gps_enabled = !settings.gps_enabled;
|
||||
state.settings.gps_enabled = !state.settings.gps_enabled;
|
||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Set Time") == 0)
|
||||
settings.gps_set_time = !settings.gps_set_time;
|
||||
state.settings.gps_set_time = !state.settings.gps_set_time;
|
||||
else if(strcmp(settings_gps_items[ui_state.menu_selected], "UTC Timezone") == 0)
|
||||
settings.utc_timezone += 1;
|
||||
state.settings.utc_timezone += 1;
|
||||
}
|
||||
else if(msg.keys & KEY_ESC)
|
||||
{
|
||||
|
|
|
@ -117,9 +117,9 @@ int _ui_getDisplayValueName(char *buf, uint8_t max_len, uint8_t index)
|
|||
if(index >= display_num) return -1;
|
||||
uint8_t value = 0;
|
||||
if(strcmp(display_items[index], "Brightness") == 0)
|
||||
value = settings.brightness;
|
||||
value = last_state.settings.brightness;
|
||||
else if(strcmp(display_items[index], "Contrast") == 0)
|
||||
value = settings.contrast;
|
||||
value = last_state.settings.contrast;
|
||||
snprintf(buf, max_len, "%d", value);
|
||||
return 0;
|
||||
}
|
||||
|
@ -135,15 +135,15 @@ int _ui_getSettingsGPSValueName(char *buf, uint8_t max_len, uint8_t index)
|
|||
{
|
||||
if(index >= settings_gps_num) return -1;
|
||||
if(strcmp(settings_gps_items[index], "GPS Enabled") == 0)
|
||||
snprintf(buf, max_len, "%s", (settings.gps_enabled) ? "ON" : "OFF");
|
||||
snprintf(buf, max_len, "%s", (last_state.settings.gps_enabled) ? "ON" : "OFF");
|
||||
else if(strcmp(settings_gps_items[index], "GPS Set Time") == 0)
|
||||
snprintf(buf, max_len, "%s", (settings.gps_set_time) ? "ON" : "OFF");
|
||||
snprintf(buf, max_len, "%s", (last_state.settings.gps_set_time) ? "ON" : "OFF");
|
||||
else if(strcmp(settings_gps_items[index], "UTC Timezone") == 0)
|
||||
// Add + prefix to positive numbers
|
||||
if(settings.utc_timezone > 0)
|
||||
snprintf(buf, max_len, "+%d", settings.utc_timezone);
|
||||
if(last_state.settings.utc_timezone > 0)
|
||||
snprintf(buf, max_len, "+%d", last_state.settings.utc_timezone);
|
||||
else
|
||||
snprintf(buf, max_len, "%d", settings.utc_timezone);
|
||||
snprintf(buf, max_len, "%d", last_state.settings.utc_timezone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue