Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinschumacher committed May 27, 2020
1 parent 1bc4b5d commit 6e37e7f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
4 changes: 0 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ lib_deps =
[email protected]
[email protected]
[email protected]
[email protected]
extra_scripts = pre:build_data.py

[env:esp12e]
Expand All @@ -45,7 +44,6 @@ lib_deps =
[email protected]
[email protected]
[email protected]
[email protected]
extra_scripts = pre:build_data.py

[env:lolin32-devel]
Expand All @@ -60,7 +58,6 @@ lib_deps =
[email protected]
[email protected]
[email protected]
[email protected]
extra_scripts = pre:build_data.py

[env:lolin32]
Expand All @@ -75,5 +72,4 @@ lib_deps =
[email protected]
[email protected]
[email protected]
[email protected]
extra_scripts = pre:build_data.py
7 changes: 6 additions & 1 deletion src/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ RgbColor Alarm(uint8_t WheelPos)
}
}

void alarmAnimation()
void alarmAnimation(bool isNight = false)
{

for (uint16_t i = 0; i < config.config.ledCount; i++)
{
animationPos++;
animationColor = Alarm(animationPos);

if (isNight)
{
animationColor = DimColor(90, animationColor);
}
uint8_t pixelPos = (i + second()) % 60;
strip->SetPixelColor(pixelPos, animationColor);
}
Expand Down
56 changes: 32 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,8 @@ uint8_t calculateHourHand()
return hourHand;
}

void showClockElements()
void renderHourDots()
{

webserver.currentTime = localTime.dateTime();
strip->ClearTo(off);

uint8_t hour12 = localTime.hour() % 12;
uint8_t segmentLength = floor((float)config.config.ledCount / 12);
uint8_t segmentStart = floor((float)config.config.ledCount / 12 * hour12);
segmentStart = (segmentStart + config.config.ledRoot) % config.config.ledCount;
for (size_t i = 0; i < segmentLength; i++)
{
strip->SetPixelColor(segmentStart + i, segment);
}

// calculate hour dots
float step = (float)config.config.ledCount / 12;
for (size_t i = 0; i < 12; i++)
{
Expand All @@ -87,12 +73,23 @@ void showClockElements()
strip->SetPixelColor(dotPos, dot);
}
}
}

void renderHourSegment()
{

setPixel(calculateHourHand(), hourColor, config.config.blendColors);
setPixel(calculateMinuteHand(), minuteColor, config.config.blendColors);
renderSecondHand();
uint8_t hour12 = localTime.hour() % 12;
uint8_t segmentLength = floor((float)config.config.ledCount / 12);
uint8_t segmentStart = floor((float)config.config.ledCount / 12 * hour12);
segmentStart = (segmentStart + config.config.ledRoot) % config.config.ledCount;
for (size_t i = 0; i < segmentLength; i++)
{
strip->SetPixelColor(segmentStart + i, segment);
}
}

strip->Show();
void showClockElements()
{
}

void setup()
Expand Down Expand Up @@ -140,24 +137,35 @@ void loop()

uint8_t sec = second();

strip->ClearTo(off);
if (currentSecond != sec)
{
currentMinute = minute();
currentSecond = sec;
updateColors(isNight());
webserver.currentTime = localTime.dateTime();
}

if (isAlarm() && tick())
{
alarmAnimation();
alarmAnimation(isNight());
}
else if (config.config.hourLight && currentMinute == 0 && !isAlarm() && tick())
{
hourRainbow();
hourRainbow(isNight());
}
else if (!isAlarm() && currentMinute != 0)
else if (!isAlarm() && currentMinute != 0 && tick())
{
currentSecond = second();
showClockElements();
currentSecond = sec;
renderHourDots();
renderHourSegment();

setPixel(calculateHourHand(), hourColor, config.config.blendColors);
setPixel(calculateMinuteHand(), minuteColor, config.config.blendColors);
renderSecondHand();

strip->Show();
animationPos = 0;
}
yield();
}

0 comments on commit 6e37e7f

Please sign in to comment.