diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 0f540bde..87de6650 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -19,20 +19,20 @@ esp_err_t err; // populate cfg vars with factory settings void defaultConfig() { - cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora spreadfactor defined in main.h - cfg.txpower = 15; // 2-15, lora tx power - cfg.adrmode = 1; // 0=disabled, 1=enabled - cfg.screensaver = 0; // 0=disabled, 1=enabled - cfg.screenon = 1; // 0=disbaled, 1=enabled - cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed - cfg.rssilimit = 0; // threshold for rssilimiter, negative value! - cfg.wifiscancycle = SEND_SECS; // wifi scan cycle [seconds/2] + cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora spreadfactor defined in main.h + cfg.txpower = 15; // 2-15, lora tx power + cfg.adrmode = 1; // 0=disabled, 1=enabled + cfg.screensaver = 0; // 0=disabled, 1=enabled + cfg.screenon = 1; // 0=disbaled, 1=enabled + cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed + cfg.rssilimit = 0; // threshold for rssilimiter, negative value! + cfg.wifiscancycle = SEND_SECS; // wifi scan cycle [seconds/2] cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] - cfg.blescantime = BLESCANTIME; // BLE scan cycle duration [seconds] - cfg.blescancycle = BLESCANCYCLE; // do a BLE scan after [BLESCANCYCLE] full Wifi scan cycles - cfg.blescan = 1; // 0=disabled, 1=enabled - cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) - cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) + cfg.blescantime = BLESCANTIME; // BLE scan cycle duration [seconds] + cfg.blescancycle = BLESCANCYCLE; // do a BLE scan after [BLESCANCYCLE] full Wifi scan cycles + cfg.blescan = 1; // 0=disabled, 1=enabled + cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) + cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) strncpy( cfg.version, PROGVERSION, sizeof(cfg.version)-1 ); } diff --git a/src/globals.h b/src/globals.h index 3902ae9d..1ef61705 100644 --- a/src/globals.h +++ b/src/globals.h @@ -34,7 +34,7 @@ typedef struct { int8_t blescancycle; // BLE scan frequency, once after [blescancycle] full wifi scans int8_t blescan; // 0=disabled, 1=enabled int8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4) - int8_t rgblum; // RGB Led luminosity (0 100%) + int8_t rgblum; // RGB Led luminosity (0..100%) char version[10]; // Firmware version } configData_t; diff --git a/src/main.cpp b/src/main.cpp index 997d7c66..8e7d9fad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,12 +136,12 @@ static void lora_init (osjob_t* j) { LMIC_startJoining(); } -// LMIC Task +// LMIC FreeRTos Task void lorawan_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check - static bool led_state ; - bool new_led_state ; + static bool led_state; + bool new_led_state; while(1) { uint16_t color; @@ -152,24 +152,25 @@ void lorawan_loop(void * pvParameters) { // is prior to send because joining state send data if ( LMIC.opmode & (OP_JOINING | OP_REJOIN) ) { color = COLOR_YELLOW; - // Joining Quick blink 20ms on each 1/5 second + // quick blink 20ms on each 1/5 second new_led_state = ((millis() % 200) < 20) ? HIGH : LOW; - // Small blink 10ms on each 1/2sec (not when joining) + // TX data pending } else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) { color = COLOR_BLUE; + // small blink 10ms on each 1/2sec (not when joining) new_led_state = ((millis() % 500) < 20) ? HIGH : LOW; - // This should not happen so indicate a pb + // This should not happen so indicate a problem } else if ( LMIC.opmode & (OP_TXDATA | OP_TXRXPEND | OP_JOINING | OP_REJOIN) == 0 ) { color = COLOR_RED; - // Heartbeat long blink 200ms on each 2 seconds + // heartbeat long blink 200ms on each 2 seconds new_led_state = ((millis() % 2000) < 200) ? HIGH : LOW; } else { - rgb_set_color(COLOR_NONE); + // led off + rgb_set_color(COLOR_NONE); } - // led need to change state ? - // avoid digitalWrite() for nothing + // led need to change state? avoid digitalWrite() for nothing if (led_state != new_led_state) { if (new_led_state == HIGH) { set_onboard_led(1); @@ -302,18 +303,17 @@ void wifi_sniffer_loop(void * pvParameters) { u8x8.clearLine(6); if (cfg.screenon && cfg.screensaver) { - vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results + vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results } yield(); u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled } // end of send data cycle else { - #ifdef BLECOUNTER // execute BLE count if BLE function is enabled - if (nloop % (WIFI_CHANNEL_MAX * cfg.blescancycle) == 0 ) { // once after cfg.blescancycle Wifi scans, do a BLE scan - if (cfg.blescan) // execute BLE count if BLE function is enabled - BLECount(); - } - #endif + #ifdef BLECOUNTER + if (nloop % (WIFI_CHANNEL_MAX * cfg.blescancycle) == 0 ) // once after cfg.blescancycle Wifi scans, do a BLE scan + if (cfg.blescan) // execute BLE count if BLE function is enabled + BLECount(); + #endif } // end of channel rotation loop } // end of infinite wifi scan loop } diff --git a/src/main.h b/src/main.h index 57a190b6..206f60e6 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,5 @@ -// program version -#define PROGVERSION "1.2.85" // use max 10 chars here! +// program version - note: increment version after modifications to configData_t struct!! +#define PROGVERSION "1.2.86" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output diff --git a/src/rgb_led.cpp b/src/rgb_led.cpp index 274695e4..58a31062 100644 --- a/src/rgb_led.cpp +++ b/src/rgb_led.cpp @@ -7,9 +7,6 @@ // RGB Led instance SmartLed rgb_led(LED_WS2812, 1, HAS_RGB_LED); -// Luminosity from 0 to 100% -uint8_t rgb_luminosity = 50 ; - float rgb_CalcColor(float p, float q, float t) { if (t < 0.0f) @@ -70,7 +67,7 @@ void rgb_set_color(uint16_t hue) { // H (is color from 0..360) should be between 0.0 and 1.0 // S is saturation keep it to 1 // L is brightness should be between 0.0 and 0.5 - // rgb_luminosity is between 0 and 100 (percent) + // cfg.rgblum is between 0 and 100 (percent) RGBColor target = rgb_hsl2rgb( hue / 360.0f, 1.0f, 0.005f * cfg.rgblum); //uint32_t color = target.R<<16 | target.G<<8 | target.B; rgb_led[0] = Rgb(target.R, target.G, target.B);