Skip to content

Commit

Permalink
Rainbow highlight is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Sep 18, 2017
1 parent 558cd20 commit f592ca4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
2 changes: 1 addition & 1 deletion doxygen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Nixie Library"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.1.1
PROJECT_NUMBER = 1.1.2

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
60 changes: 56 additions & 4 deletions examples/nixie_clock_in14_v1/clock_colorsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ static const SNixieColor colorProfiles[] =
{128, 0,100}, // Light purple
};

static const SNixieColor s_rainbow[] =
{
{252, 0, 0},
{252,252, 0},
{ 0,252, 0},
{ 0,252,252},
{ 0, 0,252},
{252, 0,252},
};

static SNixieColor s_rainbowColor = {252,0,0};
static uint8_t s_rainbowIndex = 0;

static uint8_t s_colorProfile;
static SNixieColor s_color;
Expand All @@ -61,6 +73,7 @@ void updateHighlight(bool useLightSensor, uint8_t sensorBrightness)
if ( g_savedSettings.nightHighlightBrightness == 0 )
{
g_highlight.off();
return;
}
else
{
Expand All @@ -86,11 +99,39 @@ void updateHighlight(bool useLightSensor, uint8_t sensorBrightness)
}
else
{
g_highlight.rgb(colorProfiles[g_savedSettings.colorProfile]);
if ( isRainbowMode() )
{
if ( (s_rainbowColor.r == s_rainbow[s_rainbowIndex].r) &&
(s_rainbowColor.g == s_rainbow[s_rainbowIndex].g) &&
(s_rainbowColor.b == s_rainbow[s_rainbowIndex].b)
)
{
s_rainbowIndex++;
if ( s_rainbowIndex == sizeof(s_rainbow)/sizeof(SNixieColor) )
{
s_rainbowIndex = 0;
}
}
if (s_rainbowColor.r < s_rainbow[s_rainbowIndex].r) s_rainbowColor.r += 4;
else if (s_rainbowColor.r > s_rainbow[s_rainbowIndex].r) s_rainbowColor.r -= 4;
if (s_rainbowColor.g < s_rainbow[s_rainbowIndex].g) s_rainbowColor.g += 4;
else if (s_rainbowColor.g > s_rainbow[s_rainbowIndex].g) s_rainbowColor.g -= 4;
if (s_rainbowColor.b < s_rainbow[s_rainbowIndex].b) s_rainbowColor.b += 4;
else if (s_rainbowColor.b > s_rainbow[s_rainbowIndex].b) s_rainbowColor.b -= 4;
g_highlight.rgb(s_rainbowColor);
}
else
{
g_highlight.rgb(colorProfiles[g_savedSettings.colorProfile]);
}
}
}


bool isRainbowMode()
{
return g_savedSettings.colorProfile == sizeof( colorProfiles )/sizeof(SNixieColor);
}

void colorSetupEnterFunction()
{
NixieOs::startTimer(0,SETUP_INACTIVITY_TIMEOUT_MS);
Expand Down Expand Up @@ -161,9 +202,20 @@ static void updateColor()
{
g_highlight.brightness(s_brightness);
if (s_colorProfile == 0xFF)
{
g_highlight.rgb(s_color);
}
else
g_highlight.rgb(colorProfiles[s_colorProfile]);
{
if ( s_colorProfile == sizeof(colorProfiles)/sizeof(SNixieColor) )
{
g_highlight.rgb(s_rainbowColor);
}
else
{
g_highlight.rgb(colorProfiles[s_colorProfile]);
}
}
}
else
{
Expand Down Expand Up @@ -243,7 +295,7 @@ void colorSetupEventFunction(SNixieEvent &event)
else
{
s_colorProfile++;
if (s_colorProfile >= sizeof(colorProfiles)/sizeof(SNixieColor))
if (s_colorProfile > sizeof(colorProfiles)/sizeof(SNixieColor))
{
s_colorProfile = 0xFF;
}
Expand Down
1 change: 1 addition & 0 deletions examples/nixie_clock_in14_v1/clock_colorsetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "nixieos.h"

bool isRainbowMode();
void updateHighlight(bool useLightSensor, uint8_t sensorBrightness);
void colorSetupEnterFunction();
void colorSetupStateFunction();
Expand Down
8 changes: 4 additions & 4 deletions examples/nixie_clock_in14_v1/clock_diorama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ static inline bool notInDoorLightsTime()

static inline bool outDoorLightsTime()
{
return g_sensor.brightness() <= OUTDOOR_LIGHT_THRESHOLD_LOW
&& g_sensor.brightness() > 2
return g_sensor.brightness() > OUTDOOR_LIGHT_THRESHOLD_LOW
&& g_sensor.brightness() < OUTDOOR_LIGHT_THRESHOLD_HIGH
&& outdoorLightEnable;
}

static inline bool notOutDoorLightsTime()
{
return g_sensor.brightness() >= OUTDOOR_LIGHT_THRESHOLD_HIGH
return g_sensor.brightness() > (OUTDOOR_LIGHT_THRESHOLD_HIGH + 1)
|| !outdoorLightEnable
|| g_sensor.brightness() < 2;
|| g_sensor.brightness() < (OUTDOOR_LIGHT_THRESHOLD_LOW -1);
}

static uint8_t calcOutdoorBrightness()
Expand Down
2 changes: 1 addition & 1 deletion examples/nixie_clock_in14_v1/clock_fine_tuning.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
/** Maximum brightness of Outdoor lights (0-32) */
#define OUTDOOR_LIGHT_MAX_BRIGHTNESS 32

#define OUTDOOR_LIGHT_THRESHOLD_LOW (8)
#define OUTDOOR_LIGHT_THRESHOLD_LOW (6)
#define OUTDOOR_LIGHT_THRESHOLD_HIGH (13)
#define INDOOR_LIGHT_THRESHOLD_LOW (6)
#define INDOOR_LIGHT_THRESHOLD_HIGH (16)
Expand Down
5 changes: 5 additions & 0 deletions examples/nixie_clock_in14_v1/nixie_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void SNixieSettings::read(int base)
if (highlightBrightness == 0xFF)
{
highlightOn = true;
// colorProfile = 7;
highlightBrightness = NIXIE_MAX_BRIGHTNESS;
highlightColor.r = 64;
highlightColor.g = 168;
Expand Down Expand Up @@ -146,6 +147,10 @@ void NixieClock::dimLight()
updateTubesBrightness( lastBrightness );
updateHighlight(true, lastBrightness);
}
else if (isRainbowMode())
{
updateHighlight(true, lastBrightness);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NixieLibrary
version=1.1.1
version=1.1.2
author=Alexey Dynda
maintainer=Alexey Dynda <[email protected]>
sentence=Nixie Library is intended for Nixie Clock software development.
Expand Down
6 changes: 1 addition & 5 deletions src/nixie_ds3232.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,8 @@ int16_t Ds3231::timeDelta(int16_t min1, int16_t min2)
if (delta1 < 0)
{
delta1 = - delta1;
delta2 = 24*60 + min2 - min1;
}
else
{
delta2 = 24*60 + min1 - min2;
}
delta2 = 24*60 - delta1;
return delta1 < delta2 ? delta1: delta2;
}

Expand Down

0 comments on commit f592ca4

Please sign in to comment.