Move brightness from state_t to settings_t, add Contrast

replace/3544677a94bda1645c59d8a7fa6a116040c48379
Federico Amedeo Izzo 2021-01-29 22:13:47 +01:00
rodzic 8ded5fc9b6
commit 1f240ba132
6 zmienionych plików z 49 dodań i 13 usunięć

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#ifndef SETTINGS_H
#define SETTINGS_H
typedef struct
{
uint8_t brightness;
uint8_t contrast;
}
settings_t;
#endif /* SETTINGS_H */

Wyświetl plik

@ -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;

Wyświetl plik

@ -27,6 +27,7 @@
#include <stdint.h>
#include <event.h>
#include <hwconfig.h>
#include <settings.h>
// 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];

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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;
}