Skip to content

Commit 63b16e9

Browse files
committed
Formatting
1 parent 258a388 commit 63b16e9

File tree

15 files changed

+378
-379
lines changed

15 files changed

+378
-379
lines changed

src/Animation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "Animation.h"
22

3-
43
Animation::Animation(String name)
54
{
65
m_name = name;

src/Animation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <Arduino.h>
44

5-
65
class Animation
76
{
87
public:

src/ColorUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "ColorUtils.h"
22

3-
43
CRGB hsv2rgb_smooth(uint16_t hue, uint8_t sat, uint8_t val)
54
{
65
uint8_t fractHue = hue / 6;

src/ColorUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#define HSV2RGB_SMOOTH_RANGE 1535
66

7-
87
/// Convert a hue, saturation and value to RGB by using a higher resolution
98
/// of 0 - 1535 which allows for very smooth hue transitions without
109
/// noticeable steps. The number 1535 is also defined by HSV2RGB_SMOOTH_RANGE.

src/Config.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <FS.h>
55

6-
76
bool ConfigClass::initialize()
87
{
98
if (!SPIFFS.begin())

src/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <ArduinoJson.h>
55
#include <LinkedList.h>
66

7-
87
class ConfigClass
98
{
109
public:

src/Fade.cpp

Lines changed: 113 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -8,141 +8,141 @@
88
#include <Ticker.h>
99
#include <time.h>
1010

11-
1211
namespace Fade
1312
{
1413

15-
FadeMode mode = FadeMode::NONE;
16-
uint16_t targetBrightness = 0;
17-
Ticker fadeTicker;
18-
Ticker debounce;
19-
20-
void initialize()
21-
{
22-
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
23-
getSunsetTime();
24-
}
14+
FadeMode mode = FadeMode::NONE;
15+
uint16_t targetBrightness = 0;
16+
Ticker fadeTicker;
17+
Ticker debounce;
2518

26-
void handle()
27-
{
28-
if (mode != FadeMode::NONE || debounce.active())
29-
return;
30-
31-
int8_t hour, minute;
32-
if (!getCurrentTime(&hour, &minute))
33-
return;
34-
35-
if (Config.alarmEnabled && hour == Config.alarmHour && minute == Config.alarmMinute)
36-
{
37-
Fade::begin(FadeMode::ALARM);
38-
}
39-
else if (Config.sunsetEnabled && hour == Config.sunsetHour && minute == Config.sunsetMinute && FastLEDHub.isDim())
19+
void initialize()
4020
{
41-
Fade::begin(FadeMode::SUNSET);
21+
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
22+
getSunsetTime();
4223
}
43-
}
44-
45-
void begin(FadeMode fadeMode)
46-
{
47-
mode = fadeMode;
48-
targetBrightness = FastLEDHub.brightness10;
49-
FastLEDHub.brightness10 = 0;
50-
FastLEDHub.show();
51-
52-
debounce.once(61, [&](){ debounce.detach(); });
5324

54-
if (fadeMode == FadeMode::ALARM)
25+
void handle()
5526
{
56-
FastLEDHub.begin(FastLEDHub.getAnimation(Config.alarmAnimation));
57-
fadeTicker.attach_ms(Config.alarmDuration * 60 * 1000 / 1024, tick);
58-
PRINTLN("[FastLEDHub] Start fade 'Alarm'");
27+
if (mode != FadeMode::NONE || debounce.active())
28+
return;
29+
30+
int8_t hour, minute;
31+
if (!getCurrentTime(&hour, &minute))
32+
return;
33+
34+
if (Config.alarmEnabled && hour == Config.alarmHour && minute == Config.alarmMinute)
35+
{
36+
Fade::begin(FadeMode::ALARM);
37+
}
38+
else if (Config.sunsetEnabled && hour == Config.sunsetHour && minute == Config.sunsetMinute && FastLEDHub.isDim())
39+
{
40+
Fade::begin(FadeMode::SUNSET);
41+
}
5942
}
60-
else if (fadeMode == FadeMode::SUNSET)
61-
{
62-
FastLEDHub.begin(FastLEDHub.getAnimation(Config.sunsetAnimation));
63-
fadeTicker.attach_ms(Config.sunsetDuration * 60 * 1000 / targetBrightness, tick);
64-
PRINTLN("[FastLEDHub] Start fade 'Sunset'");
65-
}
66-
}
6743

68-
void stop()
69-
{
70-
fadeTicker.detach();
71-
mode = FadeMode::NONE;
72-
}
73-
74-
void tick()
75-
{
76-
if (FastLEDHub.status == PAUSED)
77-
return;
78-
79-
if (mode == FadeMode::ALARM && FastLEDHub.brightness10 == 1023)
44+
void begin(FadeMode fadeMode)
8045
{
81-
if (Config.postAlarmAnimation != Config.alarmAnimation)
82-
FastLEDHub.begin(FastLEDHub.getAnimation(Config.postAlarmAnimation));
83-
84-
stop();
85-
PRINTLN("[FastLEDHub] End fade 'Alarm'");
46+
mode = fadeMode;
47+
targetBrightness = FastLEDHub.brightness10;
48+
FastLEDHub.brightness10 = 0;
49+
FastLEDHub.show();
50+
51+
debounce.once(61, [&]()
52+
{ debounce.detach(); });
53+
54+
if (fadeMode == FadeMode::ALARM)
55+
{
56+
FastLEDHub.begin(FastLEDHub.getAnimation(Config.alarmAnimation));
57+
fadeTicker.attach_ms(Config.alarmDuration * 60 * 1000 / 1024, tick);
58+
PRINTLN("[FastLEDHub] Start fade 'Alarm'");
59+
}
60+
else if (fadeMode == FadeMode::SUNSET)
61+
{
62+
FastLEDHub.begin(FastLEDHub.getAnimation(Config.sunsetAnimation));
63+
fadeTicker.attach_ms(Config.sunsetDuration * 60 * 1000 / targetBrightness, tick);
64+
PRINTLN("[FastLEDHub] Start fade 'Sunset'");
65+
}
8666
}
87-
else if (mode == FadeMode::SUNSET && FastLEDHub.brightness10 == targetBrightness)
88-
{
89-
stop();
90-
PRINTLN("[FastLEDHub] End fade 'Sunset'");
91-
}
92-
else
67+
68+
void stop()
9369
{
94-
FastLEDHub.brightness10++;
95-
PRINTLN("[FastLEDHub] Fade brightness: " + String(FastLEDHub.brightness10));
70+
fadeTicker.detach();
71+
mode = FadeMode::NONE;
9672
}
9773

98-
FastLEDHub.brightness10 = FastLEDHub.brightness10;
99-
}
100-
101-
void getSunsetTime()
102-
{
103-
PRINT("[FastLEDHub] Getting sunset time...");
104-
105-
WiFiClient client;
106-
HTTPClient http;
107-
String url = "http://api.sunrise-sunset.org/json?lat=" + String(Config.latitude) + "&lng=" + String(Config.longitude) + "&date=today&formatted=0";
108-
http.begin(client, url);
109-
String payload = "";
110-
if (http.GET() > 0)
111-
payload = http.getString();
112-
http.end();
113-
114-
DynamicJsonDocument doc(2048);
115-
deserializeJson(doc, payload);
116-
if(doc.containsKey("results") && doc["results"].containsKey("sunset"))
74+
void tick()
11775
{
118-
String sunset = doc["results"]["sunset"].as<String>();
119-
int16_t sunsetHour = (sunset.substring(11, 13).toInt() + Config.timeZone + Config.summerTime + 24) % 24;
120-
int16_t sunsetMinute = sunset.substring(14, 16).toInt();
121-
int16_t minutesSinceMidnight = sunsetHour * 60 + sunsetMinute;
122-
minutesSinceMidnight = (minutesSinceMidnight + Config.sunsetOffset + 1440) % 1440;
123-
Config.sunsetHour = minutesSinceMidnight / 60;
124-
Config.sunsetMinute = minutesSinceMidnight % 60;
125-
Config.save();
126-
PRINTLN(" " + String(Config.sunsetHour) + ":" + String(Config.sunsetMinute));
76+
if (FastLEDHub.status == PAUSED)
77+
return;
78+
79+
if (mode == FadeMode::ALARM && FastLEDHub.brightness10 == 1023)
80+
{
81+
if (Config.postAlarmAnimation != Config.alarmAnimation)
82+
FastLEDHub.begin(FastLEDHub.getAnimation(Config.postAlarmAnimation));
83+
84+
stop();
85+
PRINTLN("[FastLEDHub] End fade 'Alarm'");
86+
}
87+
else if (mode == FadeMode::SUNSET && FastLEDHub.brightness10 == targetBrightness)
88+
{
89+
stop();
90+
PRINTLN("[FastLEDHub] End fade 'Sunset'");
91+
}
92+
else
93+
{
94+
FastLEDHub.brightness10++;
95+
PRINTLN("[FastLEDHub] Fade brightness: " + String(FastLEDHub.brightness10));
96+
}
97+
98+
FastLEDHub.brightness10 = FastLEDHub.brightness10;
12799
}
128-
else
100+
101+
void getSunsetTime()
129102
{
130-
PRINTLN("failed. Using last known time instead.");
103+
PRINT("[FastLEDHub] Getting sunset time...");
104+
105+
WiFiClient client;
106+
HTTPClient http;
107+
String url = "http://api.sunrise-sunset.org/json?lat=" + String(Config.latitude) + "&lng=" + String(Config.longitude) + "&date=today&formatted=0";
108+
http.begin(client, url);
109+
String payload = "";
110+
if (http.GET() > 0)
111+
payload = http.getString();
112+
http.end();
113+
114+
DynamicJsonDocument doc(2048);
115+
deserializeJson(doc, payload);
116+
if (doc.containsKey("results") && doc["results"].containsKey("sunset"))
117+
{
118+
String sunset = doc["results"]["sunset"].as<String>();
119+
int16_t sunsetHour = (sunset.substring(11, 13).toInt() + Config.timeZone + Config.summerTime + 24) % 24;
120+
int16_t sunsetMinute = sunset.substring(14, 16).toInt();
121+
int16_t minutesSinceMidnight = sunsetHour * 60 + sunsetMinute;
122+
minutesSinceMidnight = (minutesSinceMidnight + Config.sunsetOffset + 1440) % 1440;
123+
Config.sunsetHour = minutesSinceMidnight / 60;
124+
Config.sunsetMinute = minutesSinceMidnight % 60;
125+
Config.save();
126+
PRINTLN(" " + String(Config.sunsetHour) + ":" + String(Config.sunsetMinute));
127+
}
128+
else
129+
{
130+
PRINTLN("failed. Using last known time instead.");
131+
}
131132
}
132-
}
133133

134-
bool getCurrentTime(int8_t *hour, int8_t *minute)
135-
{
136-
time_t n = time(nullptr);
134+
bool getCurrentTime(int8_t *hour, int8_t *minute)
135+
{
136+
time_t n = time(nullptr);
137137

138-
if (!n)
139-
return false;
138+
if (!n)
139+
return false;
140140

141-
tm *now = gmtime(&n);
142-
*hour = (now->tm_hour + Config.timeZone + Config.summerTime) % 24;
143-
*minute = now->tm_min;
141+
tm *now = gmtime(&n);
142+
*hour = (now->tm_hour + Config.timeZone + Config.summerTime) % 24;
143+
*minute = now->tm_min;
144144

145-
return true;
146-
}
145+
return true;
146+
}
147147

148148
} // namespace Fade

src/Fade.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44

55
#include <Arduino.h>
66

7-
87
class FastLEDHubClass;
98

109
namespace Fade
1110
{
1211

13-
enum class FadeMode
14-
{
15-
NONE,
16-
ALARM,
17-
SUNSET
18-
};
19-
20-
extern FadeMode mode;
21-
22-
void tick();
23-
void handle();
24-
void begin(FadeMode fadeMode);
25-
void stop();
26-
void initialize();
27-
void getSunsetTime();
28-
bool getCurrentTime(int8_t *hour, int8_t *minute);
12+
enum class FadeMode
13+
{
14+
NONE,
15+
ALARM,
16+
SUNSET
17+
};
18+
19+
extern FadeMode mode;
20+
21+
void tick();
22+
void handle();
23+
void begin(FadeMode fadeMode);
24+
void stop();
25+
void initialize();
26+
void getSunsetTime();
27+
bool getCurrentTime(int8_t *hour, int8_t *minute);
2928

3029
} // namespace Fade

0 commit comments

Comments
 (0)