diff --git a/src/configmanager.cpp b/src/configmanager.cpp index ba39b8af..3978f55b 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -289,7 +289,9 @@ void loadConfig() { ESP_LOGI(TAG, "Done"); // put actions to be triggered on loaded config here - u8x8.setPowerSave(!cfg.screenon); // set display on/off + #ifdef HAS_DISPLAY + u8x8.setPowerSave(!cfg.screenon); // set display on/off + #endif #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 1ef61705..9a65a3b8 100644 --- a/src/globals.h +++ b/src/globals.h @@ -49,8 +49,6 @@ 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 0f0f86eb..65812d40 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -99,14 +99,18 @@ 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"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LORA BUSY"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LORA BUSY"); + #endif } 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"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "PACKET QUEUED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "PACKET QUEUED"); + #endif } // Next TX is scheduled after TX_COMPLETE event. } @@ -115,34 +119,46 @@ void onEvent (ev_t ev) { switch(ev) { case EV_SCAN_TIMEOUT: ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "SCAN TIMEOUT"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "SCAN TIMEOUT"); + #endif break; case EV_BEACON_FOUND: ESP_LOGI(TAG, "EV_BEACON_FOUND"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON FOUND"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON FOUND"); + #endif break; case EV_BEACON_MISSED: ESP_LOGI(TAG, "EV_BEACON_MISSED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON MISSED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON MISSED"); + #endif break; case EV_BEACON_TRACKED: ESP_LOGI(TAG, "EV_BEACON_TRACKED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON TRACKED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "BEACON TRACKED"); + #endif break; case EV_JOINING: ESP_LOGI(TAG, "EV_JOINING"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINING"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOINING"); + #endif break; case EV_JOINED: ESP_LOGI(TAG, "EV_JOINED"); - u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp - u8x8.clearLine(7); - u8x8.drawString(0, 7, "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 // Disable link check validation (automatically enabled // during join, but not supported by TTN at this time). LMIC_setLinkCheckMode(0); @@ -156,38 +172,50 @@ void onEvent (ev_t ev) { break; case EV_RFU1: ESP_LOGI(TAG, "EV_RFU1"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RFUI"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RFUI"); + #endif break; case EV_JOIN_FAILED: ESP_LOGI(TAG, "EV_JOIN_FAILED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOIN FAILED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "JOIN FAILED"); + #endif break; case EV_REJOIN_FAILED: ESP_LOGI(TAG, "EV_REJOIN_FAILED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "REJOIN FAILED"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "REJOIN FAILED"); + #endif break; case EV_TXCOMPLETE: ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "TX COMPLETE"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "TX COMPLETE"); + #endif if (LMIC.txrxFlags & TXRX_ACK) { ESP_LOGI(TAG, "Received ack"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RECEIVED ACK"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RECEIVED ACK"); + #endif } if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); - 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); + #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 // 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 @@ -202,35 +230,47 @@ void onEvent (ev_t ev) { break; case EV_LOST_TSYNC: ESP_LOGI(TAG, "EV_LOST_TSYNC"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LOST TSYNC"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LOST TSYNC"); + #endif break; case EV_RESET: ESP_LOGI(TAG, "EV_RESET"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RESET"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RESET"); + #endif break; case EV_RXCOMPLETE: // data received in ping slot ESP_LOGI(TAG, "EV_RXCOMPLETE"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RX COMPLETE"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "RX COMPLETE"); + #endif break; case EV_LINK_DEAD: ESP_LOGI(TAG, "EV_LINK_DEAD"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK DEAD"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK DEAD"); + #endif break; case EV_LINK_ALIVE: ESP_LOGI(TAG, "EV_LINK_ALIVE"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK ALIVE"); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.drawString(0, 7, "LINK ALIVE"); + #endif break; default: ESP_LOGI(TAG, "Unknown event"); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - u8x8.printf("UNKNOWN EVENT %d", ev); + #ifdef HAS_DISPLAY + u8x8.clearLine(7); + u8x8.setCursor(0, 7); + u8x8.printf("UNKNOWN EVENT %d", ev); + #endif break; } } diff --git a/src/macsniff.cpp b/src/macsniff.cpp index fe5b80a4..e0907317 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -60,7 +60,9 @@ 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 - u8x8.draw2x2String(0, 0, counter); + #ifdef HAS_DISPLAY + u8x8.draw2x2String(0, 0, counter); + #endif 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); @@ -87,8 +89,10 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { // Current devices seen on this scan session currentScanDevice++; mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); - u8x8.setCursor(12,3); - u8x8.printf("%d", currentScanDevice); + #ifdef HAS_DISPLAY + u8x8.setCursor(12,3); + u8x8.printf("%d", currentScanDevice); + #endif rgb_set_color(COLOR_NONE); } @@ -97,17 +101,21 @@ 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 - u8x8.clearLine(3); - u8x8.drawString(0,3,"BLE Scan..."); + #ifdef HAS_DISPLAY + u8x8.clearLine(3); + u8x8.drawString(0,3,"BLE Scan..."); + #endif 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(); - u8x8.clearLine(3); - u8x8.setCursor(0,3); - u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); + #ifdef HAS_DISPLAY + u8x8.clearLine(3); + u8x8.setCursor(0,3); + u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum); + #endif } #endif diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 09d813fc..505c41cc 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -59,9 +59,11 @@ void set_reset(int val) { switch (val) { case 0: // restart device ESP_LOGI(TAG, "Remote command: restart device"); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset pending "); + #ifdef HAS_DISPLAY + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset pending "); + #endif vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server esp_restart(); break; @@ -71,16 +73,20 @@ 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 - u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset counter "); + #ifdef HAS_DISPLAY + u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Reset counter "); + #endif break; case 2: // reset device to factory settings ESP_LOGI(TAG, "Remote command: reset device to factory settings"); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Factory reset "); + #ifdef HAS_DISPLAY + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf("Factory reset "); + #endif eraseConfig(); break; } @@ -89,9 +95,11 @@ 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); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); + #ifdef HAS_DISPLAY + u8x8.clearLine(5); + u8x8.setCursor(0, 5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); + #endif }; void set_wifiscancycle(int val) { @@ -137,7 +145,9 @@ void set_screensaver(int val) { case 1: cfg.screensaver = val; break; default: cfg.screensaver = 0; break; } - u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off + #ifdef HAS_DISPLAY + u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off + #endif }; void set_display(int val) { @@ -146,7 +156,9 @@ void set_display(int val) { case 1: cfg.screenon = val; break; default: cfg.screenon = 0; break; } - u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off + #ifdef HAS_DISPLAY + u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off + #endif }; void set_lorasf(int val) { @@ -170,7 +182,9 @@ void set_blescan(int val) { default: cfg.blescan = 0; btStop(); - u8x8.clearLine(3); // clear BLE results from display + #ifdef HAS_DISPLAY + u8x8.clearLine(3); // clear BLE results from display + #endif break; } };