2021-01-16 22:02:25 +00:00
|
|
|
//
|
|
|
|
// File: blumen_lumen.h
|
|
|
|
// Author: Peter Slattery
|
|
|
|
// Creation Date: 2021-01-15
|
|
|
|
//
|
|
|
|
#ifndef BLUMEN_LUMEN_H
|
|
|
|
|
2021-03-27 23:07:31 +00:00
|
|
|
#include "message_queue.h"
|
|
|
|
|
2021-03-01 00:58:22 +00:00
|
|
|
enum bl_python_packet_type
|
|
|
|
{
|
|
|
|
PacketType_Invalid = 0,
|
|
|
|
PacketType_PatternCommand = 1,
|
|
|
|
PacketType_MotorState = 2,
|
|
|
|
PacketType_Temperature = 3,
|
2021-03-20 22:15:35 +00:00
|
|
|
PacketType_LumenariumStatus = 4,
|
2021-03-01 00:58:22 +00:00
|
|
|
};
|
|
|
|
|
2021-03-27 20:22:02 +00:00
|
|
|
enum bl_motor_state_value
|
|
|
|
{
|
|
|
|
MotorState_Invalid = 0,
|
|
|
|
|
|
|
|
MotorState_Closed = 1,
|
|
|
|
MotorState_Open = 2,
|
|
|
|
MotorState_HalfOpen = 3,
|
|
|
|
MotorState_MostlyOpen = 4,
|
|
|
|
};
|
|
|
|
|
2021-03-01 00:58:22 +00:00
|
|
|
#pragma pack(push, 1)
|
2021-01-16 22:02:25 +00:00
|
|
|
typedef struct motor_packet
|
|
|
|
{
|
|
|
|
u8 FlowerPositions[3];
|
2021-03-21 04:49:02 +00:00
|
|
|
} motor_packet;
|
|
|
|
|
|
|
|
typedef struct motor_status_packet
|
|
|
|
{
|
|
|
|
motor_packet Pos;
|
2021-03-21 01:06:04 +00:00
|
|
|
/*
|
|
|
|
u8 Motor1Pos;
|
|
|
|
u8 Motor2Pos;
|
|
|
|
u8 Motor3Pos;
|
|
|
|
*/
|
|
|
|
u8 MotorStatus[3];
|
|
|
|
u16 Temperature;
|
|
|
|
|
2021-03-21 04:49:02 +00:00
|
|
|
} motor_status_packet;
|
2021-01-16 22:02:25 +00:00
|
|
|
|
2021-03-01 00:58:22 +00:00
|
|
|
typedef struct microphone_packet
|
2021-01-24 01:38:19 +00:00
|
|
|
{
|
|
|
|
b8 ChangeAnimation;
|
|
|
|
char AnimationFileName[32];
|
|
|
|
b8 SetLayer;
|
|
|
|
char LayerName[32];
|
|
|
|
r32 LayerOpacity;
|
|
|
|
b8 SetLayerParamColor;
|
|
|
|
char LayerParamColor[7];
|
|
|
|
r32 OverrideDuration;
|
2021-03-01 00:58:22 +00:00
|
|
|
} microphone_packet;
|
|
|
|
|
|
|
|
typedef struct temp_packet
|
|
|
|
{
|
|
|
|
s8 Temperature;
|
|
|
|
} temp_packet;
|
2021-03-20 22:15:35 +00:00
|
|
|
|
|
|
|
enum motor_event_type
|
|
|
|
{
|
|
|
|
MotorEvent_Close = 0,
|
|
|
|
MotorEvent_Open = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct status_packet
|
|
|
|
{
|
|
|
|
u8 NextMotorEventType;
|
2021-03-21 01:06:04 +00:00
|
|
|
// u16 Padding;
|
2021-03-20 22:15:35 +00:00
|
|
|
u32 NextEventTime;
|
2021-03-21 01:06:04 +00:00
|
|
|
|
2021-03-20 22:15:35 +00:00
|
|
|
char AnimFileName[32];
|
|
|
|
} status_packet;
|
|
|
|
|
|
|
|
typedef struct blumen_packet
|
|
|
|
{
|
2021-03-21 01:06:04 +00:00
|
|
|
u8 Type;
|
2021-03-20 22:15:35 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
motor_packet MotorPacket;
|
2021-03-21 04:49:02 +00:00
|
|
|
motor_status_packet MotorStatusPacket;
|
2021-03-20 22:15:35 +00:00
|
|
|
microphone_packet MicPacket;
|
|
|
|
temp_packet TempPacket;
|
|
|
|
status_packet StatusPacket;
|
|
|
|
};
|
|
|
|
} blumen_packet;
|
|
|
|
|
2021-01-24 01:38:19 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2021-01-30 22:01:04 +00:00
|
|
|
// TODO(pjs): Refactor this -> blumen_network_job_state
|
2021-01-30 21:22:43 +00:00
|
|
|
struct mic_listen_job_data
|
|
|
|
{
|
2021-02-20 21:14:54 +00:00
|
|
|
bool* Running;
|
|
|
|
|
2021-01-30 21:22:43 +00:00
|
|
|
platform_socket_manager* SocketManager;
|
2021-03-20 22:15:35 +00:00
|
|
|
blumen_network_msg_queue* IncomingMsgQueue;
|
2021-01-30 22:01:04 +00:00
|
|
|
|
|
|
|
blumen_network_msg_queue* OutgoingMsgQueue;
|
2021-01-30 21:22:43 +00:00
|
|
|
};
|
|
|
|
|
2021-03-20 22:15:35 +00:00
|
|
|
typedef struct time_range
|
|
|
|
{
|
|
|
|
s32 StartHour;
|
|
|
|
s32 StartMinute;
|
|
|
|
|
|
|
|
s32 EndHour;
|
|
|
|
s32 EndMinute;
|
|
|
|
} time_range;
|
|
|
|
|
|
|
|
internal bool
|
|
|
|
SystemTimeIsInTimeRange(system_time SysTime, time_range Range)
|
|
|
|
{
|
|
|
|
bool Result = (SysTime.Hour >= Range.StartHour &&
|
|
|
|
SysTime.Minute >= Range.StartMinute &&
|
|
|
|
SysTime.Hour <= Range.EndHour &&
|
|
|
|
SysTime.Minute <= Range.EndMinute);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-21 04:49:02 +00:00
|
|
|
struct phrase_string_to_anim_file
|
|
|
|
{
|
|
|
|
char* Phrase;
|
|
|
|
u32 PatternIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
phrase_string_to_anim_file PhraseToAnimMap[] = {
|
|
|
|
{ "begonia", 0},
|
|
|
|
{ "hyacinth", 1 },
|
|
|
|
{ "tulip", 1 },
|
|
|
|
{ "calla lilly", 0 },
|
|
|
|
{ "sunflower", 1 },
|
|
|
|
{ "salvia", 2 },
|
|
|
|
{ "freesia", 2 },
|
|
|
|
};
|
|
|
|
u32 PhraseToAnimMapCount = sizeof(PhraseToAnimMap) / sizeof(PhraseToAnimMap[0]);
|
|
|
|
|
2021-03-27 22:04:18 +00:00
|
|
|
#include "blumen_lumen_settings.h"
|
|
|
|
|
2021-01-24 01:38:19 +00:00
|
|
|
struct blumen_lumen_state
|
|
|
|
{
|
2021-02-20 21:14:54 +00:00
|
|
|
bool Running;
|
|
|
|
|
2021-03-20 22:15:35 +00:00
|
|
|
blumen_network_msg_queue IncomingMsgQueue;
|
2021-01-30 22:01:04 +00:00
|
|
|
blumen_network_msg_queue OutgoingMsgQueue;
|
|
|
|
|
2021-01-24 01:38:19 +00:00
|
|
|
temp_job_req JobReq;
|
2021-01-24 22:49:38 +00:00
|
|
|
|
|
|
|
platform_thread_handle MicListenThread;
|
2021-01-30 21:22:43 +00:00
|
|
|
mic_listen_job_data MicListenJobData;
|
2021-03-01 01:13:51 +00:00
|
|
|
|
|
|
|
motor_packet LastKnownMotorState;
|
2021-03-18 05:15:37 +00:00
|
|
|
|
|
|
|
r64 TimeElapsed;
|
|
|
|
|
|
|
|
animation_handle AnimHandles[3];
|
|
|
|
u32 CurrAnim;
|
2021-03-20 22:15:35 +00:00
|
|
|
|
|
|
|
// NOTE(pjs): Based on temperature data from weatherman
|
|
|
|
// dim the leds.
|
|
|
|
r32 BrightnessPercent;
|
|
|
|
system_time LastStatusUpdateTime;
|
2021-03-21 01:06:04 +00:00
|
|
|
|
|
|
|
system_time LastSendTime;
|
2021-03-25 02:45:11 +00:00
|
|
|
|
2021-03-27 21:46:17 +00:00
|
|
|
phrase_hue AssemblyColors[3];
|
|
|
|
u32 LastAssemblyColorSet;
|
2021-03-27 20:22:02 +00:00
|
|
|
|
|
|
|
// 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;
|
2021-03-27 20:23:47 +00:00
|
|
|
|
2021-03-27 21:46:17 +00:00
|
|
|
phrase_hue_map PhraseHueMap;
|
|
|
|
|
2021-03-25 08:46:27 +00:00
|
|
|
// Debug
|
|
|
|
motor_packet DEBUG_PendingMotorPacket;
|
2021-01-24 01:38:19 +00:00
|
|
|
};
|
2021-02-06 23:10:14 +00:00
|
|
|
|
2021-03-27 23:07:31 +00:00
|
|
|
#include "message_queue.cpp"
|
2021-02-06 23:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If you change anything, exit lumenarium if its running
|
|
|
|
// then in this application hit f1 to compile then
|
|
|
|
// go to remedybg (the debugger) and hit f5
|
|
|
|
|
|
|
|
|
|
|
|
// don't touch this
|
|
|
|
u8 LastPosition = 1;
|
|
|
|
|
|
|
|
u8 ClosedValue = 1;
|
|
|
|
u8 OpenValue = 2;
|
|
|
|
|
|
|
|
|
|
|
|
r64 MotorTimeElapsed = 0;
|
|
|
|
r64 OpenClosePeriod = 15.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-24 01:38:19 +00:00
|
|
|
|
2021-01-16 22:02:25 +00:00
|
|
|
|
|
|
|
#define BLUMEN_LUMEN_H
|
|
|
|
#endif // BLUMEN_LUMEN_H
|