diff --git a/.gitignore b/.gitignore index 9650328..a62f49a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *.code-workspace *.kate-swp build/* +#these are the generated source files for the embedded protobuf +src/protogen/* +#python virtual environment +*/venv/* diff --git a/FreeRTOS b/FreeRTOS index 154dee1..b4fd629 160000 --- a/FreeRTOS +++ b/FreeRTOS @@ -1 +1 @@ -Subproject commit 154dee1c86195d88c49ba5c58c8725c16541cc16 +Subproject commit b4fd629652e936e8c781287a5fed7e90c41c8dfe diff --git a/proto/Config.proto b/proto/ProtoConfig.proto similarity index 95% rename from proto/Config.proto rename to proto/ProtoConfig.proto index de185da..c4a47fc 100644 --- a/proto/Config.proto +++ b/proto/ProtoConfig.proto @@ -1,4 +1,5 @@ syntax = "proto3"; +package Messaging; enum WheelAction { None = 0; @@ -38,5 +39,4 @@ message Config { WheelAction wheel_action = 14; } repeated Page pages = 1; - optional WheelAction wheel_action = 2; } diff --git a/src/ActionId.hpp b/src/ActionId.hpp index 26eb300..afeb85c 100644 --- a/src/ActionId.hpp +++ b/src/ActionId.hpp @@ -3,9 +3,12 @@ #include +namespace Configuration +{ struct ActionId { uint32_t value; }; +} #endif //H_C91B532FD0D0486EAE4B48A326F9CA8C diff --git a/src/Button.hpp b/src/Button.hpp index 12668a3..6fc1b3c 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -6,7 +6,10 @@ #include #include "Pixel.hpp" #include "ActionId.hpp" +#include "ProtoConfig.h" +namespace Configuration +{ class Page; class Button @@ -24,7 +27,28 @@ class Button //for custom actions, this tells the host what to do ActionId action_id; public: - Button(Button&& other) + inline Button() + { + + } + inline Button(const Button& other) + { + hold_text = other.hold_text; + keycodes = other.keycodes; + color = other.color; + goto_page = other.goto_page; + action_id = other.action_id; + } + inline Button& operator=(const Button& other) + { + hold_text = other.hold_text; + keycodes = other.keycodes; + color = other.color; + goto_page = other.goto_page; + action_id = other.action_id; + return *this; + } + inline Button(Button&& other) { hold_text = std::move(other.hold_text); keycodes = std::move(other.keycodes); @@ -32,6 +56,100 @@ class Button goto_page = other.goto_page; action_id = other.action_id; } + template< + uint32_t Config_pages_REP_LENGTH, + uint32_t Config_pages_Page_page_text_LENGTH, + uint32_t Config_pages_Page_button1_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button1_Button_keys_LENGTH, + uint32_t Config_pages_Page_button2_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button2_Button_keys_LENGTH, + uint32_t Config_pages_Page_button3_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button3_Button_keys_LENGTH, + uint32_t Config_pages_Page_button4_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button4_Button_keys_LENGTH, + uint32_t Config_pages_Page_button5_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button5_Button_keys_LENGTH, + uint32_t Config_pages_Page_button6_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button6_Button_keys_LENGTH, + uint32_t Config_pages_Page_button7_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button7_Button_keys_LENGTH, + uint32_t Config_pages_Page_button8_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button8_Button_keys_LENGTH, + uint32_t Config_pages_Page_button9_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button9_Button_keys_LENGTH, + uint32_t Config_pages_Page_button10_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button10_Button_keys_LENGTH, + uint32_t Config_pages_Page_button11_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button11_Button_keys_LENGTH, + uint32_t Config_pages_Page_button12_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button12_Button_keys_LENGTH> + void load(const typename Messaging::Config::Page + ::Button + &ser) + { + hold_text.assign(ser.button_text()); + for (int i = 0; i++; i < ser.get_keys().get_length()) + keycodes.emplace_back(ser.get_keys()[i]); + { + auto c = ser.get_led(); + color.red() = static_cast(c.get_red()); + color.green() = static_cast(c.get_green()); + color.blue() = static_cast(c.get_blue()); + } + //goto_page = ser.get_goto_page(); + action_id.value = ser.get_action_id(); + } }; +} #endif //H_B4D7EE1A3D57466AA444F3FC912641B9 diff --git a/src/Config.cpp b/src/Config.cpp index e69de29..ad53bd8 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -0,0 +1,6 @@ +#include "Config.hpp" + +namespace Configuration +{ + +} diff --git a/src/Config.hpp b/src/Config.hpp index c6d8f7f..25f5333 100644 --- a/src/Config.hpp +++ b/src/Config.hpp @@ -3,7 +3,10 @@ #include #include "Page.hpp" +#include "ProtoConfig.h" +namespace Configuration +{ class Config { std::vector pages; @@ -12,6 +15,100 @@ class Config { return pages[index]; } + void append(const Page& new_page) + { + pages.push_back(new_page); + } + template< + uint32_t Config_pages_REP_LENGTH, + uint32_t Config_pages_Page_page_text_LENGTH, + uint32_t Config_pages_Page_button1_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button1_Button_keys_LENGTH, + uint32_t Config_pages_Page_button2_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button2_Button_keys_LENGTH, + uint32_t Config_pages_Page_button3_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button3_Button_keys_LENGTH, + uint32_t Config_pages_Page_button4_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button4_Button_keys_LENGTH, + uint32_t Config_pages_Page_button5_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button5_Button_keys_LENGTH, + uint32_t Config_pages_Page_button6_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button6_Button_keys_LENGTH, + uint32_t Config_pages_Page_button7_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button7_Button_keys_LENGTH, + uint32_t Config_pages_Page_button8_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button8_Button_keys_LENGTH, + uint32_t Config_pages_Page_button9_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button9_Button_keys_LENGTH, + uint32_t Config_pages_Page_button10_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button10_Button_keys_LENGTH, + uint32_t Config_pages_Page_button11_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button11_Button_keys_LENGTH, + uint32_t Config_pages_Page_button12_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button12_Button_keys_LENGTH> + void load(const Messaging::Config< + Config_pages_REP_LENGTH, + Config_pages_Page_page_text_LENGTH, + Config_pages_Page_button1_Button_button_text_LENGTH, + Config_pages_Page_button1_Button_keys_LENGTH, + Config_pages_Page_button2_Button_button_text_LENGTH, + Config_pages_Page_button2_Button_keys_LENGTH, + Config_pages_Page_button3_Button_button_text_LENGTH, + Config_pages_Page_button3_Button_keys_LENGTH, + Config_pages_Page_button4_Button_button_text_LENGTH, + Config_pages_Page_button4_Button_keys_LENGTH, + Config_pages_Page_button5_Button_button_text_LENGTH, + Config_pages_Page_button5_Button_keys_LENGTH, + Config_pages_Page_button6_Button_button_text_LENGTH, + Config_pages_Page_button6_Button_keys_LENGTH, + Config_pages_Page_button7_Button_button_text_LENGTH, + Config_pages_Page_button7_Button_keys_LENGTH, + Config_pages_Page_button8_Button_button_text_LENGTH, + Config_pages_Page_button8_Button_keys_LENGTH, + Config_pages_Page_button9_Button_button_text_LENGTH, + Config_pages_Page_button9_Button_keys_LENGTH, + Config_pages_Page_button10_Button_button_text_LENGTH, + Config_pages_Page_button10_Button_keys_LENGTH, + Config_pages_Page_button11_Button_button_text_LENGTH, + Config_pages_Page_button11_Button_keys_LENGTH, + Config_pages_Page_button12_Button_button_text_LENGTH, + Config_pages_Page_button12_Button_keys_LENGTH> &ser) + { + auto _pages = ser.get_pages(); + for (uint32_t i = 0; i++; i < _pages.get_length()) + { + pages.emplace_back(Page()); + pages.back().load< + Config_pages_REP_LENGTH, + Config_pages_Page_page_text_LENGTH, + Config_pages_Page_button1_Button_button_text_LENGTH, + Config_pages_Page_button1_Button_keys_LENGTH, + Config_pages_Page_button2_Button_button_text_LENGTH, + Config_pages_Page_button2_Button_keys_LENGTH, + Config_pages_Page_button3_Button_button_text_LENGTH, + Config_pages_Page_button3_Button_keys_LENGTH, + Config_pages_Page_button4_Button_button_text_LENGTH, + Config_pages_Page_button4_Button_keys_LENGTH, + Config_pages_Page_button5_Button_button_text_LENGTH, + Config_pages_Page_button5_Button_keys_LENGTH, + Config_pages_Page_button6_Button_button_text_LENGTH, + Config_pages_Page_button6_Button_keys_LENGTH, + Config_pages_Page_button7_Button_button_text_LENGTH, + Config_pages_Page_button7_Button_keys_LENGTH, + Config_pages_Page_button8_Button_button_text_LENGTH, + Config_pages_Page_button8_Button_keys_LENGTH, + Config_pages_Page_button9_Button_button_text_LENGTH, + Config_pages_Page_button9_Button_keys_LENGTH, + Config_pages_Page_button10_Button_button_text_LENGTH, + Config_pages_Page_button10_Button_keys_LENGTH, + Config_pages_Page_button11_Button_button_text_LENGTH, + Config_pages_Page_button11_Button_keys_LENGTH, + Config_pages_Page_button12_Button_button_text_LENGTH, + Config_pages_Page_button12_Button_keys_LENGTH> + (_pages.get_const(i)); + } + } }; +} #endif //H_AE095F749CEA4FC29AC38902BC5FD5D1 diff --git a/src/Page.cpp b/src/Page.cpp index 4e3bdcf..ed4640f 100644 --- a/src/Page.cpp +++ b/src/Page.cpp @@ -1,5 +1,7 @@ #include "Page.hpp" +namespace Configuration +{ std::array Page::led_rgb; void Page::update_leds() @@ -7,3 +9,4 @@ 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 index f494b70..f7c8a52 100644 --- a/src/Page.hpp +++ b/src/Page.hpp @@ -3,19 +3,136 @@ #include #include "Button.hpp" +#include "ProtoConfig.h" +namespace Configuration +{ class Page { static std::array led_rgb; std::array buttons; - std::string distplay_text; + std::string display_text; public: - Page(Page&& other) : buttons(std::move(other.buttons)) { } + inline Page() { } + inline Page(const Page& other) + { + buttons = other.buttons; + display_text = other.display_text; + } + inline Page(Page&& other) : buttons(std::move(other.buttons)) { } + template< + uint32_t Config_pages_REP_LENGTH, + uint32_t Config_pages_Page_page_text_LENGTH, + uint32_t Config_pages_Page_button1_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button1_Button_keys_LENGTH, + uint32_t Config_pages_Page_button2_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button2_Button_keys_LENGTH, + uint32_t Config_pages_Page_button3_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button3_Button_keys_LENGTH, + uint32_t Config_pages_Page_button4_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button4_Button_keys_LENGTH, + uint32_t Config_pages_Page_button5_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button5_Button_keys_LENGTH, + uint32_t Config_pages_Page_button6_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button6_Button_keys_LENGTH, + uint32_t Config_pages_Page_button7_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button7_Button_keys_LENGTH, + uint32_t Config_pages_Page_button8_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button8_Button_keys_LENGTH, + uint32_t Config_pages_Page_button9_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button9_Button_keys_LENGTH, + uint32_t Config_pages_Page_button10_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button10_Button_keys_LENGTH, + uint32_t Config_pages_Page_button11_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button11_Button_keys_LENGTH, + uint32_t Config_pages_Page_button12_Button_button_text_LENGTH, + uint32_t Config_pages_Page_button12_Button_keys_LENGTH> + void load(const typename Messaging::Config::Page + &ser) + { + buttons[0].load + (ser.get_button1()); + } 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 index 52dd7d6..bcaf21e 100644 --- a/src/Pixel.hpp +++ b/src/Pixel.hpp @@ -3,6 +3,8 @@ #include +namespace Configuration +{ struct Pixel { uint32_t value; @@ -20,5 +22,6 @@ struct Pixel uint8_t& white() { return *(reinterpret_cast(value)+0); } #endif }; +} #endif //H_FF2FF9A6BC114C719F44441B6FD238C2 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c5d8248 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,43 @@ +#include "Config.hpp" +#include "Page.hpp" +#include "ProtoConfig.h" +#include "ReadBufferInterface.h" +#include "ReadBufferFixedSize.h" +//#include +#include "pico/stdlib.h" +#include + +constexpr uint32_t MAX_KEY_PRESSES = 5; +constexpr uint32_t MAX_STR_LENGTH = 50; +constexpr uint32_t MAX_PAGES = 12; +constexpr uint32_t BUFFER_SIZE = 1024; + +using ConfigDeser = Messaging::Config; + +Configuration::Config config; +Configuration::Page *active_page; +char config_buffer[1024]; + +extern "C" +int main() +{ + stdio_init_all(); + { + EmbeddedProto::ReadBufferFixedSize buffer; + ConfigDeser config_message; + if (!gets(reinterpret_cast(buffer.get_data()))) + { + //read failed + } + buffer.set_bytes_written(std::strlen(reinterpret_cast(buffer.get_data()))); + config_message.deserialize(buffer); + config.load(config_message); + } + while (true); +}