Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added weather mode #21

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Binary file not shown.

Large diffs are not rendered by default.

917 changes: 917 additions & 0 deletions firmware/GyverLamp_v1.5_MQTT-orig/aquarium2.ino

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions firmware/GyverLamp_v1.5_MQTT-orig/button.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
boolean brightDirection;

void buttonTick() {

if (!_BTN_CONNECTED) return;

// Необходимое время для калибровки сенсорной кнопки при плотном прилегании к стеклу
//if (millis() < 10000) return;

touch.tick();
if (touch.isSingle()) {
demo = false;
if (dawnFlag) {
manualOff = true;
dawnFlag = false;
loadingFlag = true;
FastLED.setBrightness(modes[currentMode].brightness);
changePower();
MQTTUpdateState();
} else {
if (ONflag) {
ONflag = false;
changePower();
MQTTUpdateState();
} else {
ONflag = true;
changePower();
MQTTUpdateState();
}
sendSettings_flag = true;
MQTTUpdateState();
}
}

if (ONflag && touch.isDouble()) {
demo = false;
if (++currentMode >= MODE_AMOUNT) currentMode = 0;
FastLED.setBrightness(modes[currentMode].brightness);
loadingFlag = true;
settChanged = true;
eepromTimer = millis();
FastLED.clear();
delay(1);
sendSettings_flag = true;
MQTTUpdateState();
}

if (ONflag && touch.isTriple()) {
demo = false;
if (--currentMode < 0) currentMode = MODE_AMOUNT - 1;
FastLED.setBrightness(modes[currentMode].brightness);
loadingFlag = true;
settChanged = true;
eepromTimer = millis();
FastLED.clear();
delay(1);
MQTTUpdateState();
sendSettings_flag = true;
}

// вывод IP на лампу
if (ONflag && touch.hasClicks()) {
if (touch.getClicks() == 5) {
resetString();
while (!fillString(WiFi.localIP().toString(), CRGB::Green, true)) {
delay(1);
yield();
}
}
}

if (ONflag && touch.isHolded()) {
brightDirection = !brightDirection;
}

if (ONflag && touch.isStep()) {
if (brightDirection) {
if (modes[currentMode].brightness < 10) modes[currentMode].brightness += 1;
else if (modes[currentMode].brightness < 250) modes[currentMode].brightness += 5;
else modes[currentMode].brightness = 255;
} else {
if (modes[currentMode].brightness > 15) modes[currentMode].brightness -= 5;
else if (modes[currentMode].brightness > 1) modes[currentMode].brightness -= 1;
else modes[currentMode].brightness = 1;
}
FastLED.setBrightness(modes[currentMode].brightness);
settChanged = true;
eepromTimer = millis();
sendSettings_flag = true;
MQTTUpdateState();
}
}
38 changes: 38 additions & 0 deletions firmware/GyverLamp_v1.5_MQTT-orig/eeprom.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
void saveEEPROM() {
EEPROM.put(3 * currentMode + 40, modes[currentMode]);
if (EEPROM.read(200) != currentMode) EEPROM.write(200, currentMode);
EEPROM.commit();
}

void eepromTick() {
if (settChanged && millis() - eepromTimer > 30000) {
settChanged = false;
eepromTimer = millis();
saveEEPROM();
EEPROM.commit();
}
}

void saveAlarm(byte almNumber) {
EEPROM.write(5 * almNumber, alarm[almNumber].state); // рассвет
eeWriteInt(5 * almNumber + 1, alarm[almNumber].time);
EEPROM.commit();
}

void saveDawnMmode() {
EEPROM.write(199, dawnMode); // рассвет
EEPROM.commit();
}

void eeprom_write_string(String string){
int string_length =string.length();
char temp_char[string_length + 1];
string.toCharArray(temp_char, string_length + 1);
EEPROM.write(addr, string_length);
for (int i = 0 ; i < string_length ; i++){
addr++;
EEPROM.write(addr, temp_char[i]);
}
addr++;
EEPROM.commit();
}
108 changes: 108 additions & 0 deletions firmware/GyverLamp_v1.5_MQTT-orig/effectTicker.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
uint32_t effTimer;

void effectsTick() {
if (!dawnFlag) {
if (!stop_eff && millis() - effTimer >= ((currentMode < 5 || currentMode > 13) ? modes[currentMode].speed : 50) ) {
effTimer = millis();
switch (currentMode) {
case 0: sparklesRoutine();
break;
case 1: fireRoutine();
break;
case 2: rainbowVertical();
break;
case 3: rainbowHorizontal();
break;
case 4: colorsRoutine();
break;
case 5: madnessNoise();
break;
case 6: cloudNoise();
break;
case 7: lavaNoise();
break;
case 8: plasmaNoise();
break;
case 9: rainbowNoise();
break;
case 10: rainbowStripeNoise();
break;
case 11: zebraNoise();
break;
case 12: forestNoise();
break;
case 13: oceanNoise();
break;
case 14: colorRoutine();
break;
case 15: snowRoutine();
break;
case 16: matrixRoutine();
break;
case 17: lightersRoutine();
break;
case 18: aquaRoutine();
break;
case 19: starfallRoutine();
break;
case 20: lightBallsRoutine();
break;
case 21: spiroRoutine();
break;
case 22: warmLightRoutine();
break;
case 23: prismataRoutine();
break;
case 24: twinklesRoutine();
break;
case 25: policeStroboRoutine();
break;
case 26: PatternIncrementalDrift2();
break;
case 27: prideRoutine();
break;
case 28: weatherRoutine();
break;
}
FastLED.show();
}
}
}

void changePower() {
if (ONflag && !stop_eff) return;

if (ONflag) {
// Включение
stop_eff = false;
int steps = 1 + round(modes[currentMode].brightness / 80);
for (int i = 0; i <= modes[currentMode].brightness; i += steps) {
FastLED.setBrightness(i);
effectsTick();
delay(2);
FastLED.show();
}
FastLED.setBrightness(modes[currentMode].brightness);
delay(2);
FastLED.show();

} else {
// Выключение
int steps = 1 + round(modes[currentMode].brightness / 40);
for (int i = modes[currentMode].brightness; i >= 0; i -= steps) {
FastLED.setBrightness(i);
effectsTick();
delay(2);
FastLED.show();
}

stop_eff = true;
FastLED.clear();
delay(2);
FastLED.show();
}

// записываем статус лампы в память
EEPROM.write(420, ONflag); EEPROM.commit();

}
Loading