Add Display Brightness Setting

This commit is contained in:
seiichiro 2021-06-20 17:36:42 +02:00
parent 3109c1168e
commit 6b1889d8f2

View file

@ -31,6 +31,7 @@ enum Settings {
S_NONE,
S_INTERVAL,
S_KEYSET,
S_BRIGHT,
S_EXIT
};
@ -41,6 +42,7 @@ Settings aset = S_NONE; // Selected Setting
#define EEPROM_KEYSET_ADR 0
#define EEPROM_INTERVAL_ADR 1
#define EEPROM_BRIGHTNESS_ADR 2
// LoRa
#include "config.h" // Contains LoRa ABP Keys
@ -54,6 +56,7 @@ uint16_t Frame_Counter_Tx = 0x0001;
uint8_t interval = 20; // Sending Interval in Settings
uint8_t packets = 0; // Sent LoRa Packets
uint8_t keyset = 1; // LoRa KeySet
uint8_t bright = 128; // Brightness
String statusmsg = "";
uint8_t loraBuffer[9]; // Lora Data Packet
@ -95,12 +98,20 @@ void handler(Button2& btn) {
if (keyset > 2)
keyset = 1;
loraKeySetup(keyset);
} else if (aset == S_BRIGHT) {
bright += 32;
if (bright > 255)
bright = 32;
oled.setContrast(bright);
} else {
switch (cset) {
case S_INTERVAL:
cset = S_KEYSET;
break;
case S_KEYSET:
cset = S_BRIGHT;
break;
case S_BRIGHT:
cset = S_EXIT;
break;
case S_EXIT:
@ -125,6 +136,7 @@ void handler(Button2& btn) {
amode = M_NORMAL;
EEPROM.update(EEPROM_KEYSET_ADR, keyset);
EEPROM.update(EEPROM_INTERVAL_ADR, interval);
EEPROM.update(EEPROM_BRIGHTNESS_ADR, bright);
} else if (aset == S_NONE) {
aset = cset;
} else {
@ -150,7 +162,7 @@ void updateDisplay() {
}
if (amode == M_SETUP) {
oled.println ("<< SETUP >>");
oled.println ("**** SETUP ****");
oled.println ("");
char tmp = ' ';
@ -165,8 +177,16 @@ void updateDisplay() {
oled.print(tmp);
tmp = (aset == S_KEYSET) ? '>' : ' ';
oled.print(tmp);
oled.print("ABP KeySet: ");
oled.print("ABP Keys: ");
oled.println(keyset);
tmp = (cset == S_BRIGHT) ? '>' : ' ';
oled.print(tmp);
tmp = (aset == S_BRIGHT) ? '>' : ' ';
oled.print(tmp);
oled.print("Brightn.: ");
oled.println(bright);
oled.println("");
tmp = (cset == S_EXIT) ? '>' : ' ';
oled.print(tmp);
oled.println(" Exit Setup");
@ -234,13 +254,16 @@ void setup() {
oled.clear();
// Get Settings from EEPROM
EEPROM.get(EEPROM_KEYSET_ADR, keyset);
if (keyset > 2) keyset = 1;
if (keyset < 1) keyset = 1;
if (keyset < 1 || keyset > 2) keyset = 1;
EEPROM.get(EEPROM_INTERVAL_ADR, interval);
if (interval < 10 || interval > 30) interval = 20;
EEPROM.get(EEPROM_BRIGHTNESS_ADR, bright);
if (bright < 0 || bright > 255) bright = 128;
oled.setContrast(bright);
// Lora Initialization
rfm.init();
loraKeySetup(keyset);