From 5e112b954d2108120407c2f301a06a64932ba5c7 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 17 Jan 2024 16:54:25 -0600 Subject: [PATCH] a bunch of misc updates --- .gitignore | 4 +++- RP2040_Deck_Demo.proto | 42 ++++++++++++++++++++++++++++++++++++ RP2040_Deck_Demo.yaml | 49 ++++++++++++++++++++++++++++++++++++++++++ src/ActionId.hpp | 11 ++++++++++ src/Button.hpp | 37 +++++++++++++++++++++++++++++++ src/Config.cpp | 0 src/Config.hpp | 17 +++++++++++++++ src/Page.cpp | 9 ++++++++ src/Page.hpp | 21 ++++++++++++++++++ src/Pixel.hpp | 24 +++++++++++++++++++++ 10 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 RP2040_Deck_Demo.proto create mode 100644 RP2040_Deck_Demo.yaml create mode 100644 src/ActionId.hpp create mode 100644 src/Button.hpp create mode 100644 src/Config.cpp create mode 100644 src/Config.hpp create mode 100644 src/Page.cpp create mode 100644 src/Page.hpp create mode 100644 src/Pixel.hpp diff --git a/.gitignore b/.gitignore index 1bb4614..9650328 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*.code-workspace \ No newline at end of file +*.code-workspace +*.kate-swp +build/* diff --git a/RP2040_Deck_Demo.proto b/RP2040_Deck_Demo.proto new file mode 100644 index 0000000..e5798ef --- /dev/null +++ b/RP2040_Deck_Demo.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +enum WheelAction { + None = 0; + Volume = 1; + MicVolume = 2; +} + +message Pixel { + uint32 red = 1; + uint32 green = 2; + uint32 blue = 3; +} + +message Config { + message Page { + message Button + { + string button_text = 1; + bytes keys = 2; + Pixel led = 3; + optional uint32 goto_page = 4; + optional uint32 action_id = 5; + } + string page_text = 1; + Button button1 = 2; + Button button2 = 3; + Button button3 = 4; + Button button4 = 5; + Button button5 = 6; + Button button6 = 7; + Button button7 = 8; + Button button8 = 9; + Button button9 = 10; + Button button10 = 11; + Button button11 = 12; + Button button12 = 13; + WheelAction wheel_action = 14; + } + repeated Page pages = 1; + optional WheelAction = 2; +} diff --git a/RP2040_Deck_Demo.yaml b/RP2040_Deck_Demo.yaml new file mode 100644 index 0000000..6bc47d3 --- /dev/null +++ b/RP2040_Deck_Demo.yaml @@ -0,0 +1,49 @@ +#important reference: https://www.usb.org/sites/default/files/hut1_4.pdf + +config: + #the + pages: + #main purpose of the name is for internal reference + - name: first_page + #action of rotary encoder + wheel: volume + #text when no key is held + text: FIRST PAGE + keys: + 0: + #mutes the system speaker + #see "System Speaker Mute" under Generic(0x01) + action: Mute + #text that displays while this key is held + #if the key is held, it won't do + text: MUTE + #color of the LED for this key + color: blue + #use a number or string for the key, doesn't matter + "1": + action: + #presses each of these keys in sequence, then releases them all + - ctrl + - alt + - del + text: TASK MANAGER + #specify color in hex + color: '0x01ab45' + #after performing action (or instead if there is no action), change the page + goto: second_page + #presumably most pages define all 12 keys + - name: second_page + wheel: mic_volume + text: + #use an array of strings to separate lines + - SECOND + - PAGE + keys: + 0: + action: + #start a process + exec: ./scripts/do_cool_think.sh + #optional, used to kill (interact?) with process later + name: cool_thing_doer + #possible format for decimal RGB + color: "12,13,14" diff --git a/src/ActionId.hpp b/src/ActionId.hpp new file mode 100644 index 0000000..26eb300 --- /dev/null +++ b/src/ActionId.hpp @@ -0,0 +1,11 @@ +#ifndef H_C91B532FD0D0486EAE4B48A326F9CA8C +#define H_C91B532FD0D0486EAE4B48A326F9CA8C + +#include + +struct ActionId +{ + uint32_t value; +}; + +#endif //H_C91B532FD0D0486EAE4B48A326F9CA8C diff --git a/src/Button.hpp b/src/Button.hpp new file mode 100644 index 0000000..12668a3 --- /dev/null +++ b/src/Button.hpp @@ -0,0 +1,37 @@ +#ifndef H_B4D7EE1A3D57466AA444F3FC912641B9 +#define H_B4D7EE1A3D57466AA444F3FC912641B9 + +#include +#include +#include +#include "Pixel.hpp" +#include "ActionId.hpp" + +class Page; + +class Button +{ + friend class Page; + + //text on screen when holding the button + std::string hold_text; + //series of keycodes pressed in order then all released + std::vector keycodes; + //color of this button + Pixel color; + //is set, make this page active after press + Page *goto_page; + //for custom actions, this tells the host what to do + ActionId action_id; + public: + Button(Button&& other) + { + hold_text = std::move(other.hold_text); + keycodes = std::move(other.keycodes); + color = other.color; + goto_page = other.goto_page; + action_id = other.action_id; + } +}; + +#endif //H_B4D7EE1A3D57466AA444F3FC912641B9 diff --git a/src/Config.cpp b/src/Config.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Config.hpp b/src/Config.hpp new file mode 100644 index 0000000..c6d8f7f --- /dev/null +++ b/src/Config.hpp @@ -0,0 +1,17 @@ +#ifndef H_AE095F749CEA4FC29AC38902BC5FD5D1 +#define H_AE095F749CEA4FC29AC38902BC5FD5D1 + +#include +#include "Page.hpp" + +class Config +{ + std::vector pages; + public: + Page& page(size_t index) + { + return pages[index]; + } +}; + +#endif //H_AE095F749CEA4FC29AC38902BC5FD5D1 diff --git a/src/Page.cpp b/src/Page.cpp new file mode 100644 index 0000000..4e3bdcf --- /dev/null +++ b/src/Page.cpp @@ -0,0 +1,9 @@ +#include "Page.hpp" + +std::array Page::led_rgb; + +void Page::update_leds() +{ + for (int i = 0; i < 12; i++) + led_rgb[i] = buttons[i].color; +} diff --git a/src/Page.hpp b/src/Page.hpp new file mode 100644 index 0000000..f494b70 --- /dev/null +++ b/src/Page.hpp @@ -0,0 +1,21 @@ +#ifndef H_1AAB801F01BA49D0BB2AAB917C307E50 +#define H_1AAB801F01BA49D0BB2AAB917C307E50 + +#include +#include "Button.hpp" + +class Page +{ + static std::array led_rgb; + std::array buttons; + std::string distplay_text; + public: + Page(Page&& other) : buttons(std::move(other.buttons)) { } + void update_leds(); + Button& button(std::size_t index) + { + return buttons[index]; + } +}; + +#endif //H_1AAB801F01BA49D0BB2AAB917C307E50 diff --git a/src/Pixel.hpp b/src/Pixel.hpp new file mode 100644 index 0000000..52dd7d6 --- /dev/null +++ b/src/Pixel.hpp @@ -0,0 +1,24 @@ +#ifndef H_FF2FF9A6BC114C719F44441B6FD238C2 +#define H_FF2FF9A6BC114C719F44441B6FD238C2 + +#include + +struct Pixel +{ + uint32_t value; + //should check for endianness I think + //but there is no fully compliant way to test at compile time + #if defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + uint8_t& green() { return *(reinterpret_cast(value)+0); } + uint8_t& red() { return *(reinterpret_cast(value)+1); } + uint8_t& blue() { return *(reinterpret_cast(value)+2); } + uint8_t& white() { return *(reinterpret_cast(value)+3); } + #else + uint8_t& green() { return *(reinterpret_cast(value)+3); } + uint8_t& red() { return *(reinterpret_cast(value)+2); } + uint8_t& blue() { return *(reinterpret_cast(value)+1); } + uint8_t& white() { return *(reinterpret_cast(value)+0); } + #endif +}; + +#endif //H_FF2FF9A6BC114C719F44441B6FD238C2