Masking off the top leds if the flowers are open, and mapping between file names and clear core motor indices

This commit is contained in:
PS 2021-03-27 13:22:02 -07:00
parent 83707b10b9
commit bb7c175c33
3 changed files with 67 additions and 7 deletions

View File

@ -195,9 +195,11 @@ ConstructAssemblyFromDefinition (assembly* Assembly, led_system* LedSystem)
}
}
internal void
internal assembly*
LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena* Scratch, context Context, gs_const_string Path, event_log* GlobalLog)
{
assembly* NewAssembly = 0;
gs_file AssemblyFile = ReadEntireFile(Context.ThreadContext.FileHandler, Path);
if (FileNoError(AssemblyFile))
{
@ -206,7 +208,7 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena
s32 IndexOfLastSlash = FindLast(Path, '\\');
gs_const_string FileName = Substring(Path, IndexOfLastSlash + 1, Path.Length);
assembly* NewAssembly = AssemblyArray_Take(Assemblies);
NewAssembly = AssemblyArray_Take(Assemblies);
NewAssembly->Arena = CreateMemoryArena(Context.ThreadContext.Allocator, "Assembly Arena");
parser AssemblyParser = ParseAssemblyFile(NewAssembly, FileName, AssemblyFileText, Scratch);
@ -232,6 +234,8 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena
{
LogError(GlobalLog, "Unable to load assembly file");
}
return NewAssembly;
}
internal void

View File

@ -5,6 +5,24 @@
//
#ifndef BLUMEN_LUMEN_CPP
internal s32
GetCCIndex (assembly Assembly, blumen_lumen_state* BLState)
{
s32 Result = 0;
u64 AssemblyNameHash = HashDJB2ToU32(StringExpand(Assembly.Name));
for (u32 i = 0; i < BLState->AssemblyNameToClearCoreMapCount; i++)
{
if (AssemblyNameHash == BLState->AssemblyNameToClearCore_Names[i])
{
Result = (s32)i;
break;
}
}
return Result;
}
internal bool
MessageQueue_CanRead(blumen_network_msg_queue* Queue)
{
@ -190,9 +208,17 @@ BlumenLumen_CustomInit(app_state* State, context Context)
gs_const_string SculpturePath0 = ConstString("data/ss_blumen_one.fold");
gs_const_string SculpturePath1 = ConstString("data/ss_blumen_two.fold");
gs_const_string SculpturePath2 = ConstString("data/ss_blumen_three.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath0, State->GlobalLog);
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath1, State->GlobalLog);
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath2, State->GlobalLog);
assembly* Flower0 = LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath0, State->GlobalLog);
assembly* Flower1 = LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath1, State->GlobalLog);
assembly* Flower2 = LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath2, State->GlobalLog);
BLState->AssemblyNameToClearCoreMapCount = 3;
BLState->AssemblyNameToClearCore_Names = PushArray(&State->Permanent,
u64,
BLState->AssemblyNameToClearCoreMapCount);
BLState->AssemblyNameToClearCore_Names[0] = HashDJB2ToU32(StringExpand(Flower0->Name));
BLState->AssemblyNameToClearCore_Names[1] = HashDJB2ToU32(StringExpand(Flower1->Name));
BLState->AssemblyNameToClearCore_Names[2] = HashDJB2ToU32(StringExpand(Flower2->Name));
#endif
#if 1
@ -437,11 +463,23 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
}
}
// TODO(PS): This should really only happen if we think the
// flower _might_ be open
// NOTE(PS): If the flowers are mostly open or full open
// we mask off the top leds to prevent them from overheating
// while telescoped inside the flower
motor_packet CurrMotorPos = BLState->LastKnownMotorState;
for (u32 a = 0; a < State->Assemblies.Count; a++)
{
assembly Assembly = State->Assemblies.Values[a];
u64 AssemblyCCIndex = GetCCIndex(Assembly, BLState);
u8 MotorPos = CurrMotorPos.FlowerPositions[AssemblyCCIndex];
if (MotorPos == MotorState_Closed ||
MotorPos == MotorState_HalfOpen)
{
continue;
}
led_buffer Buffer = State->LedSystem.Buffers[Assembly.LedBufferIndex];
led_strip_list TopStrips = AssemblyStripsGetWithTagValue(Assembly, ConstString("section"), ConstString("inner_bloom"), State->Transient);

View File

@ -14,6 +14,16 @@ enum bl_python_packet_type
PacketType_LumenariumStatus = 4,
};
enum bl_motor_state_value
{
MotorState_Invalid = 0,
MotorState_Closed = 1,
MotorState_Open = 2,
MotorState_HalfOpen = 3,
MotorState_MostlyOpen = 4,
};
#pragma pack(push, 1)
typedef struct motor_packet
{
@ -171,6 +181,14 @@ struct blumen_lumen_state
system_time LastSendTime;
v4 AssemblyColors[3];
// The indices of this array are the index the clear core uses to
// represent a motor.
// The values of the array are the names Lumenarium uses to
// represent assemblies.
//
u32 AssemblyNameToClearCoreMapCount;
u64* AssemblyNameToClearCore_Names;
};