Updating time / led brightness logging and fixed a time range checking issue
This commit is contained in:
parent
27ad4cd579
commit
c1ac7173db
|
@ -314,6 +314,24 @@ BlumenLumen_UpdateLog(app_state* State, blumen_lumen_state* BLState, context Con
|
||||||
|
|
||||||
AppendPrintF(&FileStr, "Pattern Brightness: %f\n", BLState->BrightnessPercent);
|
AppendPrintF(&FileStr, "Pattern Brightness: %f\n", BLState->BrightnessPercent);
|
||||||
|
|
||||||
|
time_range RangeIn = {};
|
||||||
|
if (SystemTimeIsInTimeRangeList(Context.SystemTime_Current,
|
||||||
|
LedOnTimes,
|
||||||
|
LedOnTimesCount,
|
||||||
|
&RangeIn))
|
||||||
|
{
|
||||||
|
AppendPrintF(&FileStr, "\tIn Leds-On Time Range: ( %d:%d - %d:%d)\n",
|
||||||
|
RangeIn.StartHour, RangeIn.StartMinute,
|
||||||
|
RangeIn.EndHour, RangeIn.EndMinute);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppendPrintF(&FileStr, "\tIn Leds-On Time Range: None\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendPrintF(&FileStr, "\tTemp Dimming: %s\n",
|
||||||
|
Blumen_TempShouldDimLeds(BLState) ? "On" : "Off");
|
||||||
|
|
||||||
AppendPrintF(&FileStr, "Last Temp Received: %d\n", BLState->LastTemperatureReceived);
|
AppendPrintF(&FileStr, "Last Temp Received: %d\n", BLState->LastTemperatureReceived);
|
||||||
|
|
||||||
gs_data LogMem = StringToData(FileStr);
|
gs_data LogMem = StringToData(FileStr);
|
||||||
|
@ -528,8 +546,9 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
|
||||||
case PacketType_Temperature:
|
case PacketType_Temperature:
|
||||||
{
|
{
|
||||||
temp_packet Temp = Packet.TempPacket;
|
temp_packet Temp = Packet.TempPacket;
|
||||||
|
BLState->LastTemperatureReceived = Temp.Temperature;
|
||||||
|
|
||||||
if (Temp.Temperature > MinHighTemperature)
|
if (Blumen_TempShouldDimLeds(BLState))
|
||||||
{
|
{
|
||||||
BLState->BrightnessPercent = HighTemperatureBrightnessPercent;
|
BLState->BrightnessPercent = HighTemperatureBrightnessPercent;
|
||||||
}
|
}
|
||||||
|
@ -537,7 +556,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
|
||||||
{
|
{
|
||||||
BLState->BrightnessPercent = FullBrightnessPercent;
|
BLState->BrightnessPercent = FullBrightnessPercent;
|
||||||
}
|
}
|
||||||
BLState->LastTemperatureReceived = Temp.Temperature;
|
|
||||||
|
|
||||||
DEBUG_ReceivedTemperature(Temp, Context->ThreadContext);
|
DEBUG_ReceivedTemperature(Temp, Context->ThreadContext);
|
||||||
BLState->ShouldUpdateLog = true;
|
BLState->ShouldUpdateLog = true;
|
||||||
|
@ -711,19 +729,24 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
|
||||||
{
|
{
|
||||||
bool TimelineShouldAdvance = false;
|
bool TimelineShouldAdvance = false;
|
||||||
r32 OverrideBrightness = 0.0f;
|
r32 OverrideBrightness = 0.0f;
|
||||||
for (u32 i = 0; i < LedOnTimesCount; i++)
|
|
||||||
{
|
time_range RangeIn = {};
|
||||||
time_range Range = LedOnTimes[i];
|
if (SystemTimeIsInTimeRangeList(Context->SystemTime_Current,
|
||||||
bool CurrTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Current, Range);
|
LedOnTimes,
|
||||||
if (CurrTimeInRange)
|
LedOnTimesCount,
|
||||||
|
&RangeIn))
|
||||||
{
|
{
|
||||||
// If we're in one of the specified time ranges,
|
// If we're in one of the specified time ranges,
|
||||||
// play animations and set brightness
|
// play animations and set brightness
|
||||||
|
//
|
||||||
|
// The values of BrightnessPercent and TimelineShouldAdvance
|
||||||
|
// are set according to less strict rules above in this update
|
||||||
|
// function. All we are doing is saying "If we are in a valid
|
||||||
|
// time range, keep those values".
|
||||||
OverrideBrightness = BLState->BrightnessPercent;
|
OverrideBrightness = BLState->BrightnessPercent;
|
||||||
TimelineShouldAdvance = State->AnimationSystem.TimelineShouldAdvance;
|
TimelineShouldAdvance = State->AnimationSystem.TimelineShouldAdvance;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
State->AnimationSystem.TimelineShouldAdvance = TimelineShouldAdvance;
|
State->AnimationSystem.TimelineShouldAdvance = TimelineShouldAdvance;
|
||||||
BLState->BrightnessPercent = OverrideBrightness;
|
BLState->BrightnessPercent = OverrideBrightness;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,24 +134,57 @@ typedef struct time_range
|
||||||
s32 EndMinute;
|
s32 EndMinute;
|
||||||
} time_range;
|
} time_range;
|
||||||
|
|
||||||
|
internal bool
|
||||||
|
SystemTimeIsBeforeTime(system_time SysTime, s32 Hour, s32 Minute)
|
||||||
|
{
|
||||||
|
bool Result = false;
|
||||||
|
if (SysTime.Hour == Hour) {
|
||||||
|
Result = SysTime.Minute < Minute;
|
||||||
|
} else {
|
||||||
|
Result = SysTime.Hour < Hour;
|
||||||
|
}
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool
|
||||||
|
SystemTimeIsAfterTime(system_time SysTime, s32 Hour, s32 Minute)
|
||||||
|
{
|
||||||
|
bool Result = false;
|
||||||
|
if (SysTime.Hour == Hour) {
|
||||||
|
Result = SysTime.Minute > Minute;
|
||||||
|
} else {
|
||||||
|
Result = SysTime.Hour > Hour;
|
||||||
|
}
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
internal bool
|
internal bool
|
||||||
SystemTimeIsInTimeRange(system_time SysTime, time_range Range)
|
SystemTimeIsInTimeRange(system_time SysTime, time_range Range)
|
||||||
{
|
{
|
||||||
bool Result = false;
|
bool Result = false;
|
||||||
if (SysTime.Hour >= Range.StartHour &&
|
|
||||||
SysTime.Hour <= Range.EndHour)
|
bool IsAfterStartTime = SystemTimeIsAfterTime(SysTime, Range.StartHour, Range.StartMinute);
|
||||||
{
|
bool IsBeforeEndTime = SystemTimeIsBeforeTime(SysTime, Range.EndHour, Range.EndMinute);
|
||||||
if (SysTime.Hour == Range.StartHour)
|
Result = IsAfterStartTime && IsBeforeEndTime;
|
||||||
{
|
|
||||||
Result = (SysTime.Minute >= Range.StartMinute);
|
return Result;
|
||||||
}
|
}
|
||||||
else if (SysTime.Hour == Range.EndHour)
|
|
||||||
|
internal bool
|
||||||
|
SystemTimeIsInTimeRangeList(system_time SysTime, time_range* Ranges, u32 RangesCount, time_range* RangeOut = 0)
|
||||||
{
|
{
|
||||||
Result = (SysTime.Minute <= Range.EndMinute);
|
bool Result = false;
|
||||||
}
|
for (u32 i = 0; i < RangesCount; i++)
|
||||||
else
|
{
|
||||||
|
time_range Range = Ranges[i];
|
||||||
|
bool CurrTimeInRange = SystemTimeIsInTimeRange(SysTime, Range);
|
||||||
|
if (CurrTimeInRange)
|
||||||
{
|
{
|
||||||
Result = true;
|
Result = true;
|
||||||
|
if (RangeOut != 0) {
|
||||||
|
*RangeOut = Range;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -233,6 +266,13 @@ struct blumen_lumen_state
|
||||||
phrase_hue DebugHue;
|
phrase_hue DebugHue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
internal bool
|
||||||
|
Blumen_TempShouldDimLeds(blumen_lumen_state* BLState)
|
||||||
|
{
|
||||||
|
bool Result = BLState->LastTemperatureReceived > MinHighTemperature;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
#include "message_queue.cpp"
|
#include "message_queue.cpp"
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
|
Loading…
Reference in New Issue