From e37e39007c6a806eb18ab43f3c8112b87a6131fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C4=8Cern=C3=BD?= Date: Tue, 11 May 2021 01:05:37 +0200 Subject: [PATCH] Connecting animation glitch fixed --- Firmware/FLORA_FIRMWARE/FLORA_FIRMWARE.ino | 24 ++++++++------- Firmware/FLORA_FIRMWARE/VFD_fns.ino | 36 +++++++++++++++------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Firmware/FLORA_FIRMWARE/FLORA_FIRMWARE.ino b/Firmware/FLORA_FIRMWARE/FLORA_FIRMWARE.ino index 78ddf3a..62690da 100644 --- a/Firmware/FLORA_FIRMWARE/FLORA_FIRMWARE.ino +++ b/Firmware/FLORA_FIRMWARE/FLORA_FIRMWARE.ino @@ -26,7 +26,7 @@ // Pick a clock version below! //#define CLOCK_VERSION_IV6 //#define CLOCK_VERSION_IV12 -//#define CLOCK_VERSION_IV22 +#define CLOCK_VERSION_IV22 #if !defined(CLOCK_VERSION_IV6) && !defined(CLOCK_VERSION_IV12) && !defined(CLOCK_VERSION_IV22) #error "You have to pick a clock version! Line 25" @@ -34,7 +34,7 @@ #define AP_NAME "FLORA_" #define FW_NAME "FLORA" -#define FW_VERSION "4.1" +#define FW_VERSION "4.2" #define CONFIG_TIMEOUT 300000 // 300000 = 5 minutes // ONLY CHANGE DEFINES BELOW IF YOU KNOW WHAT YOU'RE DOING! @@ -57,6 +57,7 @@ const char* update_username = "flora"; const char* update_password = "flora"; const char* ntpServerName = "pool.ntp.org"; +const int dotsAnimationSteps = 3000; // dotsAnimationSteps * TIMER_INTERVAL_uS = one animation cycle time in microseconds const uint8_t PixelCount = 12; // Addressable LED count RgbColor colorConfigMode = RgbColor(130, 0, 130); RgbColor colorConfigSave = RgbColor(0, 0, 130); @@ -88,11 +89,11 @@ RgbColor colonColorDefault[] = { RgbColor(120, 220, 140), // HIGH }; /* -RgbColor colonColorDefault[] = { + RgbColor colonColorDefault[] = { RgbColor(30, 70, 50), // LOW RgbColor(50, 100, 80), // MEDIUM RgbColor(100, 200, 120), // HIGH -}; + }; */ #endif @@ -196,6 +197,8 @@ volatile uint8_t bri = 0; volatile uint8_t crossFadeTime = 0; uint8_t timeUpdateStatus = 0; // 0 = no update, 1 = update success, 2 = update fail, uint8_t failedAttempts = 0; +volatile bool enableDotsAnimation; +volatile unsigned short dotsAnimationState; RgbColor colonColor; IPAddress ip_addr; @@ -206,12 +209,10 @@ NeoPixelBus strip(PixelCount); NeoGamma colorGamma; NeoPixelAnimator animations(PixelCount); DynamicJsonDocument json(2048); // config buffer -//Ticker pwm_ticker; Ticker fade_animation_ticker; Ticker onceTicker; Ticker colonTicker; ESP8266Timer ITimer; -ESP8266Timer ITimer2; DNSServer dnsServer; ESP8266WebServer server(80); WiFiUDP Udp; @@ -241,7 +242,7 @@ void setup() { const char* gw = json["gw"].as(); const char* sn = json["sn"].as(); - if (ssid != NULL && pass != NULL && ssid[0] != '\0' && pass[0] != '\0') { + if (ssid != NULL && pass != NULL && ssid[0] != '\0' && pass[0] != '\0') { Serial.println("[WIFI] Connecting to: " + String(ssid)); WiFi.mode(WIFI_STA); @@ -253,8 +254,10 @@ void setup() { WiFi.config(ip_address, gateway_ip, subnet_mask); } } - // serializeJson(json, Serial); + + enableDotsAnimation = true; // Start the dots animation + updateColonColor(colorWifiConnecting); strip_show(); @@ -276,6 +279,7 @@ void setup() { delay(100); } else { updateColonColor(colorWifiSuccess); + enableDotsAnimation = false; strip_show(); Serial.print("[WIFI] Successfully connected to: "); Serial.println(WiFi.SSID()); @@ -300,9 +304,7 @@ void setup() { } colonColor = colonColorDefault[bri]; - initScreen(); - - //initColon(); + //initScreen(); if (json["rst_cycle"].as() == 1) { cycleDigits(); diff --git a/Firmware/FLORA_FIRMWARE/VFD_fns.ino b/Firmware/FLORA_FIRMWARE/VFD_fns.ino index 1bd5dd6..b500043 100644 --- a/Firmware/FLORA_FIRMWARE/VFD_fns.ino +++ b/Firmware/FLORA_FIRMWARE/VFD_fns.ino @@ -22,15 +22,27 @@ void ICACHE_RAM_ATTR shiftWriteBytes(volatile byte *data) { // set gpio through register manipulation, fast! GPOS = 1 << LATCH; GPOC = 1 << LATCH; - /* - digitalWrite(LATCH, HIGH); - digitalWrite(LATCH, LOW); - */ - } void ICACHE_RAM_ATTR TimerHandler() { +#if !defined(CLOCK_VERSION_IV12) + // Only one ISR timer is available so if we want the dots to not glitch during wifi connection, we need to put it here... + // speed of the dots depends on refresh frequency of the display + if (enableDotsAnimation) { + int stepCount = dotsAnimationSteps / registersCount; + + for (int i = 0; i < registersCount; i++) { + if (dotsAnimationState >= stepCount * i && dotsAnimationState < stepCount * (i + 1)) { + segmentBrightness[i][7] = bri_vals_separate[bri][i]; + } else { + segmentBrightness[i][7] = 0; + } + } + dotsAnimationState++; + if (dotsAnimationState >= dotsAnimationSteps) dotsAnimationState = 0; + } +#endif // Normal PWM for (int i = 0; i < registersCount; i++) { @@ -47,13 +59,15 @@ void ICACHE_RAM_ATTR TimerHandler() for (int i = 0; i < registersCount; i++) { shiftedDutyState[i]++; - if (shiftedDutyState[i] >= pwmResolution) shiftedDutyState[i] = 0; + if (shiftedDutyState[i] >= pwmResolution) { + shiftedDutyState[i] = 0; + } } + //if (dutyState > pwmResolution) dutyState = 0; //else dutyState++; } - void initScreen() { pinMode(DATA, INPUT); pinMode(CLOCK, OUTPUT); @@ -253,10 +267,10 @@ void showIP(int delay_ms) { void setupPhaseShift() { disableScreen(); uint8_t shiftSteps = floor(pwmResolution / registersCount); - if(shiftSteps) - for (int i = 0; i < registersCount; i++) { - shiftedDutyState[i] = i * shiftSteps; - } + if (shiftSteps) + for (int i = 0; i < registersCount; i++) { + shiftedDutyState[i] = i * shiftSteps; + } enableScreen(); }