Skip to content

Commit

Permalink
Cleaned up types.h
Browse files Browse the repository at this point in the history
  • Loading branch information
connornishijima committed May 7, 2024
1 parent 0ffde02 commit b369691
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/global_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// Number of Goertzel instances running in parallel
#define NUM_FREQS ( 64 )

// How many characters a command can have
#define MAX_COMMAND_LENGTH (256)

// Max simultaneous remote controls allowed at one time
#define MAX_WEBSOCKET_CLIENTS ( 4 )

Expand Down
94 changes: 64 additions & 30 deletions src/types.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,106 @@
#define MAX_COMMAND_LENGTH (256)

// enum that stores three types: active, neutral, system
// no classes allowed in C, so we use enums to store types
enum lightshow_mode_type_t {
LIGHTSHOW_TYPE_ACTIVE,
LIGHTSHOW_TYPE_NEUTRAL,
LIGHTSHOW_TYPE_SYSTEM
/*
-----------------------------------------------------------------------------
--- EMOTISCOPE ENGINE -------------------------------------------------------
types.h
- Custom data types are defined here
-----------------------------------------------------------------------------
*/

// enum that stores three light mode types: active, neutral, system
// Active: reacts to sound
// Inactive: does not react to sound
// System: used for system animations
enum light_mode_type_t {
LIGHT_MODE_TYPE_ACTIVE,
LIGHT_MODE_TYPE_INACTIVE,
LIGHT_MODE_TYPE_SYSTEM
};

struct lightshow_mode {
char name[32];
lightshow_mode_type_t type;
void (*draw)();
// Light Modes are stored in a struct with a name, type, and draw function
struct light_mode {
char name[32]; // ............ What the mode is called
light_mode_type_t type; // ... What type of mode it is
void (*draw)(); // ........... Function pointer to how it's drawn
};

// A command is a string of characters that is sent from the web app to
// Emotiscope, or vice-versa. It also stores the origin client slot.
struct command {
char command[MAX_COMMAND_LENGTH];
uint8_t origin_client_slot;
};

// Used for the Goertzel algorithm to detect frequencies in the audio
struct freq {
float target_freq;
float coeff;
float window_step;
float magnitude;
float magnitude_full_scale;
float magnitude_last;
float novelty;
uint16_t block_size;
float target_freq; // ............ The frequency to detect
float coeff; // .................. The coefficient used in the algorithm
float window_step; // ............ The step size of the window
float magnitude; // .............. The magnitude of the frequency
float magnitude_full_scale; // ... The magnitude of the frequency at full scale
float magnitude_last; // ......... The last magnitude of the frequency
float novelty; // ................ The novelty of the frequency (spectral flux)
uint16_t block_size; // .......... The size of the block
};

// This is equivalent to CRGB from FastLED
struct CRGB8 {
uint8_t g;
uint8_t r;
uint8_t b;
};

struct CRGBF { // A bit like FastLED with floating point color channels that
// get quantized to 8 bits with dithering later
// CRGBFs are like CRGB8s, but with floating point color channels that
// get quantized to 8 bits with dithering later on in the pipeline
struct CRGBF {
float r;
float g;
float b;
};

struct fx_dot { // Used to draw dots with subpixel precision and motion blur
// Used to draw dots with subpixel precision and motion blur
struct fx_dot {
float position = 0.5;
float position_past = 0.5;
};

// Used to define Sliders in the web app
struct slider {
char name[32];
float slider_min;
float slider_max;
float slider_step;
};

// Used to define Toggles in the web app
struct toggle {
char name[32];
};

// Used to define Menu Toggles in the web app
struct menu_toggle {
char name[32];
};

// Used to define Menu Dropdowns in the web app
/*
struct menu_dropdown {
char name[32];
char options[32][32];
};
*/

// Used to store the state of profiled functions
struct profiler_function {
char name[32];
uint32_t cycles_total;
uint32_t hits;
};

// A tempo-based version of the Goertzel struct above
struct tempo {
float target_tempo_hz;
float target_tempo_hz;
float coeff;
float sine;
float cosine;
Expand All @@ -79,17 +115,14 @@ struct tempo {
uint32_t block_size;
};

// Clients are like Players in the web app. Like a video game console, they
// are plugged into one of four sockets
struct websocket_client {
int socket;
uint32_t last_ping;
};

struct CRGB8 {
uint8_t g;
uint8_t r;
uint8_t b;
};

// Stores the state of capacitive touch pins
struct touch_pin {
uint8_t pin;
uint32_t threshold;
Expand All @@ -101,6 +134,7 @@ struct touch_pin {
float touch_value;
};

// Stores all of Emotiscope's configurable settings
struct config {
float brightness;
float softness;
Expand Down

0 comments on commit b369691

Please sign in to comment.