From 3266981b44a4cfc9828f737fb0ce790c07cca953 Mon Sep 17 00:00:00 2001 From: babayaga Date: Fri, 23 May 2025 23:39:01 +0200 Subject: [PATCH] refactor 2/2 | temp profiles --- src/App.cpp | 3 +- src/App.h | 8 ++-- src/Component.cpp | 2 - src/Polymech-Base.h | 20 --------- src/SRegister.h | 100 ------------------------------------------ src/SerialMessage.cpp | 39 +++++++--------- src/SerialMessage.h | 6 +-- src/StringUtils.cpp | 8 +++- src/StringUtils.h | 12 +---- src/utils.cpp | 15 ------- src/utils.h | 17 ------- 11 files changed, 33 insertions(+), 197 deletions(-) delete mode 100644 src/Component.cpp delete mode 100644 src/Polymech-Base.h delete mode 100644 src/SRegister.h delete mode 100644 src/utils.cpp delete mode 100644 src/utils.h diff --git a/src/App.cpp b/src/App.cpp index 20eb89f7..cb62e197 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -9,6 +9,7 @@ #include "config.h" static Component *componentsArray[MAX_COMPONENTS]; + App::App() : Component("APP", COMPONENT_KEY_APP, Component::COMPONENT_DEFAULT) { DEBUG_INTERVAL = DEFAULT_DEBUG_INTERVAL; @@ -134,7 +135,7 @@ short App::info() return E_OK; } -Component *App::byId(ushort id) +Component *App::byId(ushort id) { short s = components.size(); for (short i = 0; i < s; i++) diff --git a/src/App.h b/src/App.h index 04c7a607..be25a0d7 100644 --- a/src/App.h +++ b/src/App.h @@ -2,10 +2,10 @@ #define APP_H #include -#include "xtypes.h" -#include "Component.h" -#include "xtimer.h" -#include "Bridge.h" +#include +#include +#include +#include class Bridge; diff --git a/src/Component.cpp b/src/Component.cpp deleted file mode 100644 index f43c4915..00000000 --- a/src/Component.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "./Component.h" -#include "./Bridge.h" diff --git a/src/Polymech-Base.h b/src/Polymech-Base.h deleted file mode 100644 index c044c44c..00000000 --- a/src/Polymech-Base.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _osr_base_h -#define _osr_base_h - -#if defined(ARDUINO) && ARDUINO >= 100 - #include "arduino.h" -#else - #include "WProgram.h" -#endif - -int init_osr_base(); - -#endif - -#include "Component.h" -#include "Addon.h" -#include "App.h" -#include "constants.h" -#include "macros.h" -#include "xtypes.h" - diff --git a/src/SRegister.h b/src/SRegister.h deleted file mode 100644 index 8adf117c..00000000 --- a/src/SRegister.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef SREGISTER_H -#define SREGISTER_H - -#include - -template -class ShiftRegister { -private: - T data; - uint8_t length; - uint8_t position; - int mapping[MAX_LENGTH]; - -public: - ShiftRegister() : data(0), length(0), position(0) { - for (uint8_t i = 0; i < MAX_LENGTH; i++) { - mapping[i] = 0; - } - } - - ShiftRegister(const int (&_mapping)[MAX_LENGTH]) : data(0), length(0), position(0) { - for (uint8_t i = 0; i < MAX_LENGTH; i++) { - mapping[i] = _mapping[i]; - } - } - - uint8_t add(T newData){ - data = (data << 1) | (newData & 1); - length = length == MAX_LENGTH ? MAX_LENGTH : length + 1; - return position; - } - - void map(uint8_t pos, int value) { - mapping[pos] = value; - } - - int val() const { - return mapping[position]; - } - - uint8_t incr() { - position = (position + 1) % MAX_LENGTH; - data = (data << 1) | ((data >> (MAX_LENGTH - 1)) & 1); - return position; - } - - uint8_t decr() { - position = (position == 0) ? MAX_LENGTH - 1 : position - 1; - data = (data >> 1) | ((data & 1) << (MAX_LENGTH - 1)); - return position; - } - - uint8_t pos() const { - return position; - } - - uint8_t reset() { - data = 0; - length = 0; - position = 0; - return position; - } - - uint8_t move(int direction, int steps) { - for (int i = 0; i < steps; i++) { - if (direction > 0) { - incr(); - } else if (direction < 0) { - decr(); - } - } - return position; - } - - bool isEnd() const { - return position == (length - 1) % MAX_LENGTH; - } - - ShiftRegister& operator++() { - incr(); - return *this; - } - - ShiftRegister& operator--() { - decr(); - return *this; - } -}; - - -/* -Write a class, for C++, implementing a shift register -- as template, to specify the type for the storage, eg: int, unsigned int, ... -- implement this methods : incr, decr, position, reset, move(int direction, int steps), isEnd -- let me specify the max. length of the register -- dont use std, at all -- use bit shift operators -- return the current position in all methods, using uint8_t as return type -*/ -#endif \ No newline at end of file diff --git a/src/SerialMessage.cpp b/src/SerialMessage.cpp index f9f7e474..78e61a0d 100644 --- a/src/SerialMessage.cpp +++ b/src/SerialMessage.cpp @@ -1,13 +1,26 @@ #include #include -#include "macros.h" +#include "Bridge.h" + +#include #include #include #include "SerialMessage.h" #include "CommandMessage.h" -#include "bridge.h" + +#ifndef SERIAL_COMMAND_PARSE_INTERVAL +#define SERIAL_COMMAND_PARSE_INTERVAL 50 +#endif + +// #define DEBUG_SERIAL_MESSAGES + +#ifdef DEBUG_SERIAL_MESSAGES +#define _DEBUG_MESSAGE_HANDLING(format, ...) Log.verboseln(format, ##__VA_ARGS__) +#else +#define _DEBUG_MESSAGE_HANDLING(format, ...) +#endif void printStringAsHex(const char *str) { @@ -25,38 +38,16 @@ void printStringAsHex(const char *str) Serial.println(" :: "); } -#ifndef SERIAL_COMMAND_PARSE_INTERVAL -#define SERIAL_COMMAND_PARSE_INTERVAL 50 -#endif - -// #define DEBUG_SERIAL_MESSAGES - -#ifdef DEBUG_SERIAL_MESSAGES -#define _DEBUG_MESSAGE_HANDLING(format, ...) Log.verboseln(format, ##__VA_ARGS__) -#else -#define _DEBUG_MESSAGE_HANDLING(format, ...) -#endif - -// static CommandMessage *_messages[10]; // Removed unused static array short SerialMessage::setup() { - // messages.setStorage(_messages); // Removed - uses deleted static array - // msg = new CommandMessage(0, E_CALLS::EC_NONE, E_MessageFlags::E_MF_NONE); // Removed - msg is now an object member return E_OK; } -// Removed unused parse method implementation -// CommandMessage *SerialMessage::parse(char *string) -// { -// return NULL; -// } - short SerialMessage::debug() { return E_OK; } - String SerialMessage::readStringFromSerial() { String message; diff --git a/src/SerialMessage.h b/src/SerialMessage.h index 6cb7167b..623eda64 100644 --- a/src/SerialMessage.h +++ b/src/SerialMessage.h @@ -5,9 +5,9 @@ #include #include // Add for Stream, String etc. if not implicit -#include "xtypes.h" -#include "Component.h" -#include "CommandMessage.h" +#include +#include +#include #include "config.h" #ifndef SERIAL_RX_BUFFER_SIZE diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 8b0ecfdc..4b21add3 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -73,4 +73,10 @@ E_VALUE_TYPE detectType(cchar* str) { return TYPE_STRING; } return TYPE_UNKNOWN; -} \ No newline at end of file +} + + +void printHex(uint8_t *data, uint8_t length) +{ + +} diff --git a/src/StringUtils.h b/src/StringUtils.h index 8e7dc86c..31911ec5 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -25,22 +25,12 @@ typedef enum E_VALUE_TYPE { // Function to convert a string to a native type template T convertTo(cchar* str); - // Specialization for int template<> int convertTo(cchar* str); - - // Specialization for long int template<> long int convertTo(cchar* str); - -// Specialization for long long int -//template<> long long int convertTo(cchar* str); - - - // Specialization for float template<> float convertTo(cchar* str); - // Specialization for bool template<> bool convertTo(cchar* str); @@ -51,4 +41,6 @@ bool isFloat(cchar* str); E_VALUE_TYPE detectType(cchar* str); +void printHex(uint8_t *data, uint8_t length); + #endif diff --git a/src/utils.cpp b/src/utils.cpp deleted file mode 100644 index 229518e3..00000000 --- a/src/utils.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "utils.h" - -void printHex(uint8_t *data, uint8_t length) -{ - for (int i = 0; i < length; i++) - { - if (data[i] < 0x10) - { - Serial.print("0"); - } - Serial.print(data[i], HEX); - Serial.print(" : "); - } - Serial.println(" "); -} diff --git a/src/utils.h b/src/utils.h deleted file mode 100644 index 9dc1280a..00000000 --- a/src/utils.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H - -#include -#include - -void printHex(uint8_t *data, uint8_t length); -/* -template T normalizeValue(T value, T maximum) { - if (value < 0 || value > maximum) { - return 0; // Or any other appropriate value - } - return value / maximum; -} -*/ - -#endif \ No newline at end of file