centralize display writes (part 1)

This commit is contained in:
Klaus K Wilting 2018-04-15 22:21:30 +02:00
parent b6b8ac8003
commit 130fefd49d
4 changed files with 44 additions and 26 deletions

View File

@ -10,9 +10,9 @@
; ---> SELECT TARGET PLATFORM HERE! <--- ; ---> SELECT TARGET PLATFORM HERE! <---
[platformio] [platformio]
env_default = heltec_wifi_lora_32 ;nv_default = heltec_wifi_lora_32
;env_default = ttgov1 ;env_default = ttgov1
;env_default = ttgov2 env_default = ttgov2
;env_default = lopy ;env_default = lopy
;env_default = lopy4 ;env_default = lopy4
;env_default = lolin32lite_lora ;env_default = lolin32lite_lora

View File

@ -50,22 +50,22 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
// Insert only if it was not found on global count // Insert only if it was not found on global count
if (added) { if (added) {
char buff[16]; //char buff[16];
snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value //snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE //u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE
if (sniff_type == MAC_SNIFF_WIFI ) { if (sniff_type == MAC_SNIFF_WIFI ) {
rgb_set_color(COLOR_GREEN); rgb_set_color(COLOR_GREEN);
wifis.insert(hashedmac); // add hashed MAC to wifi container wifis.insert(hashedmac); // add hashed MAC to wifi container
u8x8.setCursor(0,4); //u8x8.setCursor(0,4);
u8x8.printf("WIFI: %-4d", (int) wifis.size()); //u8x8.printf("WIFI: %-4d", (int) wifis.size());
} }
#ifdef BLECOUNTER #ifdef BLECOUNTER
else if (sniff_type == MAC_SNIFF_BLE ) { else if (sniff_type == MAC_SNIFF_BLE ) {
rgb_set_color(COLOR_MAGENTA); rgb_set_color(COLOR_MAGENTA);
bles.insert(hashedmac); // add hashed MAC to BLE container bles.insert(hashedmac); // add hashed MAC to BLE container
u8x8.setCursor(0,3); //u8x8.setCursor(0,3);
u8x8.printf("BLTH: %-4d", (int) bles.size()); //u8x8.printf("BLTH: %-4d", (int) bles.size());
} }
#endif #endif

View File

@ -45,6 +45,7 @@ configData_t cfg; // struct holds current device configuration
osjob_t sendjob, initjob; // LMIC osjob_t sendjob, initjob; // LMIC
// Initialize global variables // Initialize global variables
uint8_t channel = 0;
int macnum = 0; int macnum = 0;
uint64_t uptimecounter = 0; uint64_t uptimecounter = 0;
bool joinstate = false; bool joinstate = false;
@ -258,7 +259,7 @@ void bt_loop(void *ignore);
void sniffer_loop(void * pvParameters) { void sniffer_loop(void * pvParameters) {
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
uint8_t channel=0; channel=0;
char buff[16]; char buff[16];
int nloop=0, lorawait=0; int nloop=0, lorawait=0;
@ -271,7 +272,7 @@ void sniffer_loop(void * pvParameters) {
channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX
wifi_sniffer_set_channel(channel); wifi_sniffer_set_channel(channel);
ESP_LOGD(TAG, "Wifi set channel %d", channel); ESP_LOGD(TAG, "Wifi set channel %d", channel);
/*
snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
u8x8.draw2x2String(0, 0, buff); // display number on unique macs total u8x8.draw2x2String(0, 0, buff); // display number on unique macs total
@ -279,7 +280,7 @@ void sniffer_loop(void * pvParameters) {
u8x8.printf("ch:%02i", channel); u8x8.printf("ch:%02i", channel);
u8x8.setCursor(0,5); u8x8.setCursor(0,5);
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit);
*/
// duration of one wifi scan loop reached? then send data and begin new scan cycle // duration of one wifi scan loop reached? then send data and begin new scan cycle
if ( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { if ( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) {
u8x8.setPowerSave(!cfg.screenon); // set display on if enabled u8x8.setPowerSave(!cfg.screenon); // set display on if enabled
@ -499,11 +500,11 @@ salt_reset(); // get new 16bit for salting hashes
ESP_LOGI(TAG, "Starting Lora task on core 1"); ESP_LOGI(TAG, "Starting Lora task on core 1");
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1); xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
ESP_LOGI(TAG, "Starting Wifi task on core 0"); ESP_LOGI(TAG, "Starting Wifi task on core 0");
xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 16384, ( void * ) 1, 1, NULL, 0);
#ifdef BLECOUNTER #ifdef BLECOUNTER
if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration
ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); ESP_LOGI(TAG, "Starting Bluetooth task on core 0");
xTaskCreatePinnedToCore(bt_loop, "btscan", 8192, NULL, 5, NULL, 0); xTaskCreatePinnedToCore(bt_loop, "btscan", 16384, NULL, 5, NULL, 0);
} }
#endif #endif
@ -521,8 +522,6 @@ do_send(&sendjob);
// https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/
void loop() { void loop() {
while(1) {
#ifdef HAS_BUTTON #ifdef HAS_BUTTON
if (ButtonTriggered) { if (ButtonTriggered) {
ButtonTriggered = false; ButtonTriggered = false;
@ -532,9 +531,25 @@ void loop() {
} }
#endif #endif
vTaskDelay(500/portTICK_PERIOD_MS); #ifdef HAS_DISPLAY
// display counters(lines 0-4)
char buff[16];
snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE
u8x8.setCursor(0,4);
u8x8.printf("WIFI: %-4d", (int) wifis.size());
u8x8.setCursor(0,3);
u8x8.printf("BLTH: %-4d", (int) bles.size());
// display actual wifi channel (line 4)
u8x8.setCursor(11,4);
u8x8.printf("ch:%02i", channel);
// display RSSI status (line 5)
u8x8.setCursor(0,5);
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit);
#endif
vTaskDelay(DISPLAYREFRESH/portTICK_PERIOD_MS);
uptimecounter = uptime() / 1000; // count uptime seconds uptimecounter = uptime() / 1000; // count uptime seconds
}
} }

View File

@ -46,6 +46,9 @@
// Default RGB LED luminosity (in %) // Default RGB LED luminosity (in %)
#define RGBLUMINOSITY 30 // 30% #define RGBLUMINOSITY 30 // 30%
// OLED Display refresh cycle (in Milliseconds)
#define DISPLAYREFRESH 200 // 200ms
// LMIC settings // LMIC settings
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored // define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored
// define hardware specifics settings in platformio.ini as build_flag for hardware environment // define hardware specifics settings in platformio.ini as build_flag for hardware environment