nicer configuration of button/touch in web interface; autoconfig enhanced

This commit is contained in:
Hansi, dl9rdz 2019-06-08 12:55:54 +02:00
parent 2928b41270
commit ff035eabd4
3 changed files with 85 additions and 32 deletions

View File

@ -423,8 +423,8 @@ struct st_configitems config_list[] = {
{"oled_sda", "OLED SDA (needs reboot)", 0, &sonde.config.oled_sda}, {"oled_sda", "OLED SDA (needs reboot)", 0, &sonde.config.oled_sda},
{"oled_scl", "OLED SCL (needs reboot)", 0, &sonde.config.oled_scl}, {"oled_scl", "OLED SCL (needs reboot)", 0, &sonde.config.oled_scl},
{"oled_rst", "OLED RST (needs reboot)", 0, &sonde.config.oled_rst}, {"oled_rst", "OLED RST (needs reboot)", 0, &sonde.config.oled_rst},
{"button_pin", "Button input port (needs reboot)", 0, &sonde.config.button_pin}, {"button_pin", "Button input port (needs reboot)", -4, &sonde.config.button_pin},
{"button2_pin", "Button 2 input port (needs reboot)", 0, &sonde.config.button2_pin}, {"button2_pin", "Button 2 input port (needs reboot)", -4, &sonde.config.button2_pin},
{"touch_thresh", "Touch button threshold (needs reboot)", 0, &sonde.config.touch_thresh}, {"touch_thresh", "Touch button threshold (needs reboot)", 0, &sonde.config.touch_thresh},
{"led_pout", "LED output port (needs reboot)", 0, &sonde.config.led_pout}, {"led_pout", "LED output port (needs reboot)", 0, &sonde.config.led_pout},
{"gps_rxd", "GPS RXD pin (-1 to disable)", 0, &sonde.config.gps_rxd}, {"gps_rxd", "GPS RXD pin (-1 to disable)", 0, &sonde.config.gps_rxd},
@ -440,6 +440,11 @@ void addConfigNumEntry(char *ptr, int idx, const char *label, int *value) {
sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%d\"/></td></tr>\n", sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" value=\"%d\"/></td></tr>\n",
label, idx, *value); label, idx, *value);
} }
void addConfigButtonEntry(char *ptr, int idx, const char *label, int *value) {
sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" size=\"3\" value=\"%d\"/>",
label, idx, 127 & *value);
sprintf(ptr + strlen(ptr), "<input type=\"checkbox\" name=\"TO%d\"%s> Touch </td></tr>\n", idx, 128 & *value ? " checked" : "");
}
void addConfigTypeEntry(char *ptr, int idx, const char *label, int *value) { void addConfigTypeEntry(char *ptr, int idx, const char *label, int *value) {
// TODO // TODO
} }
@ -467,6 +472,9 @@ const char *createConfigForm() {
case 0: case 0:
addConfigNumEntry(ptr, i, config_list[i].label, (int *)config_list[i].data); addConfigNumEntry(ptr, i, config_list[i].label, (int *)config_list[i].data);
break; break;
case -4:
addConfigButtonEntry(ptr, i, config_list[i].label, (int *)config_list[i].data);
break;
default: default:
addConfigStringEntry(ptr, i, config_list[i].label, config_list[i].type, (char *)config_list[i].data); addConfigStringEntry(ptr, i, config_list[i].label, config_list[i].type, (char *)config_list[i].data);
break; break;
@ -504,6 +512,15 @@ const char *handleConfigPost(AsyncWebServerRequest *request) {
AsyncWebParameter *value = request->getParam(label, true); AsyncWebParameter *value = request->getParam(label, true);
if (!value) continue; if (!value) continue;
String strvalue = value->value(); String strvalue = value->value();
if (config_list[idx].type == -4) { // input button port with "touch" checkbox
char tmp[10];
snprintf(tmp, 10, "TO%d", idx);
AsyncWebParameter *touch = request->getParam(tmp, true);
if (touch) {
int i = atoi(strvalue.c_str()) + 128;
strvalue = String(i);
}
}
Serial.printf("Processing %s=%s\n", config_list[idx].name, strvalue.c_str()); Serial.printf("Processing %s=%s\n", config_list[idx].name, strvalue.c_str());
f.printf("%s=%s\n", config_list[idx].name, strvalue.c_str()); f.printf("%s=%s\n", config_list[idx].name, strvalue.c_str());
} }
@ -885,14 +902,17 @@ void sx1278Task(void *parameter) {
(2) set output flag receiveResult (success/error/timeout and keybord events) (2) set output flag receiveResult (success/error/timeout and keybord events)
*/ */
Serial.printf("rx task: activate=%d mainstate=%d\n", rxtask.activate, rxtask.mainState);
while (1) { while (1) {
if (rxtask.activate >= 128) { if (rxtask.activate >= 128) {
// activating sx1278 background task... // activating sx1278 background task...
Serial.printf("rx task: activate=%d mainstate=%d\n", rxtask.activate, rxtask.mainState);
rxtask.mainState = ST_DECODER; rxtask.mainState = ST_DECODER;
rxtask.currentSonde = rxtask.activate & 0x7F; rxtask.currentSonde = rxtask.activate & 0x7F;
Serial.println("rx task: calling sonde.setup()"); Serial.println("rx task: calling sonde.setup()");
sonde.setup(); sonde.setup();
} else if (rxtask.activate != -1) {
Serial.printf("rx task: activate=%d mainstate=%d\n", rxtask.activate, rxtask.mainState);
rxtask.mainState = rxtask.activate;
} }
rxtask.activate = -1; rxtask.activate = -1;
/* only if mainState is ST_DECODER */ /* only if mainState is ST_DECODER */
@ -900,13 +920,6 @@ void sx1278Task(void *parameter) {
delay(100); delay(100);
continue; continue;
} }
#if 0
if (resetup) {
resetup = false;
sonde.setup();
}
//Serial.println("rx task: calling sonde.receive()");
#endif
sonde.receive(); sonde.receive();
delay(20); delay(20);
} }
@ -933,7 +946,7 @@ void IRAM_ATTR touchISR2() {
} }
} }
// TODO: touchRead in ISR is also a bad idea. // touchRead in ISR is also a bad idea. Now moved to Ticker task
void checkTouchButton(Button & button) { void checkTouchButton(Button & button) {
if (button.isTouched) { if (button.isTouched) {
int tmp = touchRead(button.pin & 0x7f); int tmp = touchRead(button.pin & 0x7f);

View File

@ -38,24 +38,33 @@ int getKeyPressEvent(); /* in RX_FSK.ino */
Sonde::Sonde() { Sonde::Sonde() {
sondeList = (SondeInfo *)malloc((MAXSONDE+1)*sizeof(SondeInfo)); sondeList = (SondeInfo *)malloc((MAXSONDE+1)*sizeof(SondeInfo));
memset(sondeList, 0, (MAXSONDE+1)*sizeof(SondeInfo)); memset(sondeList, 0, (MAXSONDE+1)*sizeof(SondeInfo));
config.button_pin = 0; config.touch_thresh = 70;
config.button2_pin = T4 + 128; // T4 == GPIO13, should be ok for v1 and v2
config.touch_thresh = 60;
config.led_pout = 9; config.led_pout = 9;
// Try autodetecting board type // Try autodetecting board type
// Seems like on startup, GPIO4 is 1 on v1 boards, 0 on v2.1 boards? // Seems like on startup, GPIO4 is 1 on v1 boards, 0 on v2.1 boards?
int autodetect = gpio_get_level((gpio_num_t)4); int autodetect = gpio_get_level((gpio_num_t)16);
if(autodetect==1) { config.gps_rxd = -1;
config.gps_txd = -1;
if(autodetect==0) {
config.oled_sda = 4; config.oled_sda = 4;
config.oled_scl = 15; config.oled_scl = 15;
config.button_pin = 0;
config.button2_pin = T4 + 128; // T4 == GPIO13
} else { } else {
config.oled_sda = 21; config.oled_sda = 21;
config.oled_scl = 22; config.oled_scl = 22;
autodetect = gpio_get_level((gpio_num_t)17);
if(autodetect==0) { // T-Beam
config.button_pin = 39;
config.button2_pin = T4 + 128; // T4 == GPIO13
config.gps_rxd = 12;
} else {
config.button_pin = 2 + 128; // GPIO2 / T2
config.button2_pin = 14 + 128; // GPIO14 / T6
}
} }
// //
config.oled_rst = 16; config.oled_rst = 16;
config.gps_rxd = -1;
config.gps_txd = -1;
config.noisefloor = -125; config.noisefloor = -125;
strcpy(config.call,"NOCALL"); strcpy(config.call,"NOCALL");
strcpy(config.passcode, "---"); strcpy(config.passcode, "---");
@ -322,8 +331,11 @@ void Sonde::receive() {
// handled here... // handled here...
nextRxSonde(); nextRxSonde();
action = ACT_SONDE(rxtask.currentSonde); action = ACT_SONDE(rxtask.currentSonde);
if(rxtask.activate==-1) {
// race condition here. maybe better use mutex. TODO
rxtask.activate = action; rxtask.activate = action;
} }
}
res = (action<<8) | (res&0xff); res = (action<<8) | (res&0xff);
Serial.printf("receive Result is %04x\n", res); Serial.printf("receive Result is %04x\n", res);
// let waitRXcomplete resume... // let waitRXcomplete resume...
@ -471,23 +483,10 @@ void Sonde::updateDisplayIP() {
disp.updateDisplayIP(); disp.updateDisplayIP();
} }
// Probing RS41
// 40x.xxx MHz
void Sonde::updateDisplayScanner() { void Sonde::updateDisplayScanner() {
disp.setLayout(0); disp.setLayout(0);
disp.updateDisplay(); disp.updateDisplay();
disp.setLayout(config.display); disp.setLayout(config.display);
#if 0
char buf[16];
u8x8->setFont(u8x8_font_7x14_1x2_r);
u8x8->drawString(0, 0, "Scan:");
u8x8->drawString(8, 0, sondeTypeStr[si()->type]);
snprintf(buf, 16, "%3.3f MHz", si()->freq);
u8x8->drawString(0,3, buf);
snprintf(buf, 16, "%s", si()->launchsite);
u8x8->drawString(0,5, buf);
updateDisplayIP();
#endif
} }
void Sonde::updateDisplay() void Sonde::updateDisplay()

View File

@ -0,0 +1,41 @@
Heltec board
(sda,scl: 4,15) (same as LORA v1.0)
0:1 1:0 2:0 3:1 4:0 5:1 6:0 7:1 8:0 9:1 10:1 11:1 12:0 13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:1 22:0 23:0 24:0 25:0 26:0 27:0 28:0 29:0 30:0 31:0 32:0 33:0 34:0 35:0 36:0 37:0 38:0
TTGO LORA32 v2.1_1.6 (button1: touch gpio 2 => 130; button2: touch gpio14 => 142)
(sda,scl: 21,22)
0:1 1:0 2:0 3:1 4:0 5:1 6:0 7:1 8:0 9:1 10:1 11:1 12:0 13:0 14:1 15*1 16*1 17*1 18:0 19:0 20:0 21:1 22*1 23*1 24:0 25:0 26:0 27:0 28:0 29:0 30:0 31:0 32:0 33:0 34:0 35:0 36:0 37:0 38:0
TTGO LORA v1.0
(sda,scl: 4,15) (button1: 0) (button2: touch gpio13 = 141)
0:1 1:0 2:0 3:1 4*1 5:1 6:0 7:1 8:0 9:1 10:1 11:1 12:0 13:0 14:1 15*1 16*0 17*0 18:0 19:0 20:0 21:0 22*0 23*0 24:0 25:0 26:0 27:0 28:0 29:0 30:0 31:0 32:0 33:0 34:0 35:0 36:0 37:0 38:0
TTGO T-Beam
(sda,scl: 21,22) (button1: 39) (button2: touch gpio13 = 141) (gps rx: 12)
0:1 1:0 2:0 3:1 4:0 5:1 6:0 7:1 8:0 9:1 10:1 11:1 12:0 13:0 14:1 15:1 16:1 17:0 18:0 19:0 20:0 21:1 22:1 23:1 24:0 25:0 26:0 27:0 28:0 29:0 30:0 31:0 32:0 33:0 34:0 35:0 36:0 37:0 38:0
Current autodetect strategy:
RST always set to 16
GPIO16=0 (GPio22,23 would also work):
==Heltec or TTGO LORA v1.0==
SDA,SCL set to (4,15)
Button 1 set to GPIO 0
Button 2 set to Touch in GPIO 13 (141)
otherwise
==LORA32 v2.1 or T-Beam==
SDA,SCL set to (21,22)
GPIO17=0:
== T-BEAM =
GPS RX set to 12
Button 1 set to GPIO39
Button 2 set to Touch GPIO13 (141)
otherweise:
GPS disabled
Button 1 set to Touch GPIO2 (130)
Button 2 set to Touch GPIO14 (142)