use PWR button as button2 on T-Beam 1.0

This commit is contained in:
Hansi, dl9rdz 2020-01-31 19:33:55 +01:00
parent 2a364870e1
commit cd2fa51360
6 changed files with 61 additions and 22 deletions

View File

@ -32,7 +32,8 @@ AsyncWebSocket ws("/ws");
AXP20X_Class axp; AXP20X_Class axp;
#define PMU_IRQ 35 #define PMU_IRQ 35
SemaphoreHandle_t axpSemaphore;
bool pmu_irq = false;
String updateHost = "rdzsonde.mooo.com"; String updateHost = "rdzsonde.mooo.com";
int updatePort = 80; int updatePort = 80;
@ -359,9 +360,9 @@ void addSondeStatus(char *ptr, int i)
ts = *gmtime(&t); ts = *gmtime(&t);
sprintf(ptr + strlen(ptr), "<tr><td>Frame# %d, Sats=%d, %04d-%02d-%02d %02d:%02d:%02d</td></tr>", sprintf(ptr + strlen(ptr), "<tr><td>Frame# %d, Sats=%d, %04d-%02d-%02d %02d:%02d:%02d</td></tr>",
s->frame, s->sats, ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec); s->frame, s->sats, ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec);
if(s->type == STYPE_RS41) { if (s->type == STYPE_RS41) {
sprintf(ptr + strlen(ptr), "<tr><td>Burst-KT=%d Launch-KT=%d Countdown=%d (vor %ds)</td></tr>\n", sprintf(ptr + strlen(ptr), "<tr><td>Burst-KT=%d Launch-KT=%d Countdown=%d (vor %ds)</td></tr>\n",
s->burstKT, s->launchKT, s->countKT, ((uint16_t)s->frame-s->crefKT)); s->burstKT, s->launchKT, s->countKT, ((uint16_t)s->frame - s->crefKT));
} }
sprintf(ptr + strlen(ptr), "<tr><td><a target=\"_empty\" href=\"geo:%.6f,%.6f\">GEO-App</a> - ", s->lat, s->lon); sprintf(ptr + strlen(ptr), "<tr><td><a target=\"_empty\" href=\"geo:%.6f,%.6f\">GEO-App</a> - ", s->lat, s->lon);
sprintf(ptr + strlen(ptr), "<a target=\"_empty\" href=\"https://wx.dl2mf.de/?%s\">WX.DL2MF.de</a> - ", s->id); sprintf(ptr + strlen(ptr), "<a target=\"_empty\" href=\"https://wx.dl2mf.de/?%s\">WX.DL2MF.de</a> - ", s->id);
@ -459,6 +460,7 @@ struct st_configitems config_list[] = {
{"tft_orient", "TFT orientation (0/1/2/3), OLED flip: 3", 0, &sonde.config.tft_orient}, {"tft_orient", "TFT orientation (0/1/2/3), OLED flip: 3", 0, &sonde.config.tft_orient},
{"button_pin", "Button input port", -4, &sonde.config.button_pin}, {"button_pin", "Button input port", -4, &sonde.config.button_pin},
{"button2_pin", "Button 2 input port", -4, &sonde.config.button2_pin}, {"button2_pin", "Button 2 input port", -4, &sonde.config.button2_pin},
{"button2_axp", "Use AXP192 PWR as Button 2", 0, &sonde.config.button2_axp},
{"touch_thresh", "Touch button threshold<br>(0 for calib mode)", 0, &sonde.config.touch_thresh}, {"touch_thresh", "Touch button threshold<br>(0 for calib mode)", 0, &sonde.config.touch_thresh},
{"power_pout", "Power control port", 0, &sonde.config.power_pout}, {"power_pout", "Power control port", 0, &sonde.config.power_pout},
{"led_pout", "LED output port", 0, &sonde.config.led_pout}, {"led_pout", "LED output port", 0, &sonde.config.led_pout},
@ -477,9 +479,16 @@ void addConfigNumEntry(char *ptr, int idx, const char *label, int *value) {
label, idx, *value); label, idx, *value);
} }
void addConfigButtonEntry(char *ptr, int idx, const char *label, int *value) { void addConfigButtonEntry(char *ptr, int idx, const char *label, int *value) {
int v = *value, ck = 0;
if (v == 255) v = -1;
if (v != -1) {
if (v & 128) ck = 1;
v = v & 127;
}
sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" size=\"3\" value=\"%d\"/>", sprintf(ptr + strlen(ptr), "<tr><td>%s</td><td><input name=\"CFG%d\" type=\"text\" size=\"3\" value=\"%d\"/>",
label, idx, 127 & *value); label, idx, v);
sprintf(ptr + strlen(ptr), "<input type=\"checkbox\" name=\"TO%d\"%s> Touch </td></tr>\n", idx, 128 & *value ? " checked" : ""); sprintf(ptr + strlen(ptr), "<input type=\"checkbox\" name=\"TO%d\"%s> Touch </td></tr>\n", idx, ck ? " 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
@ -583,7 +592,8 @@ const char *handleConfigPost(AsyncWebServerRequest *request) {
snprintf(tmp, 10, "TO%d", idx); snprintf(tmp, 10, "TO%d", idx);
AsyncWebParameter *touch = request->getParam(tmp, true); AsyncWebParameter *touch = request->getParam(tmp, true);
if (touch) { if (touch) {
int i = atoi(strvalue.c_str()) + 128; int i = atoi(strvalue.c_str());
if (i != -1 && i != 255) i += 128;
strvalue = String(i); strvalue = String(i);
} }
} }
@ -747,7 +757,7 @@ const char *sendGPX(AsyncWebServerRequest * request) {
} }
SondeInfo *si = &sonde.sondeList[index]; SondeInfo *si = &sonde.sondeList[index];
strcpy(si->id, "test"); strcpy(si->id, "test");
si->lat=48; si->lon=11; si->alt=500; si->lat = 48; si->lon = 11; si->alt = 500;
snprintf(ptr, 10240, "<?xml version='1.0' encoding='UTF-8'?>\n" snprintf(ptr, 10240, "<?xml version='1.0' encoding='UTF-8'?>\n"
"<gpx version=\"1.1\" creator=\"http://rdzsonde.local\" xmlns=\"http://www.topografix.com/GPX/1/1\" " "<gpx version=\"1.1\" creator=\"http://rdzsonde.local\" xmlns=\"http://www.topografix.com/GPX/1/1\" "
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
@ -762,17 +772,17 @@ const char *sendGPX(AsyncWebServerRequest * request) {
return message; return message;
} }
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) {
if(type == WS_EVT_CONNECT){ if (type == WS_EVT_CONNECT) {
Serial.println("Websocket client connection received"); Serial.println("Websocket client connection received");
client->text("Hello from ESP32 Server"); client->text("Hello from ESP32 Server");
} else if(type == WS_EVT_DISCONNECT){ } else if (type == WS_EVT_DISCONNECT) {
Serial.println("Client disconnected"); Serial.println("Client disconnected");
} }
} }
#if 0 #if 0
void onWebSocketEvent(uint8_t clientNum, WStype_t type, uint8_t *payload, size_t length) { void onWebSocketEvent(uint8_t clientNum, WStype_t type, uint8_t *payload, size_t length) {
switch(type) { switch (type) {
case WStype_DISCONNECTED: case WStype_DISCONNECTED:
Serial.printf("[%u] WS client disconnected\n", clientNum); Serial.printf("[%u] WS client disconnected\n", clientNum);
break; break;
@ -1227,14 +1237,31 @@ int getKeyPress() {
} }
int getKey2Press() { int getKey2Press() {
if (sonde.config.button2_axp) {
// Use AXP power button as second button
if (pmu_irq) {
Serial.println("PMU_IRQ is set\n");
xSemaphoreTake( axpSemaphore, portMAX_DELAY );
axp.readIRQ();
if (axp.isPEKShortPressIRQ()) {
button2.pressed = KP_SHORT;
button2.keydownTime = my_millis();
}
if (axp.isPEKLongtPressIRQ()) {
button2.pressed = KP_MID;
button2.keydownTime = my_millis();
}
pmu_irq = false;
axp.clearIRQ();
xSemaphoreGive( axpSemaphore );
}
}
KeyPress p = button2.pressed; KeyPress p = button2.pressed;
button2.pressed = KP_NONE; button2.pressed = KP_NONE;
//Serial.printf("button2 press: %d at %ld (%d)\n", p, button2.keydownTime, button2.numberKeyPresses); //Serial.printf("button2 press: %d at %ld (%d)\n", p, button2.keydownTime, button2.numberKeyPresses);
return p; return p;
} }
int hasKeyPress() {
return button1.pressed || button2.pressed;
}
int getKeyPressEvent() { int getKeyPressEvent() {
int p = getKeyPress(); int p = getKeyPress();
if (p == KP_NONE) { if (p == KP_NONE) {
@ -1290,8 +1317,6 @@ int scanI2Cdevice(void)
} }
extern int initlevels[40]; extern int initlevels[40];
bool pmu_irq = false;
void setup() void setup()
{ {
@ -1303,6 +1328,9 @@ void setup()
Serial.printf("%d:%d ", i, v); Serial.printf("%d:%d ", i, v);
} }
Serial.println(""); Serial.println("");
axpSemaphore = xSemaphoreCreateBinary();
xSemaphoreGive(axpSemaphore);
#if 0 #if 0
delay(2000); delay(2000);
// temporary test // temporary test
@ -1369,7 +1397,8 @@ void setup()
pmu_irq = true; pmu_irq = true;
}, FALLING); }, FALLING);
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1); //axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1);
axp.enableIRQ( AXP202_PEK_LONGPRESS_IRQ | AXP202_PEK_SHORTPRESS_IRQ, 1 );
axp.clearIRQ(); axp.clearIRQ();
int ndevices = scanI2Cdevice(); int ndevices = scanI2Cdevice();
if (sonde.fingerprint != 17 || ndevices > 0) break; // only retry for fingerprint 17 (startup problems of new t-beam with oled) if (sonde.fingerprint != 17 || ndevices > 0) break; // only retry for fingerprint 17 (startup problems of new t-beam with oled)

View File

@ -7,6 +7,7 @@
# No specification in config file: try autodetection (gpio4 pin level at startup) # No specification in config file: try autodetection (gpio4 pin level at startup)
#button_pin=0 #button_pin=0
#button2_pin=255 #button2_pin=255
#button2_axp=0
# LED port # LED port
led_pout=9 led_pout=9
# OLED Setup is depending on hardware of LoRa board # OLED Setup is depending on hardware of LoRa board

View File

@ -679,9 +679,6 @@ uint8_t SX1278FSK::receive()
return state; return state;
} }
// ugly. shouldn't be here in a nice software design
extern int hasKeyPress();
/* /*
Function: Configures the module to receive a packet Function: Configures the module to receive a packet
Returns: Integer that determines if there has been any error Returns: Integer that determines if there has been any error

View File

@ -23,6 +23,8 @@ extern MicroNMEA nmea;
extern AXP20X_Class axp; extern AXP20X_Class axp;
extern bool axp192_found; extern bool axp192_found;
extern SemaphoreHandle_t axpSemaphore;
SPIClass spiDisp(HSPI); SPIClass spiDisp(HSPI);
@ -1353,6 +1355,8 @@ void Display::drawBatt(DispEntry *de) {
float val; float val;
char buf[30]; char buf[30];
if(!axp192_found) return; if(!axp192_found) return;
xSemaphoreTake( axpSemaphore, portMAX_DELAY );
switch(de->extra[0]) { switch(de->extra[0]) {
case 'S': case 'S':
if(!axp.isBatteryConnect()) { if(!axp.isBatteryConnect()) {
@ -1389,6 +1393,7 @@ void Display::drawBatt(DispEntry *de) {
default: default:
*buf=0; *buf=0;
} }
xSemaphoreGive( axpSemaphore );
rdis->setFont(de->fmt); rdis->setFont(de->fmt);
drawString(de, buf); drawString(de, buf);
} }

View File

@ -78,6 +78,7 @@ void Sonde::defaultConfig() {
config.oled_rst = 16; config.oled_rst = 16;
config.disptype = 0; config.disptype = 0;
config.tft_orient = 1; config.tft_orient = 1;
config.button2_axp = 0;
if(initlevels[16]==0) { if(initlevels[16]==0) {
config.oled_sda = 4; config.oled_sda = 4;
config.oled_scl = 15; config.oled_scl = 15;
@ -94,6 +95,9 @@ void Sonde::defaultConfig() {
Serial.println("Autoconfig: looks like T-Beam 1.0 board"); Serial.println("Autoconfig: looks like T-Beam 1.0 board");
config.button_pin = 38; config.button_pin = 38;
config.button2_pin = 15 + 128; //T4 + 128; // T4 = GPIO13 config.button2_pin = 15 + 128; //T4 + 128; // T4 = GPIO13
// Maybe in future use as default only PWR as button2?
//config.button2_pin = 255;
config.button2_axp = 1;
config.gps_rxd = 34; config.gps_rxd = 34;
// Check for I2C-Display@21,22 // Check for I2C-Display@21,22
#define SSD1306_ADDRESS 0x3c #define SSD1306_ADDRESS 0x3c
@ -204,6 +208,8 @@ void Sonde::setConfig(const char *cfg) {
config.button_pin = atoi(val); config.button_pin = atoi(val);
} else if(strcmp(cfg,"button2_pin")==0) { } else if(strcmp(cfg,"button2_pin")==0) {
config.button2_pin = atoi(val); config.button2_pin = atoi(val);
} else if(strcmp(cfg,"button2_axp")==0) {
config.button2_axp = atoi(val);
} else if(strcmp(cfg,"touch_thresh")==0) { } else if(strcmp(cfg,"touch_thresh")==0) {
config.touch_thresh = atoi(val); config.touch_thresh = atoi(val);
} else if(strcmp(cfg,"led_pout")==0) { } else if(strcmp(cfg,"led_pout")==0) {

View File

@ -149,6 +149,7 @@ typedef struct st_rdzconfig {
// hardware configuration // hardware configuration
int button_pin; // PIN port number menu button (+128 for touch mode) int button_pin; // PIN port number menu button (+128 for touch mode)
int button2_pin; // PIN port number menu button (+128 for touch mode) int button2_pin; // PIN port number menu button (+128 for touch mode)
int button2_axp; // Use AXP192 power button as button2
int touch_thresh; // Threshold value (0..100) for touch input button int touch_thresh; // Threshold value (0..100) for touch input button
int led_pout; // POUT port number of LED (used as serial monitor) int led_pout; // POUT port number of LED (used as serial monitor)
int power_pout; // Power control pin (for Heltec v2) int power_pout; // Power control pin (for Heltec v2)