Revert "Removed all display code if not HAS_DISPLAY"

This reverts commit 3640a62b93.
This commit is contained in:
Charles 2018-04-03 16:14:57 +02:00
parent f4ecc3924b
commit 47f0f90cf3
5 changed files with 75 additions and 137 deletions

View File

@ -289,9 +289,7 @@ void loadConfig() {
ESP_LOGI(TAG, "Done"); ESP_LOGI(TAG, "Done");
// put actions to be triggered on loaded config here // put actions to be triggered on loaded config here
#ifdef HAS_DISPLAY u8x8.setPowerSave(!cfg.screenon); // set display on/off
u8x8.setPowerSave(!cfg.screenon); // set display on/off
#endif
#ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one #ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one
antenna_select(cfg.wifiant); antenna_select(cfg.wifiant);
#endif #endif

View File

@ -49,6 +49,8 @@ extern std::set<uint16_t> macs;
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
extern HAS_DISPLAY u8x8; extern HAS_DISPLAY u8x8;
#else
extern U8X8_NULL u8x8;
#endif #endif
#ifdef BLECOUNTER #ifdef BLECOUNTER

View File

@ -99,18 +99,14 @@ void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running // Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) { if (LMIC.opmode & OP_TXRXPEND) {
ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); ESP_LOGI(TAG, "OP_TXRXPEND, not sending");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "LORA BUSY");
u8x8.drawString(0, 7, "LORA BUSY");
#endif
} else { } else {
// Prepare upstream data transmission at the next possible time. // Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02)); LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02));
ESP_LOGI(TAG, "Packet queued"); ESP_LOGI(TAG, "Packet queued");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "PACKET QUEUED");
u8x8.drawString(0, 7, "PACKET QUEUED");
#endif
} }
// Next TX is scheduled after TX_COMPLETE event. // Next TX is scheduled after TX_COMPLETE event.
} }
@ -119,46 +115,34 @@ void onEvent (ev_t ev) {
switch(ev) { switch(ev) {
case EV_SCAN_TIMEOUT: case EV_SCAN_TIMEOUT:
ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); ESP_LOGI(TAG, "EV_SCAN_TIMEOUT");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "SCAN TIMEOUT");
u8x8.drawString(0, 7, "SCAN TIMEOUT");
#endif
break; break;
case EV_BEACON_FOUND: case EV_BEACON_FOUND:
ESP_LOGI(TAG, "EV_BEACON_FOUND"); ESP_LOGI(TAG, "EV_BEACON_FOUND");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "BEACON FOUND");
u8x8.drawString(0, 7, "BEACON FOUND");
#endif
break; break;
case EV_BEACON_MISSED: case EV_BEACON_MISSED:
ESP_LOGI(TAG, "EV_BEACON_MISSED"); ESP_LOGI(TAG, "EV_BEACON_MISSED");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "BEACON MISSED");
u8x8.drawString(0, 7, "BEACON MISSED");
#endif
break; break;
case EV_BEACON_TRACKED: case EV_BEACON_TRACKED:
ESP_LOGI(TAG, "EV_BEACON_TRACKED"); ESP_LOGI(TAG, "EV_BEACON_TRACKED");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "BEACON TRACKED");
u8x8.drawString(0, 7, "BEACON TRACKED");
#endif
break; break;
case EV_JOINING: case EV_JOINING:
ESP_LOGI(TAG, "EV_JOINING"); ESP_LOGI(TAG, "EV_JOINING");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "JOINING");
u8x8.drawString(0, 7, "JOINING");
#endif
break; break;
case EV_JOINED: case EV_JOINED:
ESP_LOGI(TAG, "EV_JOINED"); ESP_LOGI(TAG, "EV_JOINED");
#ifdef HAS_DISPLAY u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp
u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "JOINED");
u8x8.drawString(0, 7, "JOINED");
#endif
// Disable link check validation (automatically enabled // Disable link check validation (automatically enabled
// during join, but not supported by TTN at this time). // during join, but not supported by TTN at this time).
LMIC_setLinkCheckMode(0); LMIC_setLinkCheckMode(0);
@ -172,50 +156,38 @@ void onEvent (ev_t ev) {
break; break;
case EV_RFU1: case EV_RFU1:
ESP_LOGI(TAG, "EV_RFU1"); ESP_LOGI(TAG, "EV_RFU1");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "RFUI");
u8x8.drawString(0, 7, "RFUI");
#endif
break; break;
case EV_JOIN_FAILED: case EV_JOIN_FAILED:
ESP_LOGI(TAG, "EV_JOIN_FAILED"); ESP_LOGI(TAG, "EV_JOIN_FAILED");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "JOIN FAILED");
u8x8.drawString(0, 7, "JOIN FAILED");
#endif
break; break;
case EV_REJOIN_FAILED: case EV_REJOIN_FAILED:
ESP_LOGI(TAG, "EV_REJOIN_FAILED"); ESP_LOGI(TAG, "EV_REJOIN_FAILED");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "REJOIN FAILED");
u8x8.drawString(0, 7, "REJOIN FAILED");
#endif
break; break;
case EV_TXCOMPLETE: case EV_TXCOMPLETE:
ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "TX COMPLETE");
u8x8.drawString(0, 7, "TX COMPLETE");
#endif
if (LMIC.txrxFlags & TXRX_ACK) { if (LMIC.txrxFlags & TXRX_ACK) {
ESP_LOGI(TAG, "Received ack"); ESP_LOGI(TAG, "Received ack");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "RECEIVED ACK");
u8x8.drawString(0, 7, "RECEIVED ACK");
#endif
} }
if (LMIC.dataLen) { if (LMIC.dataLen) {
ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen);
#ifdef HAS_DISPLAY u8x8.clearLine(6);
u8x8.clearLine(6); u8x8.setCursor(0, 6);
u8x8.setCursor(0, 6); u8x8.printf("Rcvd %i bytes", LMIC.dataLen);
u8x8.printf("Rcvd %i bytes", LMIC.dataLen); u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.setCursor(0, 7);
u8x8.setCursor(0, 7); // LMIC.snr = SNR twos compliment [dB] * 4
// LMIC.snr = SNR twos compliment [dB] * 4 // LMIC.rssi = RSSI [dBm] (-196...+63)
// LMIC.rssi = RSSI [dBm] (-196...+63) u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4);
u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4);
#endif
// check if payload received on command port, then call remote command interpreter // check if payload received on command port, then call remote command interpreter
if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) { if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) {
// caution: buffering LMIC values here because rcommand() can modify LMIC.frame // caution: buffering LMIC values here because rcommand() can modify LMIC.frame
@ -230,47 +202,35 @@ void onEvent (ev_t ev) {
break; break;
case EV_LOST_TSYNC: case EV_LOST_TSYNC:
ESP_LOGI(TAG, "EV_LOST_TSYNC"); ESP_LOGI(TAG, "EV_LOST_TSYNC");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "LOST TSYNC");
u8x8.drawString(0, 7, "LOST TSYNC");
#endif
break; break;
case EV_RESET: case EV_RESET:
ESP_LOGI(TAG, "EV_RESET"); ESP_LOGI(TAG, "EV_RESET");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "RESET");
u8x8.drawString(0, 7, "RESET");
#endif
break; break;
case EV_RXCOMPLETE: case EV_RXCOMPLETE:
// data received in ping slot // data received in ping slot
ESP_LOGI(TAG, "EV_RXCOMPLETE"); ESP_LOGI(TAG, "EV_RXCOMPLETE");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "RX COMPLETE");
u8x8.drawString(0, 7, "RX COMPLETE");
#endif
break; break;
case EV_LINK_DEAD: case EV_LINK_DEAD:
ESP_LOGI(TAG, "EV_LINK_DEAD"); ESP_LOGI(TAG, "EV_LINK_DEAD");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "LINK DEAD");
u8x8.drawString(0, 7, "LINK DEAD");
#endif
break; break;
case EV_LINK_ALIVE: case EV_LINK_ALIVE:
ESP_LOGI(TAG, "EV_LINK_ALIVE"); ESP_LOGI(TAG, "EV_LINK_ALIVE");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.drawString(0, 7, "LINK ALIVE");
u8x8.drawString(0, 7, "LINK ALIVE");
#endif
break; break;
default: default:
ESP_LOGI(TAG, "Unknown event"); ESP_LOGI(TAG, "Unknown event");
#ifdef HAS_DISPLAY u8x8.clearLine(7);
u8x8.clearLine(7); u8x8.setCursor(0, 7);
u8x8.setCursor(0, 7); u8x8.printf("UNKNOWN EVENT %d", ev);
u8x8.printf("UNKNOWN EVENT %d", ev);
#endif
break; break;
} }
} }

View File

@ -60,9 +60,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
if (newmac.second) { // first time seen this WIFI or BLE MAC if (newmac.second) { // first time seen this WIFI or BLE MAC
snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value
#ifdef HAS_DISPLAY u8x8.draw2x2String(0, 0, counter);
u8x8.draw2x2String(0, 0, counter);
#endif
ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> #%05i", typebuff, rssi, hashedmac, macs.size()); ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> #%05i", typebuff, rssi, hashedmac, macs.size());
} else { // already seen WIFI or BLE MAC } else { // already seen WIFI or BLE MAC
ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi); ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi);
@ -89,10 +87,8 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
// Current devices seen on this scan session // Current devices seen on this scan session
currentScanDevice++; currentScanDevice++;
mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE);
#ifdef HAS_DISPLAY u8x8.setCursor(12,3);
u8x8.setCursor(12,3); u8x8.printf("%d", currentScanDevice);
u8x8.printf("%d", currentScanDevice);
#endif
rgb_set_color(COLOR_NONE); rgb_set_color(COLOR_NONE);
} }
@ -101,21 +97,17 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void BLECount() { void BLECount() {
int blenum = 0; // Total device seen on this scan session int blenum = 0; // Total device seen on this scan session
currentScanDevice = 0; // Set 0 seen device on this scan session currentScanDevice = 0; // Set 0 seen device on this scan session
#ifdef HAS_DISPLAY u8x8.clearLine(3);
u8x8.clearLine(3); u8x8.drawString(0,3,"BLE Scan...");
u8x8.drawString(0,3,"BLE Scan...");
#endif
BLEDevice::init(PROGNAME); BLEDevice::init(PROGNAME);
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime); BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime);
blenum=foundDevices.getCount(); blenum=foundDevices.getCount();
#ifdef HAS_DISPLAY u8x8.clearLine(3);
u8x8.clearLine(3); u8x8.setCursor(0,3);
u8x8.setCursor(0,3); u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum);
u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum);
#endif
} }
#endif #endif

View File

@ -59,11 +59,9 @@ void set_reset(int val) {
switch (val) { switch (val) {
case 0: // restart device case 0: // restart device
ESP_LOGI(TAG, "Remote command: restart device"); ESP_LOGI(TAG, "Remote command: restart device");
#ifdef HAS_DISPLAY u8x8.clearLine(5);
u8x8.clearLine(5); u8x8.setCursor(0, 5);
u8x8.setCursor(0, 5); u8x8.printf("Reset pending ");
u8x8.printf("Reset pending ");
#endif
vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server
esp_restart(); esp_restart();
break; break;
@ -73,20 +71,16 @@ void set_reset(int val) {
wifis.clear(); // clear Wifi macs container wifis.clear(); // clear Wifi macs container
bles.clear(); // clear BLE macs container bles.clear(); // clear BLE macs container
salt = random(65536); // get new 16bit random for salting hashes salt = random(65536); // get new 16bit random for salting hashes
#ifdef HAS_DISPLAY u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter u8x8.clearLine(5);
u8x8.clearLine(5); u8x8.setCursor(0, 5);
u8x8.setCursor(0, 5); u8x8.printf("Reset counter ");
u8x8.printf("Reset counter ");
#endif
break; break;
case 2: // reset device to factory settings case 2: // reset device to factory settings
ESP_LOGI(TAG, "Remote command: reset device to factory settings"); ESP_LOGI(TAG, "Remote command: reset device to factory settings");
#ifdef HAS_DISPLAY u8x8.clearLine(5);
u8x8.clearLine(5); u8x8.setCursor(0, 5);
u8x8.setCursor(0, 5); u8x8.printf("Factory reset ");
u8x8.printf("Factory reset ");
#endif
eraseConfig(); eraseConfig();
break; break;
} }
@ -95,11 +89,9 @@ void set_reset(int val) {
void set_rssi(int val) { void set_rssi(int val) {
cfg.rssilimit = val * -1; cfg.rssilimit = val * -1;
ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit); ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit);
#ifdef HAS_DISPLAY u8x8.clearLine(5);
u8x8.clearLine(5); u8x8.setCursor(0, 5);
u8x8.setCursor(0, 5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit);
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit);
#endif
}; };
void set_wifiscancycle(int val) { void set_wifiscancycle(int val) {
@ -145,9 +137,7 @@ void set_screensaver(int val) {
case 1: cfg.screensaver = val; break; case 1: cfg.screensaver = val; break;
default: cfg.screensaver = 0; break; default: cfg.screensaver = 0; break;
} }
#ifdef HAS_DISPLAY u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off
u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off
#endif
}; };
void set_display(int val) { void set_display(int val) {
@ -156,9 +146,7 @@ void set_display(int val) {
case 1: cfg.screenon = val; break; case 1: cfg.screenon = val; break;
default: cfg.screenon = 0; break; default: cfg.screenon = 0; break;
} }
#ifdef HAS_DISPLAY u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off
u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off
#endif
}; };
void set_lorasf(int val) { void set_lorasf(int val) {
@ -182,9 +170,7 @@ void set_blescan(int val) {
default: default:
cfg.blescan = 0; cfg.blescan = 0;
btStop(); btStop();
#ifdef HAS_DISPLAY u8x8.clearLine(3); // clear BLE results from display
u8x8.clearLine(3); // clear BLE results from display
#endif
break; break;
} }
}; };