diff --git a/openrtx/include/settings.h b/openrtx/include/settings.h
new file mode 100644
index 00000000..732fd4f4
--- /dev/null
+++ b/openrtx/include/settings.h
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
+ * Niccolò Izzo IU2KIN, *
+ * Frederik Saraci IU2NRO, *
+ * Silvano Seva IU2KWO *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, see *
+ ***************************************************************************/
+
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+typedef struct
+{
+ uint8_t brightness;
+ uint8_t contrast;
+}
+settings_t;
+
+#endif /* SETTINGS_H */
diff --git a/openrtx/include/state.h b/openrtx/include/state.h
index d1d62fc0..4cd03fd3 100644
--- a/openrtx/include/state.h
+++ b/openrtx/include/state.h
@@ -40,7 +40,6 @@ typedef struct
float rssi;
uint8_t ui_screen;
- uint8_t backlight_level;
uint8_t tuner_mode;
//time_t rx_status_tv;
diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h
index 18dc12e9..f74a8912 100644
--- a/openrtx/include/ui.h
+++ b/openrtx/include/ui.h
@@ -27,6 +27,7 @@
#include
#include
#include
+#include
// Maximum menu entry length
#define MAX_ENTRY_LEN 16
@@ -119,6 +120,7 @@ typedef struct ui_state_t
} ui_state_t;
extern layout_t layout;
+extern settings_t settings;
extern const char *menu_items[6];
extern const char *settings_items[2];
extern const char *display_items[2];
diff --git a/openrtx/src/state.c b/openrtx/src/state.c
index fcd54b55..036e8b8c 100644
--- a/openrtx/src/state.c
+++ b/openrtx/src/state.c
@@ -40,7 +40,6 @@ void state_init()
state.charge = battery_getCharge(state.v_bat);
state.rssi = rtx_getRssi();
- state.backlight_level = 255;
state.channelInfoUpdated = true;
state.channel.mode = FM;
state.channel.bandwidth = BW_25;
diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c
index 285feb9c..f3ed7919 100644
--- a/openrtx/src/ui/ui.c
+++ b/openrtx/src/ui/ui.c
@@ -137,6 +137,7 @@ const color_t yellow_fab413 = {250, 180, 19, 255};
layout_t layout;
ui_state_t ui_state;
+settings_t settings;
bool layout_ready = false;
bool redraw_needed = true;
@@ -271,6 +272,11 @@ 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()
@@ -490,8 +496,6 @@ void _ui_fsm_insertVFONumber(kbd_msg_t msg, bool *sync_rtx) {
void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) {
ui_state.input_number = input_getPressedNumber(msg);
- // Backlight
- int32_t new_blight = state.backlight_level;
// CTCSS Encode/Decode Selection
bool tone_tx_enable = state.channel.fm.txToneEn;
bool tone_rx_enable = state.channel.fm.rxToneEn;
@@ -533,16 +537,12 @@ void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) {
*sync_rtx = true;
break;
case 7:
- new_blight += 25;
- new_blight = (new_blight > 255) ? 255 : new_blight;
- state.backlight_level = new_blight;
- platform_setBacklightLevel(state.backlight_level);
+ settings.brightness = (settings.brightness + 25 > 255) ? 255 : settings.brightness + 25;
+ platform_setBacklightLevel(settings.brightness);
break;
case 8:
- new_blight -= 25;
- new_blight = (new_blight < 0) ? 0 : new_blight;
- state.backlight_level = new_blight;
- platform_setBacklightLevel(state.backlight_level);
+ settings.brightness = (settings.brightness - 25 < 0) ? 0 : settings.brightness - 25;
+ platform_setBacklightLevel(settings.brightness);
break;
}
diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c
index 1b898ff3..d9cb1250 100644
--- a/openrtx/src/ui/ui_menu.c
+++ b/openrtx/src/ui/ui_menu.c
@@ -116,7 +116,12 @@ int _ui_getDisplayEntryName(char *buf, uint8_t max_len, uint8_t index)
int _ui_getDisplayValueName(char *buf, uint8_t max_len, uint8_t index)
{
if(index >= display_num) return -1;
- snprintf(buf, max_len, "%s", display_items[index]);
+ uint8_t value = 0;
+ if(strcmp(display_items[index], "Brightness"))
+ value = settings.brightness;
+ else if(strcmp(display_items[index], "Contrast"))
+ value = settings.contrast;
+ snprintf(buf, max_len, "%d", value);
return 0;
}