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