diff --git a/README.md b/README.md index 1a03252..9ebbb20 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Here is a list of commands and examples for them: *Command*: `hkey.crt`
*Syntax*: `hkey.crt `
*Example*: `hkey.crt false`
-*Description*: Enables/Disables Continuous Rapid trigger functionality on the specified key(s). +*Description*: Enables/Disables Continuous Rapid Trigger functionality on the specified key(s). *Command*: `hkey.rtus`
*Syntax*: `hkey.rtus `
diff --git a/include/config/components/keys.hpp b/include/config/components/keys.hpp new file mode 100644 index 0000000..41f4de1 --- /dev/null +++ b/include/config/components/keys.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include + +// An enum used to identify the type of key a Key object represents. +enum KeyType +{ + // Key objects of this type have been initialized as neither an HEKey or DigitalKey object. + Base, + + // A Key object that was initialized as an HEKey object. + HallEffect, + + // A Key object that was initialized as a DigitalKey object. + Digital +}; + + +// The base configuration struct for the DigitalKey and HEKey struct, containing the common fields. +struct Key +{ + // Used to identify the type of key that a Key object was initialized as (e.g. HEKey or DigitalKey). + KeyType type = KeyType::Base; + + // The index of the key. This is hardcoded in the default config and is not changed. + // It does not serve a config purpose but is instead for accessing the index from the DigitalKey object. + uint8_t index; + + // The corresponding key sent via HID interface. + char keyChar; + + // Bools whether HID commands are sent on the key. + bool hidEnabled; +}; + +// Configuration for the hall effect keys of the keypad, containing the actuation points, calibration, sensitivities etc. of the key. +struct HEKey : Key +{ + // Initialize with the correct type for identifying the type of key that a Key object was initialized as (e.g. HEKey). + HEKey() { type = KeyType::HallEffect; } + + // Bool whether rapid trigger is enabled or not. + bool rapidTrigger; + + // Bool whether continuous rapid trigger is enabled or not. + bool continuousRapidTrigger; + + // The sensitivity of the rapid trigger algorithm when pressing up. + uint16_t rapidTriggerUpSensitivity; + + // The sensitivity of the rapid trigger algorithm when pressing down. + uint16_t rapidTriggerDownSensitivity; + + // The value below which the key is pressed and rapid trigger is active in rapid trigger mode. + uint16_t lowerHysteresis; + + // The value below which the key is no longer pressed and rapid trigger is no longer active in rapid trigger mode. + uint16_t upperHysteresis; + + // The value read when the keys are in rest position/all the way down. + uint16_t restPosition; + uint16_t downPosition; +}; + +// Configuration for the digital keys of the keypad. +struct DigitalKey : Key +{ + // Initialize with the correct type for identifying the type of key that a Key object was initialized as (e.g. DigitalKey). + DigitalKey() { type = KeyType::Digital; } + + // This struct is empty on purpose. The only purpose it serves is explicitly having + // a type for the digital keys, instead of differentiating between Key and DigitalKey. +}; diff --git a/include/config/components/led.hpp b/include/config/components/led.hpp new file mode 100644 index 0000000..215057a --- /dev/null +++ b/include/config/components/led.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +// Configuration for the LEDs registered on the hardware. +struct Led +{ + // The index of the led. This is hardcoded in the default config and is not changed. + // It does not serve a config purpose but is instead for accessing the index from the Led object. + uint8_t index; + + // The RGB color of the led. + uint32_t rgb; +}; + +// An enum used to identify the type of effect the LEDs have. +enum LedEffectType +{ + // The configured RGB colors are shown at the configured brightness statically. + Static, + + // The configured RGB color is shown with brightness dependant on how far the furthest key is pressed in. + Analog, + + // Last value used to identify the end of the enum. This is necessary to get the amount of elements in the enum. + // e.g. in the serial command, there is a check looking whether the specified value is smaller than this. + MaxValue +}; diff --git a/include/config/configuration.hpp b/include/config/configuration.hpp index 0f94c03..ce9c7e1 100644 --- a/include/config/configuration.hpp +++ b/include/config/configuration.hpp @@ -1,7 +1,20 @@ #pragma once -#include "config/keys/he_key.hpp" -#include "config/keys/digital_key.hpp" +#include "config/components/keys.hpp" +#include "config/components/led.hpp" + +// Configuration for the LEDs, containing the actual LEDs, brightness, effects, ... of the keypad. +struct LedConfiguration +{ + // A list of all LEDs. (rgb, effect, ...) + Led leds[LEDS]; + + // The brightness of the LEDs. (0-100) + uint8_t brightness; + + // The ID of the RGB effect. + LedEffectType effect; +}; // Configuration for the whole firmware, containing the name of the keypad and it's configurations. struct Configuration @@ -18,11 +31,14 @@ struct Configuration // A list of all digital key configurations. (key char, hid state, ...) DigitalKey digitalKeys[DIGITAL_KEYS]; + // The config for the LEDs on the keypad. + LedConfiguration leds; + // Returns the version constant of the latest Configuration layout. static uint32_t getVersion() { // Version of the configuration in the format YYMMDDhhmm (e.g. 2301030040 for 12:44am on the 3rd january 2023) - int64_t version = 2304281204; + int64_t version = 2306182346; return version; } diff --git a/include/config/configuration_controller.hpp b/include/config/configuration_controller.hpp index 81648ac..34ac5ad 100644 --- a/include/config/configuration_controller.hpp +++ b/include/config/configuration_controller.hpp @@ -24,10 +24,17 @@ inline class ConfigurationController // structs that might get modified on a firmware update and have to be reset back to their default values then later on. Configuration getDefaultConfig() { - Configuration config = { + Configuration config = + { .name = {'m', 'i', 'n', 'i', 'p', 'a', 'd'}, .heKeys = {}, - .digitalKeys = {} + .digitalKeys = {}, + .leds = + { + .leds = {}, + .brightness = 50, + .effect = LedEffectType::Static + } }; // Populate the hall effect keys array with the correct amount of hall effect keys. @@ -69,6 +76,17 @@ inline class ConfigurationController config.digitalKeys[i].hidEnabled = false; } +#pragma GCC diagnostic ignored "-Wtype-limits" + for (uint8_t i = 0; i < LEDS; i++) +#pragma GCC diagnostic pop + { + config.leds.leds[i] = Led(); + config.leds.leds[i].index = i; + + // Set the default RGB for the leds to white (FFFFFF). + config.leds.leds[i].rgb = 0xFFFFFF; + } + return config; }; diff --git a/include/config/keys/digital_key.hpp b/include/config/keys/digital_key.hpp deleted file mode 100644 index b722cb8..0000000 --- a/include/config/keys/digital_key.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include "config/keys/key.hpp" - -// Configuration for the digital keys of the keypad. -struct DigitalKey : Key -{ - // Initialize with the correct type for identifying the type of key that a Key object was initialized as (e.g. DigitalKey). - DigitalKey() { type = KeyType::Digital; } - - // This struct is empty on purpose. The only purpose it serves is explicitly having - // a type for the digital keys, instead of differentiating between Key and DigitalKey. -}; diff --git a/include/config/keys/he_key.hpp b/include/config/keys/he_key.hpp deleted file mode 100644 index c4a91b3..0000000 --- a/include/config/keys/he_key.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include "config/keys/key.hpp" -#include "config/keys/key_type.hpp" - -// Configuration for the hall effect keys of the keypad, containing the actuation points, calibration, sensitivities etc. of the key. -struct HEKey : Key -{ - // Initialize with the correct type for identifying the type of key that a Key object was initialized as (e.g. HEKey). - HEKey() { type = KeyType::HallEffect; } - - // Bool whether rapid trigger is enabled or not. - bool rapidTrigger; - - // Bool whether continuous rapid trigger is enabled or not. - bool continuousRapidTrigger; - - // The sensitivity of the rapid trigger algorithm when pressing up. - uint16_t rapidTriggerUpSensitivity; - - // The sensitivity of the rapid trigger algorithm when pressing down. - uint16_t rapidTriggerDownSensitivity; - - // The value below which the key is pressed and rapid trigger is active in rapid trigger mode. - uint16_t lowerHysteresis; - - // The value below which the key is no longer pressed and rapid trigger is no longer active in rapid trigger mode. - uint16_t upperHysteresis; - - // The value read when the keys are in rest position/all the way down. - uint16_t restPosition; - uint16_t downPosition; -}; diff --git a/include/config/keys/key.hpp b/include/config/keys/key.hpp deleted file mode 100644 index 9b651d4..0000000 --- a/include/config/keys/key.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include "config/keys/key_type.hpp" - -// The base configuration struct for the DigitalKey and HEKey struct, containing the common fields. -struct Key -{ - // Used to identify the type of key that a Key object was initialized as (e.g. HEKey or DigitalKey). - KeyType type = KeyType::Base; - - // The index of the key. This is hardcoded in the default config and is not changed. - // It does not serve a config purpose but is instead for accessing the index from the DigitalKey object. - uint8_t index; - - // The corresponding key sent via HID interface. - char keyChar; - - // Bools whether HID commands are sent on the key. - bool hidEnabled; -}; diff --git a/include/config/keys/key_type.hpp b/include/config/keys/key_type.hpp deleted file mode 100644 index 8d2958c..0000000 --- a/include/config/keys/key_type.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -// An enum used to identify the type of key a Key object represents. -enum KeyType -{ - // Key objects of this type have been initialized as neither an HEKey or DigitalKey object. - Base, - - // A Key object that was initialized as an HEKey object. - HallEffect, - - // A Key object that was initialized as a DigitalKey object. - Digital -}; diff --git a/include/definitions.hpp b/include/definitions.hpp index 5758952..1df85fd 100644 --- a/include/definitions.hpp +++ b/include/definitions.hpp @@ -60,6 +60,12 @@ // NOTE: This way, the amount of keys is limited to 26 since the 27th key overlaps with the first analog port, 26. #define DIGITAL_PIN(index) 0 + DIGITAL_KEYS - index - 1 +// The pin the NeoPixel LEDs are chained onto. +#define LED_PIN 20 + +// The type of LEDs for the Adafruit NeoPixel library. +#define LED_TYPE NEO_GRB + NEO_KHZ800 + // Add a compiler error if the firmware is being tried to built with more than the supported 4 keys. // (only 4 ADC pins available) #if HE_KEYS > 4 @@ -71,8 +77,3 @@ #if DIGITAL_KEYS > 26 #error As of right now, the firmware only supports up to 26 digital keys. #endif - -// If the debug flag is not set via compiler parameters, default it to 0 since it's required for if statements. -#ifndef DEV -#define DEV 0 -#endif diff --git a/include/handlers/keypad_handler.hpp b/include/handlers/keypad_handler.hpp index a24bf88..d38b369 100644 --- a/include/handlers/keypad_handler.hpp +++ b/include/handlers/keypad_handler.hpp @@ -22,13 +22,12 @@ inline class KeypadHandler digitalKeyStates[i] = DigitalKeyState(); } - void handle(); + void loop(); bool outputMode; HEKeyState heKeyStates[HE_KEYS]; DigitalKeyState digitalKeyStates[DIGITAL_KEYS]; private: - void checkHEKey(const HEKey &key, uint16_t value); void checkDigitalKey(const DigitalKey &key, bool pressed); void pressKey(const Key &key); diff --git a/include/handlers/led_handler.hpp b/include/handlers/led_handler.hpp new file mode 100644 index 0000000..43bc346 --- /dev/null +++ b/include/handlers/led_handler.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include "definitions.hpp" + +inline class LEDHandler +{ +public: + void setup(); + void loop(); + +private: + void effect_static(); + void effect_analog(); + void setBrightness(uint8_t value); + + Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LEDS, LED_PIN, LED_TYPE); + +} LEDHandler; diff --git a/include/handlers/serial_handler.hpp b/include/handlers/serial_handler.hpp index afb5326..400b900 100644 --- a/include/handlers/serial_handler.hpp +++ b/include/handlers/serial_handler.hpp @@ -25,4 +25,7 @@ inline class SerialHandler void hkey_down(HEKey &key, uint16_t value); void key_char(Key &key, uint8_t keyChar); void key_hid(Key &key, bool state); + void leds_btns(uint8_t value); + void leds_efct(uint8_t value); + void led_rgb(Led &led, char hex[7]); } SerialHandler; diff --git a/include/helpers/color_helper.hpp b/include/helpers/color_helper.hpp new file mode 100644 index 0000000..95e6263 --- /dev/null +++ b/include/helpers/color_helper.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace ColorHelper +{ + uint32_t hexToDec(char hex[7]); + void decToHex(uint32_t value, char hex[7]); +} diff --git a/platformio.ini b/platformio.ini index 0bb786e..e7b57e9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,21 +17,25 @@ board = pico framework = arduino check_tool = clangtidy board_build.core = earlephilhower -board_build.arduino.earlephilhower.usb_manufacturer=Project Minipad +board_build.arduino.earlephilhower.usb_manufacturer = Project Minipad build_flags = -DUSBD_VID=0x0727 -DUSBD_PID=0x0727 -DHID_POLLING_RATE=1000 -DIGNORE_MULTI_ENDPOINT_PID_MUTATION -Wall -Wextra [env:minipad-2k-dev] -build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -DDEV=1 -board_build.arduino.earlephilhower.usb_product=minipad-2k-dev +build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -DLEDS=6 -DDEV=1 +board_build.arduino.earlephilhower.usb_product = minipad-2k-dev +lib_deps = adafruit/Adafruit NeoPixel@^1.11.0 [env:minipad-3k-dev] -build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -DDEV=1 -board_build.arduino.earlephilhower.usb_product=minipad-3k-dev +build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -DLEDS=0 -DDEV=1 +board_build.arduino.earlephilhower.usb_product = minipad-3k-dev +lib_deps = adafruit/Adafruit NeoPixel@^1.11.0 [env:minipad-2k-prod] -build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -board_build.arduino.earlephilhower.usb_product=minipad-2k +build_flags = ${env.build_flags} -DHE_KEYS=2 -DDIGITAL_KEYS=0 -DLEDS=0 -DDEV=0 +board_build.arduino.earlephilhower.usb_product = minipad-2k +lib_deps = adafruit/Adafruit NeoPixel@^1.11.0 [env:minipad-3k-prod] -build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -board_build.arduino.earlephilhower.usb_product=minipad-3k +build_flags = ${env.build_flags} -DHE_KEYS=3 -DDIGITAL_KEYS=0 -DLEDS=0 -DDEV=0 +board_build.arduino.earlephilhower.usb_product = minipad-3k +lib_deps = adafruit/Adafruit NeoPixel@^1.11.0 diff --git a/src/handlers/keypad_handler.cpp b/src/handlers/keypad_handler.cpp index 8862b84..5e0c2d2 100644 --- a/src/handlers/keypad_handler.cpp +++ b/src/handlers/keypad_handler.cpp @@ -1,6 +1,5 @@ #include #include -#include "config/keys/key_type.hpp" #include "handlers/keypad_handler.hpp" #include "handlers/serial_handler.hpp" #include "helpers/string_helper.hpp" @@ -56,7 +55,7 @@ const uint16_t ANALOG_RESOLUTION_SQUARED = pow(2, ANALOG_RESOLUTION); Step 4: Depending on whether the key is pressed or not, remember the lowest/highest peak achieved */ -void KeypadHandler::handle() +void KeypadHandler::loop() { // Go through all hall effect keys and run the checks. for (const HEKey &key : ConfigController.config.heKeys) diff --git a/src/handlers/led_handler.cpp b/src/handlers/led_handler.cpp new file mode 100644 index 0000000..7c9c0f5 --- /dev/null +++ b/src/handlers/led_handler.cpp @@ -0,0 +1,62 @@ +#include "handlers/led_handler.hpp" +#include "handlers/keypad_handler.hpp" +#include "config/configuration_controller.hpp" +#include "definitions.hpp" + +void LEDHandler::setup() +{ + // Initialize the Adafruit_NeoPixel instance. + pixels.begin(); +} + +void LEDHandler::loop() +{ + // Run the effect configured in the config. + switch (ConfigController.config.leds.effect) + { + case LedEffectType::Static: + effect_static(); + break; + case LedEffectType::Analog: + effect_analog(); + break; + } + + // Update the pixels. + pixels.show(); +} + +#pragma region Effects + +void LEDHandler::effect_static() +{ + // Go through all LEDs and set the configured color. + for (int i = 0; i < LEDS; i++) + pixels.setPixelColor(i, ConfigController.config.leds.leds[i].rgb); + + // Set the brightness of the LEDs to full brightness. This is scaled with the configured brightness afterwards. + setBrightness(100); +} + +void LEDHandler::effect_analog() +{ + // Go through all LEDs and set the configured color. + for (int i = 0; i < LEDS; i++) + pixels.setPixelColor(i, ConfigController.config.leds.leds[i].rgb); + + // Get the mapped value of the furthest down-pressed button. + uint16_t minimum = TRAVEL_DISTANCE_IN_0_01MM; + for (int i = 0; i < HE_KEYS; i++) + minimum = min(minimum, KeypadHandler.heKeyStates[i].lastMappedValue); + + // Set the brightness on the LEDs to the minimum mapped to a range of 0-100. + setBrightness((TRAVEL_DISTANCE_IN_0_01MM - minimum) * 100 / TRAVEL_DISTANCE_IN_0_01MM); +} + +#pragma endregion + +void LEDHandler::setBrightness(uint8_t value) +{ + // Set the brightness to the specified value scaled with the value in the config. + pixels.setBrightness(value * ConfigController.config.leds.brightness / 100); +} diff --git a/src/handlers/serial_handler.cpp b/src/handlers/serial_handler.cpp index e9b9315..bf1377e 100644 --- a/src/handlers/serial_handler.cpp +++ b/src/handlers/serial_handler.cpp @@ -2,6 +2,7 @@ #include "handlers/serial_handler.hpp" #include "handlers/keypad_handler.hpp" #include "helpers/string_helper.hpp" +#include "helpers/color_helper.hpp" #include "definitions.hpp" extern "C" { @@ -11,9 +12,10 @@ extern "C" // Define a handy macro for printing with a newline character at the end. #define print(fmt, ...) Serial.printf(fmt "\n", __VA_ARGS__) -// Define two more handy macros for interpreting the serial input. +// Define three more handy macros for interpreting the serial input. #define isEqual(str1, str2) strcmp(str1, str2) == 0 #define isTrue(str) isEqual(str, "1") || isEqual(str, "true") +#define startsWith(str1, str2) strstr(str1, str2) == str1 void SerialHandler::handleSerialInput(String *inputStr) { @@ -56,7 +58,7 @@ void SerialHandler::handleSerialInput(String *inputStr) #endif // Handle hall effect key specific commands by checking if the command starts with "hkey". - if (strstr(command, "hkey") == command) + if (startsWith(command, "hkey")) { // Split the command into the key string and the setting name. char keyStr[1024]; @@ -111,7 +113,7 @@ void SerialHandler::handleSerialInput(String *inputStr) } // Handle digital key specific commands by checking if the command starts with "dkey". - if (strstr(command, "dkey") == command) + else if (startsWith(command, "dkey")) { // Split the command into the key string and the setting name. char keyStr[1024]; @@ -150,6 +152,59 @@ void SerialHandler::handleSerialInput(String *inputStr) key_hid(key, isTrue(arg0)); } } + // Handle global led-related commands by checking if the command starts with "leds.". + // Checking for the dot at the end ensures that the identifier is "leds". + else if (startsWith(command, "leds.")) + { + // Get the setting name from the command. + char setting[1024]; + StringHelper::getArgumentAt(command, '.', 1, setting); + + // Handle the settings. + if (isEqual(setting, "btns")) + leds_btns(atoi(arg0)); + else if (isEqual(setting, "efct")) + leds_efct(atoi(arg0)); + } + + // Handle led-specific commands by checking if the command starts with "led". + else if (startsWith(command, "led")) + { + // Split the command into the led string and the setting name. + char ledStr[1024]; + char setting[1024]; + StringHelper::getArgumentAt(command, '.', 0, ledStr); + StringHelper::getArgumentAt(command, '.', 1, setting); + + // By default, apply this command to all leds. + Led *leds = ConfigController.config.leds.leds; + + // If an index is specified ("ledX"), replace that leds array with just that led. + // This is checked by looking whether the key string has > 3 characters. + if (strlen(ledStr) > 3) + { + // Get the index and check if it's in the valid range. + uint8_t ledIndex = atoi(ledStr + 3) - 1; +#pragma GCC diagnostic ignored "-Wtype-limits" + if (ledIndex >= LEDS) +#pragma GCC diagnostic pop + return; + + // Replace the array with that single digital key. + leds = &ConfigController.config.leds.leds[ledIndex]; + } + + // Apply the command to all targetted leds. + for (uint8_t i = 0; i < (strlen(ledStr) > 3 ? 1 : LEDS); i++) + { + // Get the led from the pointer array. + Led &led = leds[i]; + + // Handle the settings. + if (isEqual(setting, "rgb")) + led_rgb(led, arg0); + } + } } void SerialHandler::printHEKeyOutput(const HEKey &key) @@ -185,7 +240,6 @@ void SerialHandler::get() // Output all hall effect key-specific settings. for (const HEKey &key : ConfigController.config.heKeys) { - // Format the base for all lines being written. print("GET hkey%d.rt=%d", key.index + 1, key.rapidTrigger); print("GET hkey%d.crt=%d", key.index + 1, key.continuousRapidTrigger); print("GET hkey%d.rtus=%d", key.index + 1, key.rapidTriggerUpSensitivity); @@ -205,6 +259,23 @@ void SerialHandler::get() print("GET dkey%d.hid=%d", key.index + 1, key.hidEnabled); } + // Output all global led-related settings if at least one LED is registered. + if (LEDS > 0) + { + print("GET leds.btns=%d", ConfigController.config.leds.brightness); + print("GET leds.efct=%d", ConfigController.config.leds.effect); + } + + // Output all led-specific settings. + for (const Led &led : ConfigController.config.leds.leds) + { + // Parse the RGB uint16_t into a hex string. + char hex[7]; + ColorHelper::decToHex(led.rgb, hex); + + print("GET led%d.rgb=0x%s", led.index + 1, hex); + } + // Print this line to signalize the end of printing the settings to the listener. Serial.println("GET END"); } @@ -309,3 +380,25 @@ void SerialHandler::key_hid(Key &key, bool state) // Set the hid config value of the specified key to the specified state. key.hidEnabled = state; } + +void SerialHandler::leds_btns(uint8_t value) +{ + // Set the brightness of the LEDs to the specified value. + ConfigController.config.leds.brightness = value; +} + +void SerialHandler::leds_efct(uint8_t value) +{ + // If an out-of-bounds value was specified, default to static (0). + if (value > LedEffectType::MaxValue) + value = 0; + + // Set the RGB effect to the specified value. + ConfigController.config.leds.effect = (LedEffectType)value; +} + +void SerialHandler::led_rgb(Led &led, char rgb[7]) +{ + // Set the rgb config value of the specified led to the specified hex value. + led.rgb = ColorHelper::hexToDec(rgb); +} diff --git a/src/helpers/color_helper.cpp b/src/helpers/color_helper.cpp new file mode 100644 index 0000000..d59bab4 --- /dev/null +++ b/src/helpers/color_helper.cpp @@ -0,0 +1,15 @@ +#include +#include "helpers/color_helper.hpp" + +uint32_t ColorHelper::hexToDec(char hex[7]) +{ + // Parse the hex string into an RGB uint32_t. + uint32_t result = strtoul(hex, NULL, 16); + return result; +} + +void ColorHelper::decToHex(uint32_t value, char hex[7]) +{ + // Parse the RGB uint32_t into a hex string. + sprintf(hex, "%08X", value); +} diff --git a/src/main.cpp b/src/main.cpp index cfdf726..ce20686 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,9 @@ #include "config/configuration_controller.hpp" #include "handlers/serial_handler.hpp" #include "handlers/keypad_handler.hpp" +#include "handlers/led_handler.hpp" + +#pragma region Core 0 (Keypad) void setup() { @@ -26,9 +29,27 @@ void setup() void loop() { // Run the keypad handler checks to handle the actual keypad functionality. - KeypadHandler.handle(); + KeypadHandler.loop(); +} + +#pragma endregion + +#pragma region Core 1 (RGB) + +void setup1() +{ + // Pass the setup to the led handler that needs to be setup. + LEDHandler.setup(); } +void loop1() +{ + // Run the led handler checks to handle the RGB logic. + LEDHandler.loop(); +} + +#pragma endregion + void serialEvent() { // Handle incoming serial data.