Skip to content

Commit

Permalink
Connecting animation glitch fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mcer12 committed May 10, 2021
1 parent 082bec5 commit e37e390
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
24 changes: 13 additions & 11 deletions Firmware/FLORA_FIRMWARE/FLORA_FIRMWARE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
// 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"
#endif

#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!
Expand All @@ -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);
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;

Expand All @@ -206,12 +209,10 @@ NeoPixelBus<NeoGrbFeature, NeoWs2813Method> strip(PixelCount);
NeoGamma<NeoGammaTableMethod> 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;
Expand Down Expand Up @@ -241,7 +242,7 @@ void setup() {
const char* gw = json["gw"].as<const char*>();
const char* sn = json["sn"].as<const char*>();

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);

Expand All @@ -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();

Expand All @@ -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());
Expand All @@ -300,9 +304,7 @@ void setup() {
}

colonColor = colonColorDefault[bri];
initScreen();

//initColon();
//initScreen();

if (json["rst_cycle"].as<unsigned int>() == 1) {
cycleDigits();
Expand Down
36 changes: 25 additions & 11 deletions Firmware/FLORA_FIRMWARE/VFD_fns.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit e37e390

Please sign in to comment.