diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 3978f55b..ba39b8af 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -289,9 +289,7 @@ void loadConfig() { ESP_LOGI(TAG, "Done"); // put actions to be triggered on loaded config here - #ifdef HAS_DISPLAY - u8x8.setPowerSave(!cfg.screenon); // set display on/off - #endif + u8x8.setPowerSave(!cfg.screenon); // set display on/off #ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one antenna_select(cfg.wifiant); #endif diff --git a/src/globals.h b/src/globals.h index 9a65a3b8..1ef61705 100644 --- a/src/globals.h +++ b/src/globals.h @@ -49,6 +49,8 @@ extern std::set macs; #ifdef HAS_DISPLAY extern HAS_DISPLAY u8x8; +#else + extern U8X8_NULL u8x8; #endif #ifdef BLECOUNTER diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 65812d40..0f0f86eb 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -99,18 +99,14 @@ void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LORA BUSY"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LORA BUSY"); } else { // Prepare upstream data transmission at the next possible time. LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02)); ESP_LOGI(TAG, "Packet queued"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "PACKET QUEUED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "PACKET QUEUED"); } // Next TX is scheduled after TX_COMPLETE event. } @@ -119,46 +115,34 @@ void onEvent (ev_t ev) { switch(ev) { case EV_SCAN_TIMEOUT: ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "SCAN TIMEOUT"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "SCAN TIMEOUT"); break; case EV_BEACON_FOUND: ESP_LOGI(TAG, "EV_BEACON_FOUND"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON FOUND"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON FOUND"); break; case EV_BEACON_MISSED: ESP_LOGI(TAG, "EV_BEACON_MISSED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON MISSED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON MISSED"); break; case EV_BEACON_TRACKED: ESP_LOGI(TAG, "EV_BEACON_TRACKED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON TRACKED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON TRACKED"); break; case EV_JOINING: ESP_LOGI(TAG, "EV_JOINING"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINING"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOINING"); break; case EV_JOINED: ESP_LOGI(TAG, "EV_JOINED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINED"); - #endif + u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOINED"); // Disable link check validation (automatically enabled // during join, but not supported by TTN at this time). LMIC_setLinkCheckMode(0); @@ -172,50 +156,38 @@ void onEvent (ev_t ev) { break; case EV_RFU1: ESP_LOGI(TAG, "EV_RFU1"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RFUI"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RFUI"); break; case EV_JOIN_FAILED: ESP_LOGI(TAG, "EV_JOIN_FAILED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOIN FAILED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOIN FAILED"); break; case EV_REJOIN_FAILED: ESP_LOGI(TAG, "EV_REJOIN_FAILED"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "REJOIN FAILED"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "REJOIN FAILED"); break; case EV_TXCOMPLETE: ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "TX COMPLETE"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "TX COMPLETE"); if (LMIC.txrxFlags & TXRX_ACK) { ESP_LOGI(TAG, "Received ack"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RECEIVED ACK"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RECEIVED ACK"); } if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); - #ifdef HAS_DISPLAY - u8x8.clearLine(6); - u8x8.setCursor(0, 6); - u8x8.printf("Rcvd %i bytes", LMIC.dataLen); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - // LMIC.snr = SNR twos compliment [dB] * 4 - // LMIC.rssi = RSSI [dBm] (-196...+63) - u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); - #endif + u8x8.clearLine(6); + u8x8.setCursor(0, 6); + u8x8.printf("Rcvd %i bytes", LMIC.dataLen); + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + // LMIC.snr = SNR twos compliment [dB] * 4 + // LMIC.rssi = RSSI [dBm] (-196...+63) + u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); // check if payload received on command port, then call remote command interpreter if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) { // caution: buffering LMIC values here because rcommand() can modify LMIC.frame @@ -230,47 +202,35 @@ void onEvent (ev_t ev) { break; case EV_LOST_TSYNC: ESP_LOGI(TAG, "EV_LOST_TSYNC"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LOST TSYNC"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LOST TSYNC"); break; case EV_RESET: ESP_LOGI(TAG, "EV_RESET"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RESET"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RESET"); break; case EV_RXCOMPLETE: // data received in ping slot ESP_LOGI(TAG, "EV_RXCOMPLETE"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RX COMPLETE"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RX COMPLETE"); break; case EV_LINK_DEAD: ESP_LOGI(TAG, "EV_LINK_DEAD"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK DEAD"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK DEAD"); break; case EV_LINK_ALIVE: ESP_LOGI(TAG, "EV_LINK_ALIVE"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK ALIVE"); - #endif + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK ALIVE"); break; default: ESP_LOGI(TAG, "Unknown event"); - #ifdef HAS_DISPLAY - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - u8x8.printf("UNKNOWN EVENT %d", ev); - #endif + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + u8x8.printf("UNKNOWN EVENT %d", ev); break; } } diff --git a/src/macsniff.cpp b/src/macsniff.cpp index e0907317..fe5b80a4 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -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 snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value - #ifdef HAS_DISPLAY - u8x8.draw2x2String(0, 0, counter); - #endif + u8x8.draw2x2String(0, 0, counter); ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> #%05i", typebuff, rssi, hashedmac, macs.size()); } else { // already seen WIFI or BLE MAC 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 currentScanDevice++; mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); - #ifdef HAS_DISPLAY - u8x8.setCursor(12,3); - u8x8.printf("%d", currentScanDevice); - #endif + u8x8.setCursor(12,3); + u8x8.printf("%d", currentScanDevice); rgb_set_color(COLOR_NONE); } @@ -101,21 +97,17 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void BLECount() { int blenum = 0; // Total device seen on this scan session currentScanDevice = 0; // Set 0 seen device on this scan session - #ifdef HAS_DISPLAY - u8x8.clearLine(3); - u8x8.drawString(0,3,"BLE Scan..."); - #endif + u8x8.clearLine(3); + u8x8.drawString(0,3,"BLE Scan..."); BLEDevice::init(PROGNAME); BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime); blenum=foundDevices.getCount(); - #ifdef HAS_DISPLAY - u8x8.clearLine(3); - u8x8.setCursor(0,3); - u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); - #endif + u8x8.clearLine(3); + u8x8.setCursor(0,3); + u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); } #endif diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 505c41cc..09d813fc 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -59,11 +59,9 @@ void set_reset(int val) { switch (val) { case 0: // restart device ESP_LOGI(TAG, "Remote command: restart device"); - #ifdef HAS_DISPLAY - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset pending "); - #endif + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset pending "); vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server esp_restart(); break; @@ -73,20 +71,16 @@ void set_reset(int val) { wifis.clear(); // clear Wifi macs container bles.clear(); // clear BLE macs container salt = random(65536); // get new 16bit random for salting hashes - #ifdef HAS_DISPLAY - u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset counter "); - #endif + u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset counter "); break; case 2: // reset device to factory settings ESP_LOGI(TAG, "Remote command: reset device to factory settings"); - #ifdef HAS_DISPLAY - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Factory reset "); - #endif + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Factory reset "); eraseConfig(); break; } @@ -95,11 +89,9 @@ void set_reset(int val) { void set_rssi(int val) { cfg.rssilimit = val * -1; ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit); - #ifdef HAS_DISPLAY - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); - #endif + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); }; void set_wifiscancycle(int val) { @@ -145,9 +137,7 @@ void set_screensaver(int val) { case 1: cfg.screensaver = val; break; default: cfg.screensaver = 0; break; } - #ifdef HAS_DISPLAY - u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off - #endif + u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off }; void set_display(int val) { @@ -156,9 +146,7 @@ void set_display(int val) { case 1: cfg.screenon = val; break; default: cfg.screenon = 0; break; } - #ifdef HAS_DISPLAY - u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off - #endif + u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off }; void set_lorasf(int val) { @@ -182,9 +170,7 @@ void set_blescan(int val) { default: cfg.blescan = 0; btStop(); - #ifdef HAS_DISPLAY - u8x8.clearLine(3); // clear BLE results from display - #endif + u8x8.clearLine(3); // clear BLE results from display break; } };