refactor 2/2 | temp profiles

This commit is contained in:
lovebird 2025-05-23 23:39:01 +02:00
parent daf23e872a
commit 3266981b44
11 changed files with 33 additions and 197 deletions

View File

@ -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++)

View File

@ -2,10 +2,10 @@
#define APP_H
#include <Vector.h>
#include "xtypes.h"
#include "Component.h"
#include "xtimer.h"
#include "Bridge.h"
#include <xtypes.h>
#include <Component.h>
#include <Bridge.h>
#include <xtimer.h>
class Bridge;

View File

@ -1,2 +0,0 @@
#include "./Component.h"
#include "./Bridge.h"

View File

@ -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"

View File

@ -1,100 +0,0 @@
#ifndef SREGISTER_H
#define SREGISTER_H
#include <stdint.h>
template <typename T, uint8_t MAX_LENGTH>
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

View File

@ -1,13 +1,26 @@
#include <Vector.h>
#include <ArduinoLog.h>
#include "macros.h"
#include "Bridge.h"
#include <macros.h>
#include <constants.h>
#include <xtypes.h>
#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;

View File

@ -5,9 +5,9 @@
#include <ArduinoLog.h>
#include <Arduino.h> // Add for Stream, String etc. if not implicit
#include "xtypes.h"
#include "Component.h"
#include "CommandMessage.h"
#include <xtypes.h>
#include <Component.h>
#include <CommandMessage.h>
#include "config.h"
#ifndef SERIAL_RX_BUFFER_SIZE

View File

@ -73,4 +73,10 @@ E_VALUE_TYPE detectType(cchar* str) {
return TYPE_STRING;
}
return TYPE_UNKNOWN;
}
}
void printHex(uint8_t *data, uint8_t length)
{
}

View File

@ -25,22 +25,12 @@ typedef enum E_VALUE_TYPE {
// Function to convert a string to a native type
template<typename T> T convertTo(cchar* str);
// Specialization for int
template<> int convertTo<int>(cchar* str);
// Specialization for long int
template<> long int convertTo<long int>(cchar* str);
// Specialization for long long int
//template<> long long int convertTo<long long int>(cchar* str);
// Specialization for float
template<> float convertTo<float>(cchar* str);
// Specialization for bool
template<> bool convertTo<bool>(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

View File

@ -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(" ");
}

View File

@ -1,17 +0,0 @@
#ifndef UTILS_H
#define UTILS_H
#include <Arduino.h>
#include <stdint.h>
void printHex(uint8_t *data, uint8_t length);
/*
template <typename T> T normalizeValue(T value, T maximum) {
if (value < 0 || value > maximum) {
return 0; // Or any other appropriate value
}
return value / maximum;
}
*/
#endif