From bb7c175c33944a14862f5ea13c22100ed2c71134 Mon Sep 17 00:00:00 2001 From: PS Date: Sat, 27 Mar 2021 13:22:02 -0700 Subject: [PATCH] Masking off the top leds if the flowers are open, and mapping between file names and clear core motor indices --- src/app/engine/assembly/foldhaus_assembly.cpp | 8 +++- src/app/ss_blumen_lumen/blumen_lumen.cpp | 48 +++++++++++++++++-- src/app/ss_blumen_lumen/blumen_lumen.h | 18 +++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/app/engine/assembly/foldhaus_assembly.cpp b/src/app/engine/assembly/foldhaus_assembly.cpp index ebbff73..6264b0e 100644 --- a/src/app/engine/assembly/foldhaus_assembly.cpp +++ b/src/app/engine/assembly/foldhaus_assembly.cpp @@ -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 diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index fd02a59..c317696 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -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); diff --git a/src/app/ss_blumen_lumen/blumen_lumen.h b/src/app/ss_blumen_lumen/blumen_lumen.h index fb5b238..2e253e0 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.h +++ b/src/app/ss_blumen_lumen/blumen_lumen.h @@ -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; };