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 = {};
|
||||||
|
if (SystemTimeIsInTimeRangeList(Context->SystemTime_Current,
|
||||||
|
LedOnTimes,
|
||||||
|
LedOnTimesCount,
|
||||||
|
&RangeIn))
|
||||||
{
|
{
|
||||||
time_range Range = LedOnTimes[i];
|
// If we're in one of the specified time ranges,
|
||||||
bool CurrTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Current, Range);
|
// play animations and set brightness
|
||||||
if (CurrTimeInRange)
|
//
|
||||||
{
|
// The values of BrightnessPercent and TimelineShouldAdvance
|
||||||
// If we're in one of the specified time ranges,
|
// are set according to less strict rules above in this update
|
||||||
// play animations and set brightness
|
// function. All we are doing is saying "If we are in a valid
|
||||||
OverrideBrightness = BLState->BrightnessPercent;
|
// time range, keep those values".
|
||||||
TimelineShouldAdvance = State->AnimationSystem.TimelineShouldAdvance;
|
OverrideBrightness = BLState->BrightnessPercent;
|
||||||
break;
|
TimelineShouldAdvance = State->AnimationSystem.TimelineShouldAdvance;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
Result = IsAfterStartTime && IsBeforeEndTime;
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool
|
||||||
|
SystemTimeIsInTimeRangeList(system_time SysTime, time_range* Ranges, u32 RangesCount, time_range* RangeOut = 0)
|
||||||
|
{
|
||||||
|
bool Result = false;
|
||||||
|
for (u32 i = 0; i < RangesCount; i++)
|
||||||
{
|
{
|
||||||
if (SysTime.Hour == Range.StartHour)
|
time_range Range = Ranges[i];
|
||||||
{
|
bool CurrTimeInRange = SystemTimeIsInTimeRange(SysTime, Range);
|
||||||
Result = (SysTime.Minute >= Range.StartMinute);
|
if (CurrTimeInRange)
|
||||||
}
|
|
||||||
else if (SysTime.Hour == Range.EndHour)
|
|
||||||
{
|
|
||||||
Result = (SysTime.Minute <= Range.EndMinute);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
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