Cleaning Up blumen_lumen user space code

This commit is contained in:
PS 2021-03-27 15:04:18 -07:00
parent 874925a5fe
commit c4769bd53c
6 changed files with 138 additions and 108 deletions

View File

@ -82,6 +82,17 @@ internal void OpenColorPicker(app_state* State, v4* Address);
#include "engine/assembly/foldhaus_assembly.cpp"
internal assembly*
LoadAssembly(gs_const_string Path, app_state* State, context Context)
{
return LoadAssembly(&State->Assemblies,
&State->LedSystem,
State->Transient,
Context,
Path,
State->GlobalLog);
}
#include "engine/user_space.cpp"
#include "patterns/blumen_patterns.h"

View File

@ -57,16 +57,25 @@ DEBUG_SentMotorCommand(motor_packet Packet, gs_thread_context Ctx)
}
internal void
DEBUG_ReceivedMotorPositions(motor_packet Packet, gs_thread_context Ctx)
DEBUG_ReceivedMotorPositions(motor_packet NewPos,
motor_packet LastPos,
gs_thread_context Ctx)
{
gs_string Str = PushStringF(Ctx.Transient, 256, "Motor Status Received\nCurrent Positions: %d %d %d\n",
Packet.FlowerPositions[0],
Packet.FlowerPositions[1],
Packet.FlowerPositions[2]);
DEBUG_AppendText(Str, Ctx);
bool PosChanged = (LastPos.FlowerPositions[0] != NewPos.FlowerPositions[0] ||
LastPos.FlowerPositions[1] != NewPos.FlowerPositions[1] ||
LastPos.FlowerPositions[2] != NewPos.FlowerPositions[2]);
NullTerminate(&Str);
OutputDebugStringA(Str.Str);
if (PosChanged)
{
gs_string Str = PushStringF(Ctx.Transient, 256, "Motor Status Received\nCurrent Positions: %d %d %d\n",
NewPos.FlowerPositions[0],
NewPos.FlowerPositions[1],
NewPos.FlowerPositions[2]);
DEBUG_AppendText(Str, Ctx);
NullTerminate(&Str);
OutputDebugStringA(Str.Str);
}
}
// KB(1) is just bigger than any packet we send. Good for now
@ -261,34 +270,27 @@ BlumenLumen_CustomInit(app_state* State, context Context)
BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData);
#endif
#if 0
gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog);
#else
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");
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);
assembly* Flower0 = LoadAssembly(Flower0AssemblyPath, State, Context);
assembly* Flower1 = LoadAssembly(Flower1AssemblyPath, State, Context);
assembly* Flower2 = LoadAssembly(Flower2AssemblyPath, State, Context);
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
BLState->AssemblyNameToClearCore_Names[0] = HashDJB2ToU64(Flower0->Name);
BLState->AssemblyNameToClearCore_Names[1] = HashDJB2ToU64(Flower1->Name);
BLState->AssemblyNameToClearCore_Names[2] = HashDJB2ToU64(Flower2->Name);
{
gs_file ColorPhraseCSVFile = ReadEntireFile(Context.ThreadContext.FileHandler, ConstString("data/flower_codes.tsv"));
gs_const_string ColorPhraseMapStr = ConstString((char*)ColorPhraseCSVFile.Memory,
ColorPhraseCSVFile.Size);
gscsv_sheet ColorPhraseSheet = CSV_Parse(ColorPhraseMapStr, { '\t' }, State->Transient);
gs_file_handler FileHandler = Context.ThreadContext.FileHandler;
gs_file ColorPhraseCSVFile = ReadEntireFile(FileHandler, PhraseMapCSVPath);
gs_const_string ColorPhraseMapStr = DataToString(ColorPhraseCSVFile.Data);
gscsv_sheet ColorPhraseSheet = CSV_Parse(ColorPhraseMapStr,
{ PhraseMapCSVSeparator },
State->Transient);
BLState->PhraseHueMap = PhraseHueMap_GenFromCSV(ColorPhraseSheet, &State->Permanent);
}
BLState->PhraseHueMap = PhraseHueMap_GenFromCSV(ColorPhraseSheet,
&State->Permanent);
#if 1
{ // Animation PLAYGROUND
@ -343,19 +345,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
bool SendMotorCommand = false;
blumen_packet MotorCommand = {};
#if 0
MotorTimeElapsed += Context->DeltaTime;
BLState->TimeElapsed += Context->DeltaTime;
if (BLState->TimeElapsed > 5)
{
u32 NextIndex = ++BLState->CurrAnim % 3;
animation_handle Next = BLState->AnimHandles[NextIndex];
AnimationFadeGroup_FadeTo(&State->AnimationSystem.ActiveFadeGroup, Next, 5);
BLState->TimeElapsed = 0;
}
#endif
while (MessageQueue_CanRead(BLState->IncomingMsgQueue))
{
gs_data PacketData = MessageQueue_Read(&BLState->IncomingMsgQueue);
@ -406,12 +395,7 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
T[1] << 0);
motor_packet LastPos = BLState->LastKnownMotorState;
if (LastPos.FlowerPositions[0] != Motor.Pos.FlowerPositions[0] ||
LastPos.FlowerPositions[1] != Motor.Pos.FlowerPositions[1] ||
LastPos.FlowerPositions[2] != Motor.Pos.FlowerPositions[2])
{
DEBUG_ReceivedMotorPositions(Motor.Pos, Context->ThreadContext);
}
DEBUG_ReceivedMotorPositions(LastPos, Motor.Pos, Context->ThreadContext);
BLState->LastKnownMotorState = Motor.Pos;
}break;
@ -429,7 +413,8 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
BLState->BrightnessPercent = 1.f;
}
gs_string TempStr = PushStringF(State->Transient, 256, "\nTemperature: %d\n",
gs_string TempStr = PushStringF(State->Transient, 256,
"\nTemperature: %d\n",
Temp.Temperature);
NullTerminate(&TempStr);
OutputDebugStringA(TempStr.Str);
@ -441,10 +426,8 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
// Open / Close the Motor
if (MessageQueue_CanWrite(BLState->OutgoingMsgQueue))
{
#if 1
for (u32 i = 0; i < MotorOpenTimesCount; i++)
{
time_range Range = MotorOpenTimes[i];
@ -487,7 +470,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
MotorCommand = Packet;
}
}
#endif
if (SendMotorCommand)
{
@ -497,8 +479,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
}
}
// Dim the leds based on temp data
#define DIM_LED_BRIGHTNESS 1
#if DIM_LED_BRIGHTNESS
for (u32 i = 0; i < State->LedSystem.BuffersCount; i++)
{
led_buffer Buffer = State->LedSystem.Buffers[i];
@ -517,11 +497,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
motor_packet CurrMotorPos = BLState->LastKnownMotorState;
for (u32 a = 0; a < State->Assemblies.Count; a++)
{
// TODO(PS): make sure to align which assembly goes with which
// flower index
bool FlowerIsOpen = BLState->LastKnownMotorState.FlowerPositions[a] == 2;
//if (!FlowerIsOpen) continue;
assembly Assembly = State->Assemblies.Values[a];
u64 AssemblyCCIndex = GetCCIndex(Assembly, BLState);
@ -547,7 +522,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
}
}
}
#endif
// Send Status Packet
{

View File

@ -128,53 +128,6 @@ SystemTimeIsInTimeRange(system_time SysTime, time_range Range)
return Result;
}
global time_range MotorOpenTimes[] = {
{ 00, 30, 00, 40 },
{ 00, 50, 01, 00 },
{ 01, 10, 01, 20 },
{ 01, 30, 01, 40 },
{ 01, 50, 02, 00 },
{ 02, 10, 02, 20 },
{ 02, 30, 02, 40 },
{ 02, 50, 03, 00 },
{ 03, 10, 03, 20 },
{ 03, 30, 03, 40 },
{ 03, 50, 04, 00 },
{ 04, 10, 04, 20 },
{ 04, 30, 04, 40 },
{ 04, 50, 05, 00 },
{ 05, 10, 05, 20 },
{ 05, 30, 05, 40 },
{ 05, 50, 06, 00 },
{ 06, 10, 06, 20 },
{ 06, 30, 06, 40 },
{ 06, 50, 07, 00 },
{ 07, 10, 07, 20 },
{ 07, 30, 07, 40 },
{ 07, 50, 8, 00 },
{ 8, 10, 8, 20 },
{ 8, 30, 8, 40 },
{ 8, 50, 9, 00 },
{ 9, 10, 9, 20 },
{ 9, 30, 9, 40 },
{ 9, 50, 10, 00 },
{ 10, 10, 10, 20 },
{ 10, 30, 10, 40 },
{ 10, 50, 11, 00 },
{ 11, 10, 11, 20 },
{ 11, 30, 11, 40 },
{ 11, 50, 12, 00 },
{ 12, 10, 12, 20 },
{ 12, 30, 12, 40 },
{ 12, 50, 13, 00 },
{ 13, 10, 13, 20 },
{ 13, 30, 13, 40 },
{ 13, 50, 14, 00 },
{ 14, 10, 14, 20 },
{ 14, 30, 14, 40 },
{ 14, 50, 15, 00 },
};
global u32 MotorOpenTimesCount = sizeof(MotorOpenTimes) / sizeof(MotorOpenTimes[0]);;
struct phrase_string_to_anim_file
{
@ -193,6 +146,8 @@ phrase_string_to_anim_file PhraseToAnimMap[] = {
};
u32 PhraseToAnimMapCount = sizeof(PhraseToAnimMap) / sizeof(PhraseToAnimMap[0]);
#include "blumen_lumen_settings.h"
struct blumen_lumen_state
{
bool Running;

View File

@ -0,0 +1,61 @@
/* date = March 27th 2021 2:50 pm */
#ifndef BLUMEN_LUMEN_SETTINGS_H
#define BLUMEN_LUMEN_SETTINGS_H
gs_const_string Flower0AssemblyPath = ConstString("data/ss_blumen_one.fold");
gs_const_string Flower1AssemblyPath = ConstString("data/ss_blumen_two.fold");
gs_const_string Flower2AssemblyPath = ConstString("data/ss_blumen_three.fold");
gs_const_string PhraseMapCSVPath = ConstString("data/flower_codes.tsv");
char PhraseMapCSVSeparator = '\t';
global time_range MotorOpenTimes[] = {
{ 00, 30, 00, 40 },
{ 00, 50, 01, 00 },
{ 01, 10, 01, 20 },
{ 01, 30, 01, 40 },
{ 01, 50, 02, 00 },
{ 02, 10, 02, 20 },
{ 02, 30, 02, 40 },
{ 02, 50, 03, 00 },
{ 03, 10, 03, 20 },
{ 03, 30, 03, 40 },
{ 03, 50, 04, 00 },
{ 04, 10, 04, 20 },
{ 04, 30, 04, 40 },
{ 04, 50, 05, 00 },
{ 05, 10, 05, 20 },
{ 05, 30, 05, 40 },
{ 05, 50, 06, 00 },
{ 06, 10, 06, 20 },
{ 06, 30, 06, 40 },
{ 06, 50, 07, 00 },
{ 07, 10, 07, 20 },
{ 07, 30, 07, 40 },
{ 07, 50, 8, 00 },
{ 8, 10, 8, 20 },
{ 8, 30, 8, 40 },
{ 8, 50, 9, 00 },
{ 9, 10, 9, 20 },
{ 9, 30, 9, 40 },
{ 9, 50, 10, 00 },
{ 10, 10, 10, 20 },
{ 10, 30, 10, 40 },
{ 10, 50, 11, 00 },
{ 11, 10, 11, 20 },
{ 11, 30, 11, 40 },
{ 11, 50, 12, 00 },
{ 12, 10, 12, 20 },
{ 12, 30, 12, 40 },
{ 12, 50, 13, 00 },
{ 13, 10, 13, 20 },
{ 13, 30, 13, 40 },
{ 13, 50, 14, 00 },
{ 14, 10, 14, 20 },
{ 14, 30, 14, 40 },
{ 14, 50, 15, 00 },
};
global u32 MotorOpenTimesCount = CArrayLength(MotorOpenTimes);
#endif //BLUMEN_LUMEN_SETTINGS_H

View File

@ -1390,6 +1390,13 @@ internal gs_data StringToData(gs_string String)
{
return StringToData(String.ConstString);
}
internal gs_const_string DataToString(gs_data Data)
{
gs_const_string Result = {};
Result.Str = (char*)Data.Memory;
Result.Length = Data.Size;
return Result;
}
internal bool IsSlash(char C) { return ((C == '/') || (C == '\\')); }
internal bool IsUpper(char C) { return(('A' <= C) && (C <= 'Z')); }
@ -3783,6 +3790,16 @@ HashDJB2ToU32(u32 Length, char* String)
}
return Hash;
}
internal u32
HashDJB2ToU32(gs_const_string Str)
{
return HashDJB2ToU32(StringExpand(Str));
}
internal u32
HashDJB2ToU32(gs_string Str)
{
return HashDJB2ToU32(StringExpand(Str));
}
internal u64
HashDJB2ToU64(char* String)
@ -3805,6 +3822,16 @@ HashDJB2ToU64(u32 Length, char* String)
}
return Hash;
}
internal u64
HashDJB2ToU64(gs_const_string Str)
{
return HashDJB2ToU64(StringExpand(Str));
}
internal u64
HashDJB2ToU64(gs_string Str)
{
return HashDJB2ToU64(StringExpand(Str));
}
///////////////////////////
//

View File

@ -273,6 +273,8 @@ Glue(gs_AssertFail_, __LINE__) = 1 / (int)(!!(c)), \
#define IsPowerOfTwo(x) (((x) & ((x) - 1)) == 0)
#define IsOdd(x) (((x) & 1) != 0)
#define CArrayLength(arr) (sizeof(arr) / (sizeof(arr[0])))
internal void
ZeroMemory_(u8* Memory, u64 Size)
{