From e1d9ec0884c772dabb65ed3c6c4e7289824fa07c Mon Sep 17 00:00:00 2001 From: Jochen Vothknecht <jochen3120@gmail.com> Date: Fri, 27 May 2022 17:53:00 +0200 Subject: [PATCH] **HUGE** refactoring: sanitizing number types --- CLC-qthing/CyanLight.cpp | 15 +++-- CLC-qthing/CyanLight.hpp | 7 ++- CLC-qthing/IRSender.cpp | 9 ++- CLC-qthing/IRSender.hpp | 8 +-- CLC-qthing/SiliconTorch/CapMan.cpp | 3 +- CLC-qthing/SiliconTorch/CapMan.hpp | 5 +- CLC-qthing/SiliconTorch/CyanBus.cpp | 32 +++++------ CLC-qthing/SiliconTorch/CyanBus.hpp | 22 ++++---- CLC-qthing/SiliconTorch/CyanBusCRC.cpp | 14 ++--- CLC-qthing/SiliconTorch/CyanBusCRC.hpp | 6 +- .../FxCyanF-classImplementation.cpp | 55 ++++++++++--------- .../SiliconTorch/FxCyanF-configureFromNVS.cpp | 11 ++-- CLC-qthing/SiliconTorch/FxCyanF.hpp | 38 ++++++------- CLC-qthing/SiliconTorch/FxCyanRGB8.cpp | 32 +++++------ CLC-qthing/SiliconTorch/FxCyanRGB8.hpp | 18 +++--- CLC-qthing/SiliconTorch/FxPublish.cpp | 2 +- CLC-qthing/SiliconTorch/FxVSync.cpp | 2 + CLC-qthing/SiliconTorch/LambdaTask.cpp | 10 +++- CLC-qthing/SiliconTorch/Metrics.cpp | 38 ++++++------- CLC-qthing/SiliconTorch/Metrics.hpp | 39 +++++++------ CLC-qthing/SiliconTorch/NVSExplorer.cpp | 36 ++++++------ CLC-qthing/SiliconTorch/NVSExplorer.hpp | 5 +- CLC-qthing/SiliconTorch/NVSExplorer.md | 2 +- CLC-qthing/SiliconTorch/PWMChannel.cpp | 10 +++- CLC-qthing/SiliconTorch/PWMChannel.hpp | 11 ++-- CLC-qthing/SiliconTorch/RS485.cpp | 28 +++++----- CLC-qthing/SiliconTorch/RS485.hpp | 19 ++++--- CLC-qthing/SiliconTorch/SiliconTorch.cpp | 2 +- CLC-qthing/SiliconTorch/SiliconTorch.hpp | 2 +- CLC-qthing/SimpleUART.hpp | 2 +- CLC-qthing/SpiderLib/Callback.hpp | 1 - CLC-qthing/SpiderLib/CallbackMap.hpp | 15 ++--- CLC-qthing/SpiderLib/NumberTypes.hpp | 20 +++++++ CLC-qthing/SpiderLib/SNTP.cpp | 3 +- CLC-qthing/SpiderLib/SNTP.hpp | 3 +- CLC-qthing/SpiderLib/Time.cpp | 10 ++-- CLC-qthing/SpiderLib/Time.hpp | 10 ++-- CLC-qthing/SpiderLib/UDP.cpp | 14 +++-- CLC-qthing/SpiderLib/UDP.hpp | 2 + CLC-qthing/SpiderLib/Util.hpp | 9 ++- CLC-qthing/device_main.cpp | 8 ++- 41 files changed, 314 insertions(+), 264 deletions(-) create mode 100644 CLC-qthing/SpiderLib/NumberTypes.hpp diff --git a/CLC-qthing/CyanLight.cpp b/CLC-qthing/CyanLight.cpp index a9eb1af..d97ff2a 100644 --- a/CLC-qthing/CyanLight.cpp +++ b/CLC-qthing/CyanLight.cpp @@ -6,20 +6,23 @@ // ESP32 specific #include "esp_log.h" +// project specific +#include "SpiderLib/NumberTypes.hpp" -uint8_t MAX_CHANNELS = 8; + +u8 MAX_CHANNELS = 8; const char* TAG = "CyanLight"; -const uint8_t channelGPIOs[] = { 27, 16, 17, 18, 19, 21, 22, 23 }; +const u8 channelGPIOs[] = { 27, 16, 17, 18, 19, 21, 22, 23 }; namespace CyanLight { - CyanLightControl::CyanLightControl(uint8_t channelsConfigured, uint32_t baseChannel) : SiliconTorch::FxCyanF::FxCyanF(baseChannel) { + CyanLightControl::CyanLightControl(u8 channelsConfigured, u32 baseChannel) : SiliconTorch::FxCyanF::FxCyanF(baseChannel) { - uint8_t channels = std::min(channelsConfigured, MAX_CHANNELS); + u8 channels = std::min(channelsConfigured, MAX_CHANNELS); - for (uint8_t i = 0; i < channels; i++) this->addChannel(); + for (u8 i = 0; i < channels; i++) this->addChannel(); } @@ -28,7 +31,7 @@ namespace CyanLight { auto ch = this->getChannelCount(); if (ch < MAX_CHANNELS) { - return SiliconTorch::FxCyanF::FxCyanF::addChannel((uint8_t)channelGPIOs[ch]); + return SiliconTorch::FxCyanF::FxCyanF::addChannel((u8)channelGPIOs[ch]); } else { ESP_LOGE(TAG, "Cannot create channel#[ %i ]! CLC hardware limit is #[ %i ]", ch, MAX_CHANNELS); return false; diff --git a/CLC-qthing/CyanLight.hpp b/CLC-qthing/CyanLight.hpp index 2521817..63dd53a 100644 --- a/CLC-qthing/CyanLight.hpp +++ b/CLC-qthing/CyanLight.hpp @@ -1,14 +1,17 @@ #pragma once -// TODO: should we include <cinttypes> here or accepts its ingress via FxCyanF.hpp ??? +// TODO: should we include NumberTypes.hpp here or accepts its ingress via FxCyanF.hpp ??? #include "SiliconTorch/FxCyanF.hpp" +#include "SpiderLib/NumberTypes.hpp" + + namespace CyanLight { class CyanLightControl : public SiliconTorch::FxCyanF::FxCyanF { public: - CyanLightControl(uint8_t channelsConfigured, uint32_t baseChannel = 0); + CyanLightControl(u8 channelsConfigured, u32 baseChannel = 0); bool addChannel(); diff --git a/CLC-qthing/IRSender.cpp b/CLC-qthing/IRSender.cpp index 86f3e98..8c95816 100644 --- a/CLC-qthing/IRSender.cpp +++ b/CLC-qthing/IRSender.cpp @@ -5,8 +5,11 @@ #include "driver/gpio.h" #include "driver/ledc.h" +// project specific +#include "SpiderLib/NumberTypes.hpp" -IRSender::IRSender(uint8_t TXpin, uint8_t CLKpin, uint8_t UARTchannel, uint8_t LEDCchannel) { + +IRSender::IRSender(u8 TXpin, u8 CLKpin, u8 UARTchannel, u8 LEDCchannel) { ledc_timer_config_t ledc_timer; ledc_timer.duty_resolution = LEDC_TIMER_1_BIT; @@ -48,7 +51,7 @@ IRSender::IRSender(uint8_t TXpin, uint8_t CLKpin, uint8_t UARTchannel, uint8_t L } -void IRSender::send(uint8_t byte) { +void IRSender::send(u8 byte) { } @@ -56,7 +59,7 @@ void IRSender::send(std::string &data) { } -void IRSender::send(uint8_t *buffer, size_t length) { +void IRSender::send(u8 *buffer, size_t length) { } diff --git a/CLC-qthing/IRSender.hpp b/CLC-qthing/IRSender.hpp index 82ebf9a..618059d 100644 --- a/CLC-qthing/IRSender.hpp +++ b/CLC-qthing/IRSender.hpp @@ -1,17 +1,17 @@ #pragma once -#include <cinttypes> +#include "SpiderLib/NumberTypes.hpp" #include <string> class IRSender { public: - IRSender(uint8_t TXpin, uint8_t CLKpin, uint8_t UARTchannel = 1, uint8_t LEDCchannel = 7); + IRSender(u8 TXpin, u8 CLKpin, u8 UARTchannel = 1, u8 LEDCchannel = 7); - void send(uint8_t byte); + void send(u8 byte); void send(std::string &data); - void send(uint8_t *buffer, size_t length); + void send(u8 *buffer, size_t length); }; diff --git a/CLC-qthing/SiliconTorch/CapMan.cpp b/CLC-qthing/SiliconTorch/CapMan.cpp index 138fa28..e6933fe 100644 --- a/CLC-qthing/SiliconTorch/CapMan.cpp +++ b/CLC-qthing/SiliconTorch/CapMan.cpp @@ -3,7 +3,6 @@ // C++ system level // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? -#include <cinttypes> // #include <functional> // ESP32 specific @@ -13,7 +12,7 @@ // #include "driver/uart.h" // project specific -// #include "" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include <qthing> diff --git a/CLC-qthing/SiliconTorch/CapMan.hpp b/CLC-qthing/SiliconTorch/CapMan.hpp index 2bcf884..f84ccab 100644 --- a/CLC-qthing/SiliconTorch/CapMan.hpp +++ b/CLC-qthing/SiliconTorch/CapMan.hpp @@ -4,7 +4,6 @@ // #include <string> // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? -#include <cinttypes> // #include <functional> // ESP32 specific @@ -14,7 +13,7 @@ // #include "driver/uart.h" // project specific -// #include "" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include <qthing> @@ -42,7 +41,7 @@ namespace SiliconTorch { - void registerLEDStrip(std::string& name, uint16_t startIdx, uint16_t length, ColorType); + void registerLEDStrip(std::string& name, u16 startIdx, u16 length, ColorType); diff --git a/CLC-qthing/SiliconTorch/CyanBus.cpp b/CLC-qthing/SiliconTorch/CyanBus.cpp index a53644d..13e5b35 100644 --- a/CLC-qthing/SiliconTorch/CyanBus.cpp +++ b/CLC-qthing/SiliconTorch/CyanBus.cpp @@ -3,7 +3,6 @@ // C++ system level #include <cstring> // memset, strncmp #include <cstdlib> // TODO: is this for memcpy? -#include <cinttypes> #include <functional> // ESP32 specific @@ -19,6 +18,7 @@ #include "LambdaTask.hpp" #include "SpiderLib/Callback.hpp" #include "SpiderLib/CallbackMap.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include "" @@ -29,7 +29,7 @@ static const char* TAG = "CyanBus"; // Extract the length from a buffer; Network order / Big-Endian -static uint16_t getLength(const uint8_t* buffer) { +static u16 getLength(const u8* buffer) { return (buffer[0] << 8) | buffer[1]; } @@ -42,9 +42,9 @@ namespace SiliconTorch { const char* const HEADER = "fxCyan"; - CyanBus::CyanBus(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate, uint8_t uartChannel) : tx(tx), rx(rx), de(de), re(re), uartChannel(uartChannel) { + CyanBus::CyanBus(u8 tx, u8 rx, u8 de, u8 re, u32 baudRate, u8 uartChannel) : tx(tx), rx(rx), de(de), re(re), uartChannel(uartChannel) { - uint64_t bitMask = 0; + u64 bitMask = 0; bitMask |= 1ULL << tx; bitMask |= 1ULL << de; @@ -113,14 +113,14 @@ namespace SiliconTorch { uart_port_t _ch = (uart_port_t)uartChannel; - const uint32_t bufLEN = MTU + 256; // MTU + maxEventSize(120) + slack - uint8_t* buffer = new uint8_t[bufLEN]; // our packet buffer - uint8_t* bufPTR = buffer; // points inside our buffer; used for envelope parsing… + const u32 bufLEN = MTU + 256; // MTU + maxEventSize(120) + slack + u8* buffer = new u8[bufLEN]; // our packet buffer + u8* bufPTR = buffer; // points inside our buffer; used for envelope parsing… - uint16_t payloadLEN = 0; - const uint8_t crcLEN = 4; - const uint8_t lengthLEN = 2; - const uint8_t headerLEN = std::strlen(HEADER); + u16 payloadLEN = 0; + const u8 crcLEN = 4; + const u8 lengthLEN = 2; + const u8 headerLEN = std::strlen(HEADER); std::memset(buffer, 0x00, bufLEN); @@ -260,8 +260,8 @@ namespace SiliconTorch { } void CyanBus::packetTask() { - const uint8_t* buffer = new uint8_t[MTU]; - uint16_t payloadLEN = 0; + const u8* buffer = new u8[MTU]; + u16 payloadLEN = 0; auto Q = packetQ; while (true) { @@ -293,12 +293,12 @@ namespace SiliconTorch { } - void CyanBus::setBaudRate(uint32_t baudRate) { + void CyanBus::setBaudRate(u32 baudRate) { uart_set_baudrate((uart_port_t)uartChannel, baudRate); } - uint32_t CyanBus::getBaudRate() { - uint32_t baudRate = 0; + u32 CyanBus::getBaudRate() { + u32 baudRate = 0; uart_get_baudrate((uart_port_t)uartChannel, &baudRate); return baudRate; } diff --git a/CLC-qthing/SiliconTorch/CyanBus.hpp b/CLC-qthing/SiliconTorch/CyanBus.hpp index 9891c54..de76ae3 100644 --- a/CLC-qthing/SiliconTorch/CyanBus.hpp +++ b/CLC-qthing/SiliconTorch/CyanBus.hpp @@ -2,7 +2,6 @@ // C++ system level #include <string> -#include <cinttypes> #include <functional> // ESP32 specific @@ -13,6 +12,7 @@ #include "LambdaTask.hpp" #include "SpiderLib/Callback.hpp" #include "SpiderLib/CallbackMap.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include "" @@ -25,29 +25,29 @@ namespace SiliconTorch { // CyanBus payload MTU // This leads to ~54 P/s @ 2 MBaud at 100% load - constexpr uint32_t MTU = 4096; + constexpr u32 MTU = 4096; // CyanBus envelope header extern const char* const HEADER; typedef struct { - const uint8_t* payload; - const uint16_t length; + const u8* payload; + const u16 length; } PacketData; typedef struct { const bool crcOK; - const uint16_t payloadLEN; + const u16 payloadLEN; } PacketMetrics; class CyanBus { public: - CyanBus(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate = 115200, uint8_t uartChannel = 1); + CyanBus(u8 tx, u8 rx, u8 de, u8 re, u32 baudRate = 115200, u8 uartChannel = 1); - uint32_t getBaudRate(); - void setBaudRate(uint32_t baudRate); + u32 getBaudRate(); + void setBaudRate(u32 baudRate); const SpiderLib::CallbackMap<void(const PacketData&)> packetCallback; const SpiderLib::Callback<void(const PacketMetrics&)> metricsCallback; @@ -57,8 +57,8 @@ namespace SiliconTorch { QueueHandle_t uartEvQ; QueueHandle_t packetQ; - uint8_t uartChannel; - uint8_t tx, rx, de, re; + u8 uartChannel; + u8 tx, rx, de, re; void txEN(bool state); void rxEN(bool state); @@ -67,7 +67,7 @@ namespace SiliconTorch { // Receive only ATM! (make public after sound implementation…) void write(std::string& data); - void write(const uint8_t* data, uint32_t length); + void write(const u8* data, u32 length); void readerTask(); diff --git a/CLC-qthing/SiliconTorch/CyanBusCRC.cpp b/CLC-qthing/SiliconTorch/CyanBusCRC.cpp index fc6a9a7..7d5cbef 100644 --- a/CLC-qthing/SiliconTorch/CyanBusCRC.cpp +++ b/CLC-qthing/SiliconTorch/CyanBusCRC.cpp @@ -1,14 +1,14 @@ #include "CyanBusCRC.hpp" // C++ system level -#include <cinttypes> +// #include <functional> // ESP32 specific #include "esp_log.h" #include "esp32/rom/crc.h" // project specific -// #include "LambdaTask.hpp" +#include "SpiderLib/NumberTypes.hpp" static const char* TAG = "CyanBus"; @@ -20,17 +20,17 @@ namespace SiliconTorch { // Checks CyanBus CRC // Note: The last 4 bytes of buffer contain the CRC to check against and are included in the given length - bool checkCRC(uint8_t* buffer, uint32_t length) { + bool checkCRC(u8* buffer, u32 length) { if (length < 4) { ESP_LOGD(TAG, "CRC calculation failed: Input buffer too small! Got bytes[ %d ] but needs bytes[ >= 4 ]", length); return false; } - // uint32_t _init = 0x00000000; - uint32_t _init = 0xFFFFFFFF; - uint32_t calculatedCRC = crc32_be(_init, buffer, length - 4); - uint32_t packetCRC = reinterpret_cast<uint32_t*>(&buffer[length - 4])[0]; + // u32 _init = 0x00000000; + u32 _init = 0xFFFFFFFF; + u32 calculatedCRC = crc32_be(_init, buffer, length - 4); + u32 packetCRC = reinterpret_cast<u32*>(&buffer[length - 4])[0]; bool crcOK = packetCRC == calculatedCRC; diff --git a/CLC-qthing/SiliconTorch/CyanBusCRC.hpp b/CLC-qthing/SiliconTorch/CyanBusCRC.hpp index 2cf93e5..23da20d 100644 --- a/CLC-qthing/SiliconTorch/CyanBusCRC.hpp +++ b/CLC-qthing/SiliconTorch/CyanBusCRC.hpp @@ -1,13 +1,13 @@ #pragma once // C++ system level -#include <cinttypes> +// #include <functional> // ESP32 specific // #include "esp_log.h" // project specific -// #include "LambdaTask.hpp" +#include "SpiderLib/NumberTypes.hpp" @@ -17,7 +17,7 @@ namespace SiliconTorch { // Checks CyanBus CRC // seems to work against Crc32Posix from python crccheck package - bool checkCRC(uint8_t* buffer, uint32_t length); + bool checkCRC(u8* buffer, u32 length); } diff --git a/CLC-qthing/SiliconTorch/FxCyanF-classImplementation.cpp b/CLC-qthing/SiliconTorch/FxCyanF-classImplementation.cpp index 33a02ce..3efba5d 100644 --- a/CLC-qthing/SiliconTorch/FxCyanF-classImplementation.cpp +++ b/CLC-qthing/SiliconTorch/FxCyanF-classImplementation.cpp @@ -17,6 +17,7 @@ #include "FxVSync.hpp" #include "CyanBus.hpp" #include "Metrics.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff #include <qthing> @@ -41,12 +42,12 @@ namespace SiliconTorch { const std::string HEADER("fxCyanF"); - const uint8_t MAX_CHANNELS = 8; // Maybe 16…? + const u8 MAX_CHANNELS = 8; // Maybe 16…? const std::string delimiter = ":"; - static float bytes2float(const uint8_t* bytes) { + static float bytes2float(const u8* bytes) { float f; memcpy(&f, bytes, sizeof(f)); @@ -55,7 +56,7 @@ namespace SiliconTorch { } - FxCyanF::FxCyanF(uint32_t baseChannel) : metrics(Metrics::Metrics("fxCyan")), baseChannel(baseChannel) { + FxCyanF::FxCyanF(u32 baseChannel) : metrics(Metrics::Metrics("fxCyan")), baseChannel(baseChannel) { this->metrics.registerMetric("frames", "frameCounter"); this->metrics.registerMetric("errors", "errorCounter"); @@ -79,16 +80,16 @@ namespace SiliconTorch { add_binary_message_callback(this->genDeviceTopic("pwm/$all"), [&](qthing::multipart_message_t message) { - if (message.offset == 0) this->handleUnicast((const uint8_t*)message.payload, message.length); + if (message.offset == 0) this->handleUnicast((const u8*)message.payload, message.length); else ESP_LOGE(TAG, "Invalid message format: Fragmentation is unsupported"); }); std::string header("fxCyanF"); - uint8_t headerLength = header.length(); + u8 headerLength = header.length(); qthing::addUDPPacketCallback(header, [&, headerLength](udpPacket packet) { - this->handleUnicast((const uint8_t*)packet.payload + headerLength, packet.length - headerLength); + this->handleUnicast((const u8*)packet.payload + headerLength, packet.length - headerLength); }); @@ -188,13 +189,13 @@ namespace SiliconTorch { } - bool FxCyanF::addChannel(uint8_t gpio) { + bool FxCyanF::addChannel(u8 gpio) { if (this->channelsConfigured >= MAX_CHANNELS) { ESP_LOGE(TAG, "Cannot create channel#[ %i ]! ESP32 hardware limit is #[ %i ]", this->channelsConfigured, MAX_CHANNELS); return false; } - uint8_t channel = this->channelsConfigured; + u8 channel = this->channelsConfigured; // TODO: catch channel creation errors from IDF (e.g. on input-only GPIO) this->channels[channel] = new Impl::PWMChannel(channel, gpio); @@ -212,10 +213,10 @@ namespace SiliconTorch { } - bool FxCyanF::handleUnicast(const uint8_t* data, std::size_t length) { + bool FxCyanF::handleUnicast(const u8* data, std::size_t length) { std::size_t size = this->getChannelCount() * sizeof(float); - int32_t diff = length - size; + i32 diff = length - size; if (diff < 0) { ESP_LOGE(TAG, "Invalid |data|[ %d ]: Received ΔB[ %d ] bytes too few", length, -diff); @@ -224,7 +225,7 @@ namespace SiliconTorch { return false; } - for (uint8_t ch = 0; ch < this->getChannelCount(); ch++) { + for (u8 ch = 0; ch < this->getChannelCount(); ch++) { float f = bytes2float(data + ch * sizeof(float)); this->setPWM(ch, f); } @@ -235,11 +236,11 @@ namespace SiliconTorch { return true; } - bool FxCyanF::handleBroadcast(const uint8_t* data, std::size_t length) { + bool FxCyanF::handleBroadcast(const u8* data, std::size_t length) { std::size_t size = this->getChannelCount() * sizeof(float); std::size_t offset = this->getBaseChannel() * sizeof(float); - int32_t diff = length - offset - size; + i32 diff = length - offset - size; if (diff < 0) { // TODO: test thoroughly! ESP_LOGE(TAG, "Invalid data length[ %i ]: Received ΔB = %i bytes too few", length, -diff); @@ -248,7 +249,7 @@ namespace SiliconTorch { return false; } - for (uint8_t ch = 0; ch < this->getChannelCount(); ch++) { + for (u8 ch = 0; ch < this->getChannelCount(); ch++) { float f = bytes2float(data + offset + ch * sizeof(float)); this->setPWM(ch, f); } @@ -260,7 +261,7 @@ namespace SiliconTorch { } - void FxCyanF::setPWM(uint8_t channel, float value) { + void FxCyanF::setPWM(u8 channel, float value) { if (channel >= this->channelsConfigured) { ESP_LOGW(TAG, "ChannelID out of range: channel[ %i ]", channel); @@ -272,8 +273,8 @@ namespace SiliconTorch { if (value < 0.0f) value = 0.0f; if (value > 1.0f) value = 1.0f; - uint32_t maxPWM = 1 << (this->resolution - 1); - uint32_t pwm = (uint32_t)( value * (maxPWM - 1) ); + u32 maxPWM = 1 << (this->resolution - 1); + u32 pwm = (u32)( value * (maxPWM - 1) ); this->channels[channel]->setPWM(pwm); } @@ -284,7 +285,7 @@ namespace SiliconTorch { } - bool FxCyanF::setFrqRes(uint32_t frq_hz, uint8_t res_bits) { + bool FxCyanF::setFrqRes(u32 frq_hz, u8 res_bits) { this->timer_cfg.duty_resolution = (ledc_timer_bit_t)res_bits; this->timer_cfg.freq_hz = frq_hz; @@ -306,10 +307,10 @@ namespace SiliconTorch { void FxCyanF::registerAtCyanBus(CyanBus::CyanBus& cyanBus) { /* - uint8_t headerLength = HEADER.length(); + u8 headerLength = HEADER.length(); cyanBus.packetCallback.add(HEADER, [&, headerLength](const CyanBus::PacketData& packet) { - this->handlePacket((uint8_t*)(packet.payload + headerLength), packet.length - headerLength); + this->handlePacket((u8*)(packet.payload + headerLength), packet.length - headerLength); }); FxVSync::registerAtCyanBus(cyanBus, [&]() { @@ -318,31 +319,31 @@ namespace SiliconTorch { */ } - void FxCyanF::setBaseChannel(uint16_t baseChannel) { + void FxCyanF::setBaseChannel(u16 baseChannel) { this->baseChannel = baseChannel; } - uint16_t FxCyanF::getBaseChannel() { + u16 FxCyanF::getBaseChannel() { return this->baseChannel; } - uint8_t FxCyanF::getChannelCount() { + u8 FxCyanF::getChannelCount() { return this->channelsConfigured; } - bool FxCyanF::setFrequency(uint32_t frq_hz) { + bool FxCyanF::setFrequency(u32 frq_hz) { return this->setFrqRes(frq_hz, this->resolution); } - uint32_t FxCyanF::getFrequency() { + u32 FxCyanF::getFrequency() { return this->frequency; } - bool FxCyanF::setResolution(uint8_t res_bits) { + bool FxCyanF::setResolution(u8 res_bits) { return this->setFrqRes(this->frequency, res_bits); } - uint8_t FxCyanF::getResolution() { + u8 FxCyanF::getResolution() { return this->resolution; } diff --git a/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp b/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp index 75349dc..20fa96f 100644 --- a/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp +++ b/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp @@ -20,6 +20,7 @@ // #include <qthing/mqtt_common.hpp> // project specific +#include "SpiderLib/NumberTypes.hpp" // #include "FxVSync.hpp" // #include "CyanBus.hpp" // #include "Metrics.hpp" @@ -46,10 +47,10 @@ namespace SiliconTorch { nvs_open(nvsNameSpace, NVS_READONLY, &nvs); - uint32_t frq = 0; + u32 frq = 0; nvs_get_u32(nvs, "frequency", &frq); - uint8_t res = 0; + u8 res = 0; nvs_get_u8(nvs, "resolution", &res); @@ -61,9 +62,9 @@ namespace SiliconTorch { ESP_LOGW(TAG, "Found config for FxCyanF{ frequency[ %d Hz ] resolution[ %d Bit ] } in NVS", frq, res); // TODO: Log-Level Debug - for (uint8_t ch = 0; ch < MAX_CHANNELS; ch++) { + for (u8 ch = 0; ch < MAX_CHANNELS; ch++) { - int8_t gpio = -1; + i8 gpio = -1; char channel[32]; snprintf(channel, 32, "ch%d_gpio", ch); @@ -72,7 +73,7 @@ namespace SiliconTorch { if (gpio >= 0) { - target.addChannel((uint8_t)gpio); + target.addChannel((u8)gpio); ESP_LOGW(TAG, "channel[ %d ] gpio[ %d ]", ch, gpio); // TODO: Log-Level Info diff --git a/CLC-qthing/SiliconTorch/FxCyanF.hpp b/CLC-qthing/SiliconTorch/FxCyanF.hpp index eceac4d..3e900c1 100644 --- a/CLC-qthing/SiliconTorch/FxCyanF.hpp +++ b/CLC-qthing/SiliconTorch/FxCyanF.hpp @@ -6,12 +6,12 @@ // C++ system level #include <string> #include <functional> -#include <cinttypes> // project specific #include "CyanBus.hpp" #include "Metrics.hpp" #include "PWMChannel.hpp" +#include "SpiderLib/NumberTypes.hpp" @@ -23,38 +23,38 @@ namespace SiliconTorch { extern const char* nvsNameSpace; extern const std::string HEADER; - extern const uint8_t MAX_CHANNELS; + extern const u8 MAX_CHANNELS; typedef std::function<void()> PacketHandledCallback; typedef std::function<float(float)> GammaCorrector; class FxCyanF { public: - FxCyanF(uint32_t baseChannel = 0); + FxCyanF(u32 baseChannel = 0); - bool addChannel(uint8_t gpio); + bool addChannel(u8 gpio); - void setPWM(uint8_t channel, float value); + void setPWM(u8 channel, float value); void setGammaCorrector(GammaCorrector gammaCorrector); - uint8_t getChannelCount(); + u8 getChannelCount(); - void setBaseChannel(uint16_t baseChannel); - uint16_t getBaseChannel(); + void setBaseChannel(u16 baseChannel); + u16 getBaseChannel(); - bool setFrequency(uint32_t frq_hz); - uint32_t getFrequency(); + bool setFrequency(u32 frq_hz); + u32 getFrequency(); - bool setResolution(uint8_t res_bits); - uint8_t getResolution(); + bool setResolution(u8 res_bits); + u8 getResolution(); - bool setFrqRes(uint32_t frq_hz, uint8_t res_bits); + bool setFrqRes(u32 frq_hz, u8 res_bits); void setPacketHandledCallback(PacketHandledCallback callback); - bool handleUnicast(const uint8_t* data, std::size_t length); - bool handleBroadcast(const uint8_t* data, std::size_t length); + bool handleUnicast(const u8* data, std::size_t length); + bool handleBroadcast(const u8* data, std::size_t length); void registerAtCyanBus(CyanBus::CyanBus& cyanBus); @@ -70,11 +70,11 @@ namespace SiliconTorch { private: - uint32_t frequency = 1000; // Hz - uint8_t resolution = 10; // bits + u32 frequency = 1000; // Hz + u8 resolution = 10; // bits - uint32_t baseChannel; - uint8_t channelsConfigured = 0; + u32 baseChannel; + u8 channelsConfigured = 0; Impl::PWMChannel** channels; diff --git a/CLC-qthing/SiliconTorch/FxCyanRGB8.cpp b/CLC-qthing/SiliconTorch/FxCyanRGB8.cpp index 24ba38e..4351d6b 100644 --- a/CLC-qthing/SiliconTorch/FxCyanRGB8.cpp +++ b/CLC-qthing/SiliconTorch/FxCyanRGB8.cpp @@ -3,7 +3,6 @@ // C++ system level #include <string> #include <cstring> // memset -#include <cinttypes> #include <algorithm> #include <functional> @@ -14,6 +13,7 @@ // project specific #include "FxVSync.hpp" #include "CyanBus.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include "" @@ -27,7 +27,7 @@ namespace SiliconTorch { const std::string HEADER("fxCyanRGB8"); - FxCyanRGB8::FxCyanRGB8(uint16_t leds, uint16_t startIdx) : leds(leds), startIdx(startIdx) { + FxCyanRGB8::FxCyanRGB8(u16 leds, u16 startIdx) : leds(leds), startIdx(startIdx) { buffer0 = new qthing::RGB[leds]; buffer1 = new qthing::RGB[leds]; @@ -39,7 +39,7 @@ namespace SiliconTorch { } - void FxCyanRGB8::handlePacket(uint8_t* buffer, std::size_t length) { + void FxCyanRGB8::handlePacket(u8* buffer, std::size_t length) { if (length < 3) { ESP_LOGE(HEADER.c_str(), "Wrong |buffer|[ %d ]: Must be greater than 2!", length); @@ -53,13 +53,13 @@ namespace SiliconTorch { Pixel* packetPx = reinterpret_cast<Pixel*>(buffer+2); - uint16_t packetPxs = (length - 2) / 3; - uint16_t packetStartIdx = (buffer[0] << 8) | buffer[1]; + u16 packetPxs = (length - 2) / 3; + u16 packetStartIdx = (buffer[0] << 8) | buffer[1]; if (packetStartIdx == startIdx) { - for (uint16_t px = 0; px < std::min(leds, packetPxs); px++) { + for (u16 px = 0; px < std::min(leds, packetPxs); px++) { buffer1[px].r = packetPx[px].r / 255.0f; buffer1[px].g = packetPx[px].g / 255.0f; buffer1[px].b = packetPx[px].b / 255.0f; @@ -67,9 +67,9 @@ namespace SiliconTorch { } else if(packetStartIdx > startIdx) { - uint16_t delta = packetStartIdx - startIdx; + u16 delta = packetStartIdx - startIdx; - for (uint16_t px = delta; px < std::min(leds, (uint16_t)(packetPxs + delta)); px++) { + for (u16 px = delta; px < std::min(leds, (u16)(packetPxs + delta)); px++) { buffer1[px].r = packetPx[px - delta].r / 255.0f; buffer1[px].g = packetPx[px - delta].g / 255.0f; buffer1[px].b = packetPx[px - delta].b / 255.0f; @@ -77,12 +77,12 @@ namespace SiliconTorch { } else if (packetStartIdx < startIdx) { - uint16_t delta = startIdx - packetStartIdx; + u16 delta = startIdx - packetStartIdx; // Packet does not contain any pixels for us if (packetPxs < delta) return; - for (uint16_t px = 0; px < std::min(leds, (uint16_t)(packetPxs - delta)); px++) { + for (u16 px = 0; px < std::min(leds, (u16)(packetPxs - delta)); px++) { buffer1[px].r = packetPx[px + delta].r / 255.0f; buffer1[px].g = packetPx[px + delta].g / 255.0f; buffer1[px].b = packetPx[px + delta].b / 255.0f; @@ -92,10 +92,10 @@ namespace SiliconTorch { void FxCyanRGB8::registerAtCyanBus(CyanBus::CyanBus& cyanBus) { - uint8_t headerLength = HEADER.length(); + u8 headerLength = HEADER.length(); cyanBus.packetCallback.add(HEADER, [&, headerLength](const SiliconTorch::CyanBus::PacketData& packet) { - this->handlePacket((uint8_t*)(packet.payload + headerLength), packet.length - headerLength); + this->handlePacket((u8*)(packet.payload + headerLength), packet.length - headerLength); }); FxVSync::registerAtCyanBus(cyanBus, [&]() { @@ -108,17 +108,17 @@ namespace SiliconTorch { if (!udpHandlerRegistered) { udpHandlerRegistered = true; - uint8_t headerLength = HEADER.length(); + u8 headerLength = HEADER.length(); qthing::addUDPPacketCallback(HEADER, [&, headerLength](qthing::udpPacket packet) { - this->handlePacket((uint8_t*)(packet.payload + headerLength), packet.length - headerLength); + this->handlePacket((u8*)(packet.payload + headerLength), packet.length - headerLength); requestBufferSwap(); }); } } // qthing::Animator - qthing::RGB FxCyanRGB8::render(uint16_t addr) { + qthing::RGB FxCyanRGB8::render(u16 addr) { if (addr < leds) { return buffer0[addr]; } else { @@ -142,7 +142,7 @@ namespace SiliconTorch { buffer0 = buffer1; buffer1 = tmp; - for (uint16_t px = 0; px < leds; px++){ + for (u16 px = 0; px < leds; px++){ buffer1[px].r = 0; buffer1[px].g = 0; buffer1[px].b = 0; diff --git a/CLC-qthing/SiliconTorch/FxCyanRGB8.hpp b/CLC-qthing/SiliconTorch/FxCyanRGB8.hpp index 4901f07..769543b 100644 --- a/CLC-qthing/SiliconTorch/FxCyanRGB8.hpp +++ b/CLC-qthing/SiliconTorch/FxCyanRGB8.hpp @@ -2,7 +2,6 @@ // C++ system level #include <string> -#include <cinttypes> #include <functional> // ESP32 specific @@ -11,6 +10,7 @@ // project specific #include "CyanBus.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff #include <qthing> @@ -22,16 +22,16 @@ namespace SiliconTorch { namespace FxCyanRGB8 { typedef struct __attribute__((__packed__)) { - uint8_t r; - uint8_t g; - uint8_t b; + u8 r; + u8 g; + u8 b; } Pixel; extern const std::string HEADER; class FxCyanRGB8 : public qthing::Animation<qthing::RGB> { public: - FxCyanRGB8(uint16_t leds, uint16_t startIdx = 0); + FxCyanRGB8(u16 leds, u16 startIdx = 0); void getAnimator(); @@ -42,11 +42,11 @@ namespace SiliconTorch { void registerUDPHandler(); // Strip the header before calling this function! - void handlePacket(uint8_t* buffer, std::size_t length); + void handlePacket(u8* buffer, std::size_t length); // qthing::Animator void step(); - qthing::RGB render(uint16_t addr); + qthing::RGB render(u16 addr); private: @@ -56,8 +56,8 @@ namespace SiliconTorch { bool swapRequested = false; bool udpHandlerRegistered = false; - uint16_t leds; - uint16_t startIdx; + u16 leds; + u16 startIdx; void swapBuffers(); diff --git a/CLC-qthing/SiliconTorch/FxPublish.cpp b/CLC-qthing/SiliconTorch/FxPublish.cpp index 99e8859..27680c1 100644 --- a/CLC-qthing/SiliconTorch/FxPublish.cpp +++ b/CLC-qthing/SiliconTorch/FxPublish.cpp @@ -4,7 +4,6 @@ #include <string> // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? -// #include <cinttypes> // #include <functional> // ESP32 specific @@ -12,6 +11,7 @@ // project specific #include "CyanBus.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff #include <qthing> diff --git a/CLC-qthing/SiliconTorch/FxVSync.cpp b/CLC-qthing/SiliconTorch/FxVSync.cpp index a536a6b..b1bb375 100644 --- a/CLC-qthing/SiliconTorch/FxVSync.cpp +++ b/CLC-qthing/SiliconTorch/FxVSync.cpp @@ -8,6 +8,8 @@ // project specific #include "CyanBus.hpp" +#include "SpiderLib/NumberTypes.hpp" + // qthing stuff // #include "" diff --git a/CLC-qthing/SiliconTorch/LambdaTask.cpp b/CLC-qthing/SiliconTorch/LambdaTask.cpp index 18a18f7..5d9fef9 100644 --- a/CLC-qthing/SiliconTorch/LambdaTask.cpp +++ b/CLC-qthing/SiliconTorch/LambdaTask.cpp @@ -1,8 +1,12 @@ #include "LambdaTask.hpp" +// ESP32 system level #include "freertos/FreeRTOS.h" #include "freertos/task.h" +// project specific +#include "SpiderLib/NumberTypes.hpp" + static void taskWrapper(void* body) { @@ -10,8 +14,8 @@ static void taskWrapper(void* body) { (*f)(); } -static uint16_t taskID = 0; -static uint16_t nextID() { +static u16 taskID = 0; +static u16 nextID() { return taskID++; // TODO: increment thread-safe! } @@ -23,7 +27,7 @@ SiliconTorch::Util::LambdaTask::LambdaTask(SiliconTorch::Util::Function0 body) : // TODO: allow other niceness than one // TODO: allow pinning to other cores than app CPU - uint8_t priority = 1; + u8 priority = 1; std::function<void()> _body = [&]() { this->body(); diff --git a/CLC-qthing/SiliconTorch/Metrics.cpp b/CLC-qthing/SiliconTorch/Metrics.cpp index 6372778..33ba042 100644 --- a/CLC-qthing/SiliconTorch/Metrics.cpp +++ b/CLC-qthing/SiliconTorch/Metrics.cpp @@ -1,5 +1,8 @@ #include "Metrics.hpp" +// C++ system level +#include <climits> + // ESP32 specific #include "freertos/FreeRTOS.h" // #include "freertos/semphr.h" @@ -14,12 +17,9 @@ // qthing stuff #include <qthing> -// C++ system level -#include <climits> -#include <cinttypes> - // project specific #include "../SpiderLib/SNTP.hpp" +#include "SpiderLib/NumberTypes.hpp" using namespace qthing; @@ -29,7 +29,7 @@ using json = nlohmann::json; static const char* TAG = "Metrics"; -static uint8_t nextTask = 0; +static u8 nextTask = 0; static void methodTaskWrapper(void* parameter) { std::function<void()>* f = (std::function<void()>*)parameter; (*f)(); @@ -40,8 +40,8 @@ namespace SiliconTorch { namespace Metrics { - uint32_t uptime_ms() { - return (uint32_t)(esp_timer_get_time() / 1000L); + u32 uptime_ms() { + return (u32)(esp_timer_get_time() / 1000L); } Metrics::Metrics(const std::string& nameSpace) : nameSpace(nameSpace) { @@ -63,7 +63,7 @@ namespace SiliconTorch { ESP_LOGI(TAG, "Found my birth timestamp[ %lld ]", this->birth); SpiderLib::SNTP::instance().registerTimeSyncHandler([&](){ - uint64_t now = (uint64_t)std::time(NULL); + u64 now = (u64)std::time(NULL); float age = (float)(now - this->birth); age /= 24.0f * 60.0f * 60.0f; @@ -73,7 +73,7 @@ namespace SiliconTorch { } else { SpiderLib::SNTP::instance().registerTimeSyncHandler([&](){ - this->birth = (uint64_t)std::time(NULL); + this->birth = (u64)std::time(NULL); esp_err_t err = nvs_set_u64(this->nvs, "birth", this->birth); @@ -149,7 +149,7 @@ namespace SiliconTorch { it->second->save(&this->nvs); - uint32_t now = uptime_ms(); + u32 now = uptime_ms(); lifeTime += now - lifeTimeSaved; lifeTimeSaved = now; @@ -172,7 +172,7 @@ namespace SiliconTorch { while (true) { - uint32_t now = uptime_ms(); + u32 now = uptime_ms(); if ((now - lastSaved ) / 1000 > saveInterval ) saveData(); if ((now - lastPublished) / 1000 > publishInterval) publishData(); @@ -194,7 +194,7 @@ namespace SiliconTorch { } - uint64_t Metrics::getCounterValue(const std::string& shortName) { + u64 Metrics::getCounterValue(const std::string& shortName) { auto result = counters.find(shortName); @@ -250,7 +250,7 @@ namespace SiliconTorch { } } - uint64_t CounterMetric::getValue() { + u64 CounterMetric::getValue() { return value; } @@ -272,23 +272,23 @@ namespace SiliconTorch { } // pre-increment - uint64_t& CounterMetric::CounterMetric::operator++() { + u64& CounterMetric::CounterMetric::operator++() { inc(); return value; } // pre-decrement - uint64_t& CounterMetric::CounterMetric::operator--() { + u64& CounterMetric::CounterMetric::operator--() { dec(); return value; } // post-increment - uint64_t CounterMetric::CounterMetric::operator++(int ignored) { - uint64_t out = value; inc(); return out; + u64 CounterMetric::CounterMetric::operator++(int ignored) { + u64 out = value; inc(); return out; } // post-decrement - uint64_t CounterMetric::CounterMetric::operator--(int ignored) { - uint64_t out = value; dec(); return out; + u64 CounterMetric::CounterMetric::operator--(int ignored) { + u64 out = value; dec(); return out; } } } diff --git a/CLC-qthing/SiliconTorch/Metrics.hpp b/CLC-qthing/SiliconTorch/Metrics.hpp index 7b00f41..e651959 100644 --- a/CLC-qthing/SiliconTorch/Metrics.hpp +++ b/CLC-qthing/SiliconTorch/Metrics.hpp @@ -9,6 +9,9 @@ // ESP32 specific #include "nvs.h" +// project specific +#include "SpiderLib/NumberTypes.hpp" + namespace SiliconTorch { @@ -17,7 +20,7 @@ namespace SiliconTorch { typedef std::function<void()> Incrementer; - uint32_t uptime_ms(); // rolls over after about 136 years + u32 uptime_ms(); // rolls over after about 136 years class CounterMetric { public: @@ -28,7 +31,7 @@ namespace SiliconTorch { bool dirty = false; - uint64_t getValue(); + u64 getValue(); void inc(); void dec(); @@ -37,15 +40,15 @@ namespace SiliconTorch { void save(nvs_handle_t* nvs); // saves only if enoughg time elapsed void forceSave(nvs_handle_t* nvs); // saves value immediately - uint64_t& operator++(); // pre-increment - uint64_t& operator--(); // pre-decrement + u64& operator++(); // pre-increment + u64& operator--(); // pre-decrement - uint64_t operator++(int); // post-increment - uint64_t operator--(int); // post-decrement + u64 operator++(int); // post-increment + u64 operator--(int); // post-decrement private: - uint64_t value = 0; + u64 value = 0; }; @@ -59,7 +62,7 @@ namespace SiliconTorch { * returns the actual value or 0 for unknown counters * also supports getting the special bootCnt, uptime and lifetime metrics */ - uint64_t getCounterValue(const std::string& shortName); + u64 getCounterValue(const std::string& shortName); Incrementer generateMetricIncrementer(const std::string& shortName); @@ -72,21 +75,21 @@ namespace SiliconTorch { private: - uint32_t saveInterval = 60*60; // seconds - uint32_t publishInterval = 60; // seconds + u32 saveInterval = 60*60; // seconds + u32 publishInterval = 60; // seconds - uint32_t lastSaved = uptime_ms(); // unix timestamp - uint32_t lastPublished = uptime_ms(); // unix timestamp + u32 lastSaved = uptime_ms(); // unix timestamp + u32 lastPublished = uptime_ms(); // unix timestamp - uint32_t tickPeriod = 3000; // milli seconds + u32 tickPeriod = 3000; // milli seconds - uint64_t lifeTime = 0; // milli seconds - uint64_t lifeTimeSaved = 0; // milli seconds + u64 lifeTime = 0; // milli seconds + u64 lifeTimeSaved = 0; // milli seconds - uint32_t bootCnt = 0; - uint32_t bootCntSaveUptime = 60; // seconds + u32 bootCnt = 0; + u32 bootCntSaveUptime = 60; // seconds - uint64_t birth = 0; // unix timestamp of first device activation + u64 birth = 0; // unix timestamp of first device activation void tickTask(); void saveBootCntTask(); diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.cpp b/CLC-qthing/SiliconTorch/NVSExplorer.cpp index 8bc4fb7..6c150ba 100644 --- a/CLC-qthing/SiliconTorch/NVSExplorer.cpp +++ b/CLC-qthing/SiliconTorch/NVSExplorer.cpp @@ -6,7 +6,6 @@ #include <vector> #include <cstring> // memset, memcpy, strncmp // #include <cstdlib> -#include <cinttypes> // #include <functional> // ESP32 specific @@ -17,6 +16,7 @@ // project specific #include <SpiderLib/Util.hpp> +#include "SpiderLib/NumberTypes.hpp" // qthing stuff #include <qthing> @@ -41,7 +41,7 @@ namespace SiliconTorch { - uint16_t deviceTopicLEN = requestTopic("").length(); + u16 deviceTopicLEN = requestTopic("").length(); auto wrapMessageHandler = [deviceTopicLEN](std::function<void(std::vector<std::string>&, qthing::multipart_message_t)> handler) { return [handler, deviceTopicLEN](qthing::multipart_message_t msg) { @@ -154,7 +154,7 @@ namespace SiliconTorch { float NVSExplorer::getFloat(const std::string& nameSpace, const std::string& key) { float value = std::nanf("1337"); - uint32_t* valptr = reinterpret_cast<uint32_t*>(&value); + u32* valptr = reinterpret_cast<u32*>(&value); nvs_handle_t nvs; if ( nvs_open(nameSpace.c_str(), NVS_READONLY, &nvs) == ESP_OK ) { @@ -168,7 +168,7 @@ namespace SiliconTorch { double NVSExplorer::getDouble(const std::string& nameSpace, const std::string& key) { double value = std::nan("1337"); - uint64_t* valptr = reinterpret_cast<uint64_t*>(&value); + u64* valptr = reinterpret_cast<u64*>(&value); nvs_handle_t nvs; if ( nvs_open(nameSpace.c_str(), NVS_READONLY, &nvs) == ESP_OK ) { @@ -183,7 +183,7 @@ namespace SiliconTorch { bool NVSExplorer::setFloat(const std::string& nameSpace, const std::string& key, float value) { bool success = true; - uint32_t intval = reinterpret_cast<uint32_t*>(&value)[0]; + u32 intval = reinterpret_cast<u32*>(&value)[0]; nvs_handle_t nvs; if ( nvs_open(nameSpace.c_str(), NVS_READWRITE, &nvs) == ESP_OK ) { @@ -200,7 +200,7 @@ namespace SiliconTorch { bool NVSExplorer::setDouble(const std::string& nameSpace, const std::string& key, double value) { bool success = true; - uint64_t intval = reinterpret_cast<uint64_t*>(&value)[0]; + u64 intval = reinterpret_cast<u64*>(&value)[0]; nvs_handle_t nvs; if ( nvs_open(nameSpace.c_str(), NVS_READWRITE, &nvs) == ESP_OK ) { @@ -263,7 +263,7 @@ namespace SiliconTorch { } - int64_t getSignedInt(const std::string& nameSpace, const std::string& key, int64_t defaultValue) { + i64 getSignedInt(const std::string& nameSpace, const std::string& key, i64 defaultValue) { // Lets first test & evaluate the other function before duplication……… @@ -271,9 +271,9 @@ namespace SiliconTorch { } - uint64_t getUnsignedInt(const std::string& nameSpace, const std::string& key, uint64_t defaultValue) { + u64 getUnsignedInt(const std::string& nameSpace, const std::string& key, u64 defaultValue) { - uint64_t value = defaultValue; + u64 value = defaultValue; nvs_type_t entryType = NVS_TYPE_ANY; // search for the key to get its type @@ -299,16 +299,16 @@ namespace SiliconTorch { if ( nvs_open(nameSpace.c_str(), NVS_READONLY, &nvs) != ESP_OK ) // namespace not found return defaultValue; - uint64_t* valptr = &value; + u64* valptr = &value; switch (entryType) { - case NVS_TYPE_U8: { nvs_get_u8(nvs, key.c_str(), ( uint8_t*)valptr); break; } - case NVS_TYPE_I8: { nvs_get_i8(nvs, key.c_str(), ( int8_t*)valptr); break; } - case NVS_TYPE_U16: { nvs_get_u16(nvs, key.c_str(), (uint16_t*)valptr); break; } - case NVS_TYPE_I16: { nvs_get_i16(nvs, key.c_str(), ( int16_t*)valptr); break; } - case NVS_TYPE_U32: { nvs_get_u32(nvs, key.c_str(), (uint32_t*)valptr); break; } - case NVS_TYPE_I32: { nvs_get_i32(nvs, key.c_str(), ( int32_t*)valptr); break; } - case NVS_TYPE_U64: { nvs_get_u64(nvs, key.c_str(), (uint64_t*)valptr); break; } - case NVS_TYPE_I64: { nvs_get_i64(nvs, key.c_str(), ( int64_t*)valptr); break; } + case NVS_TYPE_U8: { nvs_get_u8(nvs, key.c_str(), ( u8*)valptr); break; } + case NVS_TYPE_I8: { nvs_get_i8(nvs, key.c_str(), ( i8*)valptr); break; } + case NVS_TYPE_U16: { nvs_get_u16(nvs, key.c_str(), (u16*)valptr); break; } + case NVS_TYPE_I16: { nvs_get_i16(nvs, key.c_str(), ( i16*)valptr); break; } + case NVS_TYPE_U32: { nvs_get_u32(nvs, key.c_str(), (u32*)valptr); break; } + case NVS_TYPE_I32: { nvs_get_i32(nvs, key.c_str(), ( i32*)valptr); break; } + case NVS_TYPE_U64: { nvs_get_u64(nvs, key.c_str(), (u64*)valptr); break; } + case NVS_TYPE_I64: { nvs_get_i64(nvs, key.c_str(), ( i64*)valptr); break; } default: {} } diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.hpp b/CLC-qthing/SiliconTorch/NVSExplorer.hpp index 4573eeb..edea9e4 100644 --- a/CLC-qthing/SiliconTorch/NVSExplorer.hpp +++ b/CLC-qthing/SiliconTorch/NVSExplorer.hpp @@ -15,6 +15,7 @@ // #include "driver/uart.h" // project specific +#include "SpiderLib/NumberTypes.hpp" // #include "SpiderLib/ManagedMutex.hpp" // qthing stuff @@ -40,8 +41,8 @@ namespace SiliconTorch { // Gets the key regardless of its type in flash - int64_t getSignedInt(const std::string& nameSpace, const std::string& key, int64_t defaultValue = 0); - uint64_t getUnsignedInt(const std::string& nameSpace, const std::string& key, uint64_t defaultValue = 0); + i64 getSignedInt(const std::string& nameSpace, const std::string& key, i64 defaultValue = 0); + u64 getUnsignedInt(const std::string& nameSpace, const std::string& key, u64 defaultValue = 0); float getFloat(const std::string& nameSpace, const std::string& key); double getDouble(const std::string& nameSpace, const std::string& key); diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.md b/CLC-qthing/SiliconTorch/NVSExplorer.md index 67c02b7..1e4dabe 100644 --- a/CLC-qthing/SiliconTorch/NVSExplorer.md +++ b/CLC-qthing/SiliconTorch/NVSExplorer.md @@ -54,7 +54,7 @@ In the following list, `argument` stands for the message content received on the - `get_raw` - **get generic value** request: `REQUEST/get_raw/NS/KEY` response: `RESPONSE/get_raw/NS/KEY` - description: returns the value in its binary form, for example `2 bytes` in case of `uint16_t` + description: returns the value in its binary form, for example `2 bytes` in case of `u16` - `get_<float|double>` - **get floating point value** request: `REQUEST/get_<float|double>/NS/KEY` diff --git a/CLC-qthing/SiliconTorch/PWMChannel.cpp b/CLC-qthing/SiliconTorch/PWMChannel.cpp index e00bf33..bb25bac 100644 --- a/CLC-qthing/SiliconTorch/PWMChannel.cpp +++ b/CLC-qthing/SiliconTorch/PWMChannel.cpp @@ -4,9 +4,13 @@ #include "driver/gpio.h" #include "driver/ledc.h" +// project specific +#include "SpiderLib/NumberTypes.hpp" -SiliconTorch::Impl::PWMChannel::PWMChannel(uint8_t channel, uint8_t gpio) : channel{(ledc_channel_t)channel} { + + +SiliconTorch::Impl::PWMChannel::PWMChannel(u8 channel, u8 gpio) : channel{(ledc_channel_t)channel} { gpio_config_t conf; @@ -35,13 +39,13 @@ SiliconTorch::Impl::PWMChannel::PWMChannel(uint8_t channel, uint8_t gpio) : chan this->setPWM(0); } -void SiliconTorch::Impl::PWMChannel::setPWM(uint32_t pwm) { +void SiliconTorch::Impl::PWMChannel::setPWM(u32 pwm) { ledc_set_duty(LEDC_HIGH_SPEED_MODE, this->channel, pwm); ledc_update_duty(LEDC_HIGH_SPEED_MODE, this->channel); this->pwm = pwm; } -uint32_t SiliconTorch::Impl::PWMChannel::getPWM() { +u32 SiliconTorch::Impl::PWMChannel::getPWM() { return this->pwm; } diff --git a/CLC-qthing/SiliconTorch/PWMChannel.hpp b/CLC-qthing/SiliconTorch/PWMChannel.hpp index 420213d..6154fa4 100644 --- a/CLC-qthing/SiliconTorch/PWMChannel.hpp +++ b/CLC-qthing/SiliconTorch/PWMChannel.hpp @@ -3,6 +3,9 @@ // ESP32 specific #include "driver/ledc.h" +// project specific +#include "SpiderLib/NumberTypes.hpp" + namespace SiliconTorch { @@ -10,13 +13,13 @@ namespace SiliconTorch { class PWMChannel { public: - PWMChannel(uint8_t channel, uint8_t gpio); + PWMChannel(u8 channel, u8 gpio); - uint32_t getPWM(); - void setPWM(uint32_t pwm); + u32 getPWM(); + void setPWM(u32 pwm); private: - uint32_t pwm = 0; + u32 pwm = 0; ledc_channel_t channel; }; diff --git a/CLC-qthing/SiliconTorch/RS485.cpp b/CLC-qthing/SiliconTorch/RS485.cpp index c4fd6e9..805b30a 100644 --- a/CLC-qthing/SiliconTorch/RS485.cpp +++ b/CLC-qthing/SiliconTorch/RS485.cpp @@ -1,7 +1,7 @@ #include "RS485.hpp" // C++ system level -#include <cinttypes> +// #include <functional> // ESP32 specific #include "esp_log.h" @@ -9,7 +9,7 @@ #include "driver/uart.h" // project specific -// #include "LambdaTask.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include "" @@ -21,7 +21,7 @@ static const char* TAG = "RS485"; // This leads to ~54 P/s @ 2 MBaud at 100% load // TODO: Make configurable?! -const uint32_t CyanBusMTU = 4096; +const u32 CyanBusMTU = 4096; namespace SiliconTorch { @@ -29,9 +29,9 @@ namespace SiliconTorch { namespace Impl { - RS485::RS485(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate, uint8_t uartChannel) : tx(tx), rx(rx), de(de), re(re), uartChannel(uartChannel) { + RS485::RS485(u8 tx, u8 rx, u8 de, u8 re, u32 baudRate, u8 uartChannel) : tx(tx), rx(rx), de(de), re(re), uartChannel(uartChannel) { - uint64_t bitMask = 0; + u64 bitMask = 0; bitMask |= 1 << tx; bitMask |= 1 << de; @@ -82,8 +82,8 @@ namespace SiliconTorch { } - void RS485::write(const uint8_t* data, uint32_t length) { - uint32_t send = uart_write_bytes((uart_port_t)uartChannel, reinterpret_cast<const char*>(data), length); + void RS485::write(const u8* data, u32 length) { + u32 send = uart_write_bytes((uart_port_t)uartChannel, reinterpret_cast<const char*>(data), length); // TODO: remove after change! ESP_LOGE(TAG, "This class is receive-only atm! TX won't work!"); @@ -92,7 +92,7 @@ namespace SiliconTorch { } void RS485::write(std::string& data) { - uint32_t send = uart_write_bytes((uart_port_t)uartChannel, data.c_str(), data.length()); + u32 send = uart_write_bytes((uart_port_t)uartChannel, data.c_str(), data.length()); // TODO: remove after change! ESP_LOGE(TAG, "This class is receive-only atm! TX won't work!"); @@ -101,24 +101,24 @@ namespace SiliconTorch { } // returns the real amount of data read - uint32_t RS485::read(uint8_t* data, uint32_t length) { + u32 RS485::read(u8* data, u32 length) { return uart_read_bytes((uart_port_t)uartChannel, data, length, 0); // TODO: ticks…??? } - uint32_t RS485::available() { + u32 RS485::available() { size_t tmp; uart_get_buffered_data_len((uart_port_t)uartChannel, &tmp); - return (uint32_t)tmp; + return (u32)tmp; } - void RS485::setBaudRate(uint32_t baudRate) { + void RS485::setBaudRate(u32 baudRate) { uart_set_baudrate((uart_port_t)uartChannel, baudRate); } - uint32_t RS485::getBaudRate() { - uint32_t baudRate = 0; + u32 RS485::getBaudRate() { + u32 baudRate = 0; uart_get_baudrate((uart_port_t)uartChannel, &baudRate); return baudRate; } diff --git a/CLC-qthing/SiliconTorch/RS485.hpp b/CLC-qthing/SiliconTorch/RS485.hpp index 74a2918..e691c29 100644 --- a/CLC-qthing/SiliconTorch/RS485.hpp +++ b/CLC-qthing/SiliconTorch/RS485.hpp @@ -2,9 +2,10 @@ // C++ system level #include <string> -#include <cinttypes> #include <functional> +// project specific +#include "SpiderLib/NumberTypes.hpp" namespace SiliconTorch { @@ -13,18 +14,18 @@ namespace SiliconTorch { class RS485 { public: - RS485(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate = 115200, uint8_t uartChannel = 1); + RS485(u8 tx, u8 rx, u8 de, u8 re, u32 baudRate = 115200, u8 uartChannel = 1); - uint32_t getBaudRate(); - void setBaudRate(uint32_t baudRate); + u32 getBaudRate(); + void setBaudRate(u32 baudRate); - uint32_t available(); - uint32_t read(uint8_t* data, uint32_t length); + u32 available(); + u32 read(u8* data, u32 length); private: - uint8_t uartChannel; - uint8_t tx, rx, de, re; + u8 uartChannel; + u8 tx, rx, de, re; void txEN(bool state); void rxEN(bool state); @@ -32,7 +33,7 @@ namespace SiliconTorch { // Receive only ATM! void write(std::string& data); - void write(const uint8_t* data, uint32_t length); + void write(const u8* data, u32 length); }; } diff --git a/CLC-qthing/SiliconTorch/SiliconTorch.cpp b/CLC-qthing/SiliconTorch/SiliconTorch.cpp index 1b61ff1..857f2e1 100644 --- a/CLC-qthing/SiliconTorch/SiliconTorch.cpp +++ b/CLC-qthing/SiliconTorch/SiliconTorch.cpp @@ -3,7 +3,6 @@ // C++ system level #include <cstring> // memset, strncmp #include <cstdlib> // TODO: is this for memcpy? -#include <cinttypes> #include <functional> // ESP32 specific @@ -19,6 +18,7 @@ #include "LambdaTask.hpp" #include "SpiderLib/Callback.hpp" #include "SpiderLib/CallbackMap.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include "" diff --git a/CLC-qthing/SiliconTorch/SiliconTorch.hpp b/CLC-qthing/SiliconTorch/SiliconTorch.hpp index 866578a..65b693f 100644 --- a/CLC-qthing/SiliconTorch/SiliconTorch.hpp +++ b/CLC-qthing/SiliconTorch/SiliconTorch.hpp @@ -2,7 +2,6 @@ // C++ system level #include <string> -#include <cinttypes> #include <functional> // ESP32 specific @@ -13,6 +12,7 @@ #include "LambdaTask.hpp" #include "SpiderLib/Callback.hpp" #include "SpiderLib/CallbackMap.hpp" +#include "SpiderLib/NumberTypes.hpp" // qthing stuff // #include "" diff --git a/CLC-qthing/SimpleUART.hpp b/CLC-qthing/SimpleUART.hpp index 8ffd2d8..3d108cc 100644 --- a/CLC-qthing/SimpleUART.hpp +++ b/CLC-qthing/SimpleUART.hpp @@ -1,6 +1,6 @@ #pragma once -#include <cinttypes> +#include "SpiderLib/NumberTypes.hpp" diff --git a/CLC-qthing/SpiderLib/Callback.hpp b/CLC-qthing/SpiderLib/Callback.hpp index d637e17..561ec8f 100644 --- a/CLC-qthing/SpiderLib/Callback.hpp +++ b/CLC-qthing/SpiderLib/Callback.hpp @@ -3,7 +3,6 @@ // C++ system level // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? -// #include <cinttypes> #include <functional> // ESP32 specific diff --git a/CLC-qthing/SpiderLib/CallbackMap.hpp b/CLC-qthing/SpiderLib/CallbackMap.hpp index afe7728..6dfed5c 100644 --- a/CLC-qthing/SpiderLib/CallbackMap.hpp +++ b/CLC-qthing/SpiderLib/CallbackMap.hpp @@ -10,7 +10,8 @@ // #include "esp_log.h" // project specific -// #include "CyanBusCRC.hpp" +#include "SpiderLib/NumberTypes.hpp" + // qthing stuff // #include "" @@ -29,26 +30,26 @@ namespace SpiderLib { public: typedef std::function<void(Args...)> CallbackF; - CallbackMap(uint32_t maxPrefixLength = 16) : maxPrefixLength(maxPrefixLength) {}; + CallbackMap(u32 maxPrefixLength = 16) : maxPrefixLength(maxPrefixLength) {}; // Doesn't work with zero-length prefixes (callback won't be called but no error occurs) - void operator()(const uint8_t* const buffer, uint32_t length, Args&&... args) const { + void operator()(const u8* const buffer, u32 length, Args&&... args) const { - uint32_t _len = std::min(maxPrefixLength, length); + u32 _len = std::min(maxPrefixLength, length); char _prefix[_len + 1]; _prefix[_len] = 0x00; std::memcpy(_prefix, buffer, _len); std::string prefix(_prefix); - uint32_t bestMatchLEN = 0; + u32 bestMatchLEN = 0; CallbackF callback = NULL; for (auto it = callbackMap.begin(); it != callbackMap.end(); ++it) { // input buffer is >= current iterators magic string length if (_len >= it->first.length() && prefix.find(it->first) == 0) { - uint32_t matchLEN = it->first.length(); + u32 matchLEN = it->first.length(); if (matchLEN > bestMatchLEN) { bestMatchLEN = it->first.length(); callback = it->second; @@ -81,7 +82,7 @@ namespace SpiderLib { } private: - uint32_t maxPrefixLength; + u32 maxPrefixLength; mutable std::map<std::string, CallbackF> callbackMap; }; diff --git a/CLC-qthing/SpiderLib/NumberTypes.hpp b/CLC-qthing/SpiderLib/NumberTypes.hpp new file mode 100644 index 0000000..0cd1cd7 --- /dev/null +++ b/CLC-qthing/SpiderLib/NumberTypes.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include <cinttypes> + + +using u8 = uint8_t; +using i8 = int8_t; + +using u16 = uint16_t; +using i16 = int16_t; + +using u32 = uint32_t; +using i32 = int32_t; + +using u64 = uint64_t; +using i64 = int64_t; + +using f32 = float; +using f64 = double; +using f128 = long double; diff --git a/CLC-qthing/SpiderLib/SNTP.cpp b/CLC-qthing/SpiderLib/SNTP.cpp index 575ae29..9fa644f 100644 --- a/CLC-qthing/SpiderLib/SNTP.cpp +++ b/CLC-qthing/SpiderLib/SNTP.cpp @@ -12,10 +12,9 @@ #include <ctime> #include <cstring> #include <functional> -#include <cinttypes> // project specific -// #include "Metrics.hpp" +#include "SpiderLib/NumberTypes.hpp" /*extern "C" { diff --git a/CLC-qthing/SpiderLib/SNTP.hpp b/CLC-qthing/SpiderLib/SNTP.hpp index 2dc7d0d..517e6b8 100644 --- a/CLC-qthing/SpiderLib/SNTP.hpp +++ b/CLC-qthing/SpiderLib/SNTP.hpp @@ -4,11 +4,10 @@ // #include "driver/ledc.h" // C++ system level -// #include <cinttypes> #include <functional> // project specific -// #include "Metrics.hpp" +// #include "SpiderLib/NumberTypes.hpp" namespace SpiderLib { diff --git a/CLC-qthing/SpiderLib/Time.cpp b/CLC-qthing/SpiderLib/Time.cpp index f1785a6..4b71702 100644 --- a/CLC-qthing/SpiderLib/Time.cpp +++ b/CLC-qthing/SpiderLib/Time.cpp @@ -4,17 +4,17 @@ #include "esp_timer.h" // C++ system level -#include <cinttypes> +// #include <functional> // project specific -// #include "MyHeader.hpp" +#include "SpiderLib/NumberTypes.hpp" namespace SpiderLib { - uint32_t Time::s() { return (uint32_t)(esp_timer_get_time() / 1000000ULL); } - uint64_t Time::ms() { return (uint64_t)(esp_timer_get_time() / 1000ULL); } - uint64_t Time::us() { return (uint64_t) esp_timer_get_time(); } + u32 Time::s() { return (u32)(esp_timer_get_time() / 1000000ULL); } + u64 Time::ms() { return (u64)(esp_timer_get_time() / 1000ULL); } + u64 Time::us() { return (u64) esp_timer_get_time(); } } diff --git a/CLC-qthing/SpiderLib/Time.hpp b/CLC-qthing/SpiderLib/Time.hpp index 9ada8dc..ae4f78f 100644 --- a/CLC-qthing/SpiderLib/Time.hpp +++ b/CLC-qthing/SpiderLib/Time.hpp @@ -4,10 +4,10 @@ // #include "MyHeader.h" // C++ system level -#include <cinttypes> +// #include <functional> // project specific -// #include "MyHeader.hpp" +#include "SpiderLib/NumberTypes.hpp" namespace SpiderLib { @@ -15,9 +15,9 @@ namespace SpiderLib { class Time { public: - static uint32_t s(); - static uint64_t ms(); - static uint64_t us(); + static u32 s(); + static u64 ms(); + static u64 us(); }; } diff --git a/CLC-qthing/SpiderLib/UDP.cpp b/CLC-qthing/SpiderLib/UDP.cpp index 4f4e7f3..e63be3d 100644 --- a/CLC-qthing/SpiderLib/UDP.cpp +++ b/CLC-qthing/SpiderLib/UDP.cpp @@ -11,13 +11,15 @@ #include "lwip/sockets.h" #include "lwip/sys.h" +#include "SpiderLib/NumberTypes.hpp" + static const char* TAG = "udp-server"; static const in_port_t PORT = 4213; // rate-limits positive udp log messages; time in milliseconds -static const uint16_t loggingTimeout = 500; // TODO: make configurable?! +static const u16 loggingTimeout = 500; // TODO: make configurable?! static std::map<std::string, qthing::udpPacketCallback> packetCallbackMap; @@ -66,9 +68,9 @@ static void udp_server_task(void* pvParameters) { ESP_LOGI(TAG, "Waiting for data"); // This is for the rate limited logging only - uint32_t loggingBytes = 0; - uint16_t loggingPackets = 0; - uint32_t loggingLastMillis = qthing::millis(); + u32 loggingBytes = 0; + u16 loggingPackets = 0; + u32 loggingLastMillis = qthing::millis(); while (true) { struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6 @@ -102,7 +104,7 @@ static void udp_server_task(void* pvParameters) { } std::string payload_str(rx_buffer); - int16_t lenBestMatch = -1; + i16 lenBestMatch = -1; qthing::udpPacketCallback callback = NULL; for (auto it = packetCallbackMap.begin(); it != packetCallbackMap.end(); ++it) { if (len >= it->first.length() && payload_str.find(it->first) == 0) { @@ -112,7 +114,7 @@ static void udp_server_task(void* pvParameters) { } if (lenBestMatch > -1) { - qthing::udpPacket packet = {.sourceAddr = sourceAddr, .payload = rx_buffer, .length = (uint16_t)len}; + qthing::udpPacket packet = {.sourceAddr = sourceAddr, .payload = rx_buffer, .length = (u16)len}; callback(packet); } else { diff --git a/CLC-qthing/SpiderLib/UDP.hpp b/CLC-qthing/SpiderLib/UDP.hpp index 40e3bb9..29ce421 100644 --- a/CLC-qthing/SpiderLib/UDP.hpp +++ b/CLC-qthing/SpiderLib/UDP.hpp @@ -1,5 +1,7 @@ #pragma once +#include "SpiderLib/NumberTypes.hpp" + /* diff --git a/CLC-qthing/SpiderLib/Util.hpp b/CLC-qthing/SpiderLib/Util.hpp index c92d8ca..050321a 100644 --- a/CLC-qthing/SpiderLib/Util.hpp +++ b/CLC-qthing/SpiderLib/Util.hpp @@ -7,10 +7,9 @@ #include <vector> #include <string> #include <cstring> -#include <cinttypes> // project specific -// #include "MyHeader.hpp" +#include "SpiderLib/NumberTypes.hpp" namespace SpiderLib { @@ -23,13 +22,13 @@ namespace SpiderLib { template< template<typename> typename T> std::string join(T<std::string>& collection, const std::string& delimiter) { - uint32_t length = 0; + u32 length = 0; // caching this temporarily // TODO: do we need this or would the compiler be smart enough to cache it itself? // or couldn't he cache it itself because C++ is strict and it is a method-call? // questions over questions……… - uint32_t delimiterLength = delimiter.length(); + u32 delimiterLength = delimiter.length(); for (auto const& item : collection) length += item.length() + delimiterLength; // TODO: replace delimiterLength -> delimiter.length() ? @@ -41,7 +40,7 @@ namespace SpiderLib { for (auto const& item : collection) { - uint32_t len = item.length(); + u32 len = item.length(); std::memcpy(ptr, item.c_str(), len); ptr += len; diff --git a/CLC-qthing/device_main.cpp b/CLC-qthing/device_main.cpp index 334bb68..0a4d94f 100644 --- a/CLC-qthing/device_main.cpp +++ b/CLC-qthing/device_main.cpp @@ -10,6 +10,8 @@ #include "CyanLight.hpp" #include "SiliconTorch/FxCyanF.hpp" +#include "SpiderLib/NumberTypes.hpp" + // ### LIBS FOR TESTING ### #include <cstdlib> @@ -122,7 +124,7 @@ void device_main() { ctrl->setFrqRes(100, 19); - for (uint8_t i = 0; i < 100; i++) { + for (u8 i = 0; i < 100; i++) { bool _f = i % 2 == 0; @@ -149,13 +151,13 @@ void device_main() { float limit = 50.0f; while (true) { - for (uint8_t i = 0; i < limit; i++) { + for (u8 i = 0; i < limit; i++) { float pwm = i / limit; ctrl->setPWM(0, pwm*pwm); vTaskDelay(delay); } - for (uint8_t i = 0; i < limit; i++) { + for (u8 i = 0; i < limit; i++) { float pwm = i / limit; ctrl->setPWM(0, 1.0f - pwm*pwm); vTaskDelay(delay); -- GitLab