init commit

This commit is contained in:
mk
2025-12-01 06:47:16 -03:00
commit d6faf3e062
19 changed files with 2116 additions and 0 deletions

37
include/README Normal file
View File

@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

29
include/base_pattern.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef BASE_PATTERN_H
#define BASE_PATTERN_H
#include <Arduino.h>
#include <FastLED.h>
class BasePattern {
public:
BasePattern() : timeToProcess(2000), lastProcessed(millis()) {};
virtual ~BasePattern() = default;
// Called once at start
virtual void init() { Serial.printf("BasePattern::init\n"); };
// Called repeatedly. Return true to request exit, false to continue.
virtual void loop() { Serial.printf("BasePattern::loop\n"); };
// Called once at end
virtual void exit() { Serial.printf("BasePattern::exit\n"); };
void show() {
lastProcessed = millis();
FastLED.show();
}
bool shouldProcess() { return millis() - lastProcessed > timeToProcess; }
unsigned long timeToProcess, lastProcessed;
};
#endif // BASE_PATTERN_H

36
include/cLED.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef cHSV_H
#define cHSV_H
#include <FastLED.h>
#include <cstdint>
class cLED {
public:
int h;
int s;
int v;
uint8_t h8_t;
uint8_t s8_t;
uint8_t v8_t;
cLED() : h(0), s(0), v(0), h8_t(0), s8_t(0), v8_t(0) {};
// HSV as 360,100,100
cLED(int hue, int sat, int val) : h(hue), s(sat), v(val) {
h = (h > 360) ? 255 : h;
s = (s > 100) ? 255 : s;
v = (v > 100) ? 255 : v;
h8_t = 255 * (h / 360.0f);
s8_t = 255 * (s / 100.0f);
v8_t = 255 * (v / 100.0f);
};
CHSV asHSV() {
h8_t = 255 * (h / 360.0f);
s8_t = 255 * (s / 100.0f);
v8_t = 255 * (v / 100.0f);
return CHSV(h8_t, s8_t, v8_t);
}
};
#endif

8
include/hsv_colours.h Normal file
View File

@@ -0,0 +1,8 @@
#include <FastLED.h>
namespace HSVColor {
CHSV Green = CHSV(120, 2, 2);
CHSV Red = CHSV(0, 2, 20);
CHSV Cyan = CHSV(200, 70, 2);
} // namespace HSVColor

90
include/patterns.h Normal file
View File

@@ -0,0 +1,90 @@
#ifndef PATTERNS_H
#define PATTERNS_H
#include "base_pattern.h"
#include "cLED.h"
class hueCheck : public BasePattern {
public:
hueCheck() { timeToProcess = 200; };
~hueCheck() {};
void init() override { offLEDPos = 0; };
void exit() override {};
void loop();
int offLEDPos;
};
class ISHYGDDT : public BasePattern {
public:
ISHYGDDT() { timeToProcess = 4000; };
~ISHYGDDT() {};
void init();
void exit() override {};
void loop();
const float m_deepBluePerc = 0.5f;
const float m_lightBluePerc = 0.2f;
const float m_brownPerc = 0.1f;
const float m_peachPerc = 0.2f;
};
class RedYellowFade : public BasePattern {
public:
RedYellowFade() { timeToProcess = 100; };
~RedYellowFade() {};
void init();
void exit() override {};
void loop();
cLED yellow;
cLED red;
};
class Peppermint : public BasePattern {
public:
Peppermint() { timeToProcess = 7000; };
~Peppermint() {};
void init();
void exit() override {};
void loop();
cLED white;
cLED red;
};
class Bugs : public BasePattern {
public:
Bugs() { timeToProcess = 120; };
~Bugs() {};
void init();
void exit() override {};
void loop();
};
class HolyNight : public BasePattern {
public:
HolyNight() { timeToProcess = 10; };
~HolyNight() {};
void init();
void exit() override {};
void loop();
int breathValue = 0;
bool breathIn = true;
};
class Standard : public BasePattern {
public:
Standard() { timeToProcess = 10; };
~Standard() {};
void init();
void exit() override {};
void loop();
};
class DriveThru : public BasePattern {
public:
DriveThru() { timeToProcess = 250; };
~DriveThru() {};
void init();
void exit() override {};
void loop();
};
#endif

17
include/state_machine.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef STATE_MACHINE_H
#define STATE_MACHINE_H
#include "base_pattern.h"
class StateMachine {
public:
StateMachine();
void changeState(BasePattern *newState);
void processState();
private:
BasePattern *currentPattern;
};
#endif