From 9f58f038e7e7f6259e365be71e67cc1353193dfc Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 15 Sep 2024 09:47:40 +0100 Subject: [PATCH 1/5] #208 #207 Remove SimpleTest, Move logging to TcMenuLog library, Add mbed SPI impl --- cmake/CMakeLists.txt | 4 +- library.json | 5 +- library.properties | 4 +- platformio-test.ini | 1 + platformio.ini | 1 + src/IoLogging.cpp | 84 -------- src/IoLogging.h | 220 --------------------- src/PlatformDetermination.h | 3 - src/PrintCompat.h | 239 ---------------------- src/ResistiveTouchScreen.cpp | 2 +- src/TextUtilities.cpp | 135 ------------- src/TextUtilities.h | 147 -------------- src/extras/SPIHelper.h | 56 +++++- src/testing/SimpleTest.cpp | 177 ----------------- src/testing/SimpleTest.h | 275 -------------------------- test/test_ioa_core/TextUtilsTests.cpp | 62 ------ 16 files changed, 65 insertions(+), 1350 deletions(-) delete mode 100644 src/IoLogging.cpp delete mode 100644 src/IoLogging.h delete mode 100644 src/PrintCompat.h delete mode 100644 src/TextUtilities.cpp delete mode 100644 src/TextUtilities.h delete mode 100644 src/testing/SimpleTest.cpp delete mode 100644 src/testing/SimpleTest.h delete mode 100644 test/test_ioa_core/TextUtilsTests.cpp diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 26054d6..d4e7175 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -3,11 +3,9 @@ add_library(IoAbstraction ../src/EepromAbstractionWire.cpp ../src/IoAbstraction.cpp ../src/IoAbstractionWire.cpp - ../src/IoLogging.cpp ../src/KeyboardManager.cpp ../src/ResistiveTouchScreen.cpp ../src/SwitchInput.cpp - ../src/TextUtilities.cpp ../src/wireHelpers.cpp ../src/pico/PicoDigitalIO.cpp ../src/pico/i2cWrapper.cpp @@ -19,7 +17,7 @@ target_compile_definitions(IoAbstraction ) target_include_directories(IoAbstraction PUBLIC - ${PROJECT_SOURCE_DIR}/IoAbstraction/src + ${PROJECT_SOURCE_DIR}/lib/IoAbstraction/src ) target_link_libraries(IoAbstraction PUBLIC diff --git a/library.json b/library.json index 0997319..6f05611 100644 --- a/library.json +++ b/library.json @@ -23,9 +23,12 @@ }, { "name": "TaskManagerIO" + }, + { + "name": "TcMenuLog" } ], - "version": "4.3.0", + "version": "4.4.0", "license": "Apache-2.0", "frameworks": "arduino, mbed", "platforms": "*", diff --git a/library.properties b/library.properties index b0340f2..2bea8f2 100644 --- a/library.properties +++ b/library.properties @@ -4,7 +4,7 @@ # name=IoAbstraction -version=4.3.0 +version=4.4.0 maintainer=https://www.thecoderscorner.com author=davetcc category=Other @@ -12,4 +12,4 @@ url=https://github.com/TcMenu/IoAbstraction sentence=Treat PCF8574, MCP23017 and Shift registers like pins, matrix keypad, touch screen handler, button press and rotary encoder management (switches) on any supported IO (including DfRobot & Joysticks) with event handling, interchangable AVR/I2C(AT24) EEPROMs. paragraph=Interchange between PCF8574, MCP23017, 74HC595, and regular pins. Fully debounced switches, rotary encoders, joystick encoder emulation (including on DfRobot), matrix keypads/keyboards, and touch screen input on any IO device that require no extra components in most cases. An EEPROM abstraction that works with AVR & I2C AT24x ROMs. Simple cross device btree collection. includes=IoAbstraction.h -depends=TaskManagerIO,SimpleCollections +depends=TaskManagerIO,SimpleCollections,TcMenuLog diff --git a/platformio-test.ini b/platformio-test.ini index 45db6c6..17ba079 100644 --- a/platformio-test.ini +++ b/platformio-test.ini @@ -6,6 +6,7 @@ extra_scripts = post:merge-bin.py test_build_src = true lib_deps = + TcMenuLog TaskManagerIO SimpleCollections diff --git a/platformio.ini b/platformio.ini index 269be48..1b86ae3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,6 +2,7 @@ framework = arduino lib_deps = + davetcc/TcMenuLogging davetcc/TaskManagerIO@^1.4.3 davetcc/SimpleCollections@^1.2.3 davetcc/LiquidCrystalIO@^1.4.3 diff --git a/src/IoLogging.cpp b/src/IoLogging.cpp deleted file mode 100644 index 18fb9ab..0000000 --- a/src/IoLogging.cpp +++ /dev/null @@ -1,84 +0,0 @@ - -/** - * @file IoLogging.h - * - * Some very basic logging utilities for any IoAbstraction user that log to a chosen serial interface. Turned on - * by un-commenting the define. Should NOT be used in production. - */ - -#include "IoLogging.h" -#include "TaskPlatformDeps.h" - -#ifdef IO_LOGGING_DEBUG - -unsigned int enabledLevels = IO_LOGGING_DEFAULT_LEVEL; - -void serlogHexDump(SerLoggingLevel level, const char *title, const void* data, size_t strlen) { - if(!serLevelEnabled(level)) return; - - logTimeAndLevel(title, level); - LoggingPort.println(); - - const auto str = (const uint8_t *) data; - static const char hexChar[] = { "0123456789ABCDEF" }; - for (size_t ii = 0; ii < strlen; ii++) { - char sz[4]; - sz[0] = hexChar[str[ii] >> 4]; - sz[1] = hexChar[str[ii] & 0x0f]; - sz[2] = ((ii % 8) == 7) ? '\n' : ' '; - sz[3] = 0; - LoggingPort.print(sz); - }; - LoggingPort.println(); -} - -const char* prettyLevel(SerLoggingLevel level) { - switch(level) { - case SER_WARNING: return "WRN"; - case SER_ERROR: return "ERR"; - case SER_DEBUG: return "DBG"; - case SER_TCMENU_INFO: return "TCM"; - case SER_TCMENU_DEBUG: return "TCD"; - case SER_NETWORK_INFO: return "NET"; - case SER_NETWORK_DEBUG: return "NTD"; - case SER_IOA_INFO: return "IOA"; - case SER_IOA_DEBUG: return "IOD"; - case SER_USER_1: return "U01"; - case SER_USER_2: return "U02"; - case SER_USER_3: return "U03"; - case SER_USER_4: return "U04"; - case SER_USER_5: return "U05"; - case SER_USER_6: return "U06"; - default: return "???"; - } -} - -const char* niceErrorCode(tm_internal::TmErrorCode code) { - switch(code) { - case tm_internal::TM_INFO_REALLOC: - return "mem"; - case tm_internal::TM_INFO_TASK_ALLOC: - return "alloc"; - case tm_internal::TM_INFO_TASK_FREE: - return "free"; - case tm_internal::TM_WARN_HIGH_SPINCOUNT: - return "spin"; - case tm_internal::TM_ERROR_FULL: - return "full"; - default: - case tm_internal::TM_ERROR_LOCK_FAILURE: - return "err"; - } -} - -void startTaskManagerLogDelegate() { - tm_internal::setLoggingDelegate([](tm_internal::TmErrorCode errorCode, int task) { - serlogF3(SER_IOA_DEBUG, "TMLog ", niceErrorCode(errorCode), task); - }); -} - -#ifdef BUILD_FOR_PICO_CMAKE -PrintfLogger LoggingPort; -#endif - -#endif diff --git a/src/IoLogging.h b/src/IoLogging.h deleted file mode 100644 index 6cbb796..0000000 --- a/src/IoLogging.h +++ /dev/null @@ -1,220 +0,0 @@ -#ifndef _IO_LOGGING_H_ -#define _IO_LOGGING_H_ - -/** - * @file IoLogging.h - * @brief Some very basic logging utilities for any IoAbstraction user that log to a chosen serial interface. Turned on - * by un-commenting the define. Should NOT be used in production. - */ - -#include "PlatformDetermination.h" - -// START user adjustable section. - -// the below definition controls logging, enable logging by either defining this build flag -// or uncommenting the line below. -//#define IO_LOGGING_DEBUG - -// These are the default levels that will be enabled when logging starts, you can add them at -// runtime using serEnableLevel(level, true/false) -#ifndef IO_LOGGING_DEFAULT_LEVEL -#define IO_LOGGING_DEFAULT_LEVEL (SER_WARNING|SER_ERROR|SER_IOA_INFO|SER_TCMENU_INFO|SER_NETWORK_INFO|SER_DEBUG|SER_USER_1) -#endif - -// END user adjustable section. - -/** - * This enumeration contains all the available logging levels, each logging level is a bit in the structure, and - * we assume there can be up to 15 levels. With 4 user levels available. - */ -enum SerLoggingLevel { - SER_WARNING = 0x0001, - SER_ERROR = 0x0002, - SER_DEBUG = 0x0004, - SER_TCMENU_INFO = 0x0008, - SER_NETWORK_INFO = 0x0010, - SER_IOA_INFO = 0x0020, - SER_USER_1 = 0x0040, - SER_USER_2 = 0x0080, - SER_USER_3 = 0x0100, - SER_USER_4 = 0x0200, - SER_USER_5 = 0x0400, - SER_USER_6 = 0x0800, - SER_TCMENU_DEBUG = 0x1000, - SER_NETWORK_DEBUG = 0x2000, - SER_IOA_DEBUG = 0x4000, - SER_LOG_EVERYTHING = 0xffff -}; - -#ifdef IO_LOGGING_DEBUG - -/** This uint16_t stores the enabled logging levels, don't use directly */ -extern unsigned int enabledLevels; - -#ifdef IOA_USE_MBED - -#include "PrintCompat.h" -#include -// -// On mbed you create an instance of this class called LoggingPort in your main class. -// see the mbed example. -// -class MBedLogger : public Print { -private: - FileHandle& serial; -public: - explicit MBedLogger(FileHandle& serialName) : serial(serialName) {} - - size_t write(uint8_t ch) override { - serial.write(&ch, 1); - return 1; - } - - size_t write(const char* sz) override { - auto len = strlen(sz); - serial.write(sz, len); - return len; - } -}; -extern MBedLogger LoggingPort; -// a couple of definitions here to avoid including headers, F() macro not needed on mbed -unsigned long millis(); -#define F(x) x -#define IOLOG_MBED_PORT_IF_NEEDED(tx, rx) BufferedSerial serPort(tx, rx);MBedLogger LoggingPort(serPort); -#define IOLOG_START_SERIAL serPort.set_baud(115200); -#elif defined(BUILD_FOR_PICO_CMAKE) -#include "PrintCompat.h" -#include -#include -#ifdef BUILD_PICO_FORCE_UART -class PrintfLogger : public Print { -private: -public: - size_t write(uint8_t ch) override { - uart_putc_raw(uart0, ch); - return 1; - } - - size_t write(const char* sz) override { - auto len = strlen(sz); - for(int i=0;i -#include -#include -#include typedef uint8_t pinid_t; #define pgm_read_byte_near(x) (*(x)) #else diff --git a/src/PrintCompat.h b/src/PrintCompat.h deleted file mode 100644 index def548d..0000000 --- a/src/PrintCompat.h +++ /dev/null @@ -1,239 +0,0 @@ -// -// Created by David Cherry on 24/07/2020. -// - -#ifndef IOA_PRINT_COMPAT_H -#define IOA_PRINT_COMPAT_H - -#include -#include -#include - -/** - * @file PrintCompat.h - * @brief Compatibility with the Arduino Print API for mbed boards, should never be included in an Arduino build - */ - -#ifdef IOA_USE_ARDUINO -# error "Print compatibility has been included on Arduino, this will cause problems, please report." -#endif - -// These are definitions of the mode in which the integer print can work, either decimal, hex or binary. -#define DEC 10 -#define HEX 16 -#define BIN 2 - -/** - * This is a print interface that is roughly compatible with the Arduino one, supporting printing of characters, - * strings, integers, float, boolean and double. In order to provide a class that supports Print you must implement - * at least write(char ch); - */ -class Print { -public: - /** - * this is the minimum that you must implement to provide the write interface. It writes a single character - * to the underlying stream. - * @param ch the character to write. - * @return returns 1 if written, otherwise 0. - */ - virtual size_t write(uint8_t ch) = 0; - - /** - * You can optionally override this function, it writes a whole string to the underlying stream, returning the - * number of characters written - * @param sz the string data to write, zero terminated - * @return the number of characters - */ - virtual size_t write(const char* sz) { - int written = 0; - while(*sz) { - write(*sz); - sz++; - written++; - } - return written; - } - - /** - * Prints a characcter to the stream without a newline - * @param ch the character to print. - */ - void print(char ch) { - write(ch); - } - - /** - * Prints a character to the stream followed by a newline. - * @param ch - */ - void println(char ch) { - write(ch); - write('\n'); - } - - /** - * Prints a zero terminated string to the stream - * @param sz the string to write. - */ - void print(const char* sz) { write(sz); } - - /** - * Prints a zero terminated string followed by newline to the stream - * @param sz the string to write - */ - void println(const char* sz) { - write(sz); - write('\n'); - } - - /** - * Prints an integer value, with an optional radix, default DEC, but either DEC, HEX or BIN - * @param val the numeric value to be printed - * @param radix the base, DEC, HEX or BIN - */ - void print(int val, int radix = DEC) { - char sz[33]; - itoa(val, sz, radix); - write(sz); - } - - /** - * Prints an integer value, with an optional radix, default DEC, but either DEC, HEX or BIN, the integer - * is followed by a new line character. - * @param val the numeric value to be printed - * @param radix the base DEC, HEX or BIN - */ - void println(int val, int radix = DEC) { - print(val, radix); - write('\n'); - } - - /** - * Prints an unsigned integer value, with an optional radix, default DEC, but either DEC, HEX or BIN - * @param val the numeric value to be printed - * @param radix the base, DEC, HEX or BIN - */ - void print(unsigned int val, int radix = DEC) { - char sz[33]; - itoa(int(val), sz, radix); - write(sz); - } - - /** - * Prints an integer value, with an optional radix, default DEC, but either DEC, HEX or BIN, the integer - * is followed by a new line character. - * @param val the numeric value to be printed - * @param radix the base DEC, HEX or BIN - */ - void println(unsigned int val, int radix = DEC) { - print(int(val), radix); - write('\n'); - } - - /** - * Prints a long value, with an optional radix, default DEC, but either DEC, HEX or BIN - * @param val the numeric value to be printed - * @param radix the base DEC, HEX or BIN - */ - void print(long val, int radix = DEC) { - print((int)val, radix); - } - - /** - * Prints a long value, with an optional radix, default DEC, but either DEC, HEX or BIN, the integer - * is followed by a new line character. - * @param val the numeric value to be printed - * @param radix the base DEC, HEX or BIN - */ - void println(long val, int radix = DEC) { - print((int)val, radix); - write('\n'); - } - - /** - * Prints an unsigned long value, with an optional radix, default DEC, but either DEC, HEX or BIN - * @param val the numeric value to be printed - * @param radix the base, DEC, HEX or BIN - */ - void print(unsigned long val, int radix = DEC) { - char sz[33]; - itoa(int(val), sz, radix); - write(sz); - } - - /** - * Prints an unsigned long value, with an optional radix, default DEC, but either DEC, HEX or BIN - * @param val the numeric value to be printed - * @param radix the base, DEC, HEX or BIN - */ - void println(unsigned long val, int radix = DEC) { - print(val, radix); - write('\n'); - } - - /** - * Prints a double value to a number of decimal places (maximum supported decimal places is 6). - * @param dbl the double value to print - * @param dp the number of decimal places, default 3. Max 6. - */ - void print(double dbl, int dp = 3) { - char sz[32]; - sz[0]=0; - fastftoa(sz, (float)dbl, dp, sizeof sz); - write(sz); - } - - /** - * Prints a double value to a number of decimal places (maximum supported decimal places is 19). This is followed - * by a newline. - * @param dbl the double value to print - * @param dp the number of decimal places, default 3. Max 19. - */ - void println(double dbl, int dp = 3) { - print(dbl, dp); - write('\n'); - } - - /** - * Prints a boolean value, either true or false. - * @param b the boolean to print. - */ - void print(bool b) { - write(b ? "true" : "false"); - } - - /** - * Prints a boolean value, either true or false, followed by a newline. - * @param b the boolean to print. - */ - void println(bool b) { - write(b ? "true\n" : "false\n"); - } - - /** - * Print a newline character. - */ - void println() { - write('\n'); - } - - // - // the following are to handle cases where write is called with basically an invalid type. I'd personally - // of liked not to port this, but too much code relies on it being there. - // - - inline size_t write(short t) { return write((uint8_t)t); } - inline size_t write(unsigned short t) { return write((uint8_t)t); } - inline size_t write(int t) { return write((uint8_t)t); } - inline size_t write(unsigned int t) { return write((uint8_t)t); } - inline size_t write(long t) { return write((uint8_t)t); } - inline size_t write(unsigned long t) { return write((uint8_t)t); } - // Enable write(char) to fall through to write(uint8_t) - inline size_t write(char c) { return write((uint8_t) c); } - inline size_t write(int8_t c) { return write((uint8_t) c); } -}; - -//forward definition of yield() function -void yield(); - -#endif //IOA_PRINT_COMPAT_H diff --git a/src/ResistiveTouchScreen.cpp b/src/ResistiveTouchScreen.cpp index 5541be6..cb1c871 100644 --- a/src/ResistiveTouchScreen.cpp +++ b/src/ResistiveTouchScreen.cpp @@ -11,7 +11,7 @@ namespace iotouch { } if (ticks++ > accel) { ticks = 0; - accel = max(minTicks, uint8_t(accel / 2U)); + accel = internal_max(minTicks, uint8_t(accel / 2U)); return true; } return false; diff --git a/src/TextUtilities.cpp b/src/TextUtilities.cpp deleted file mode 100644 index 7d5ad63..0000000 --- a/src/TextUtilities.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry). - * This product is licensed under an Apache license, see the LICENSE file in the top-level directory. - */ - -#include -#include "TextUtilities.h" - -void appendChar(char* str, char val, int len) { - int i = 0; - len -= 2; - while(str[i] && len) { - --len; - ++i; - } - str[i++] = val; - str[i] = (char)0; -} - -long dpToDivisor(int dp) { - switch(dp) { - case 8: return 100000000L; - case 7: return 10000000L; - case 6: return 1000000L; - case 5: return 100000; - case 4: return 10000; - case 3: return 1000; - case 2: return 100; - case 1: return 10; - case 0: return 1; - default: - case 9: return 1000000000L; - } -} - -long valueToSignificantPlaces(unsigned long value, bool negative) { - unsigned long divisor = 10U; - int places = 1; - while(value > divisor) { - divisor *= 10U; - places = places + 1; - } - return negative ? (places + 1) : places; -} - -void ltoaClrBuff(char* str, long val, uint8_t dp, char padChar, int len) { - str[0]=0; - fastltoa_mv(str, val, dpToDivisor(dp), padChar, len); -} - -void fastltoa(char* str, long val, uint8_t dp, char padChar, int len) { - fastltoa_mv(str, val, dpToDivisor(dp), padChar, len); -} - -void fastltoa_mv(char* str, long val, long divisor, char padChar, int len) { - int i=0; - len -=2; - - if (val < 0) { - val = abs(val); - appendChar(str, '-', len); - } - - val %= divisor; - divisor /= 10; - - while(str[i] && i < len) ++i; - - bool hadNonZeroChar = false; - bool zeroPad = padChar != 0; - - while(divisor > 9 && i < len) { - str[i] = (char)((val / divisor) + '0'); - hadNonZeroChar |= (str[i] != '0'); - if(zeroPad && !hadNonZeroChar) str[i] = padChar; - if(zeroPad || hadNonZeroChar) ++i; - val %= divisor; - divisor /= 10; - } - str[i++] = '0' + (val % 10); - str[i] = (char)0; -} - -void fastftoa(char* sz, float fl, int dp, int strSize) { - bool neg = false; - if(fl < 0.0F) { - fl = fl * -1.0F; - neg = true; - } - - // here we get the whole and fractonal parts, knowing its always positive, lastly, we - // multiply it up by decimal places to turn it into an int, then we can present it as "[-]whole.fraction" - auto whole = (int32_t)fl; - fl = fl - float(whole); - auto fraction = int32_t(fl * (float)dpToDivisor(dp)); - - if(neg) appendChar(sz, '-', strSize); - fastltoa(sz, whole, 9, NOT_PADDED, strSize); - appendChar(sz, '.', strSize); - fastltoa(sz, fraction, dp, '0', strSize); -} - -char hexChar(uint8_t val) { - if(val < 10) return char(val + '0'); - return char(val - 10) + 'A'; -} - - -void intToHexString(char* buffer, size_t bufferSize, unsigned int input, int digits, bool with0x) { - if(with0x) { - buffer[0] = '0'; - buffer[1] = 'x'; - bufferSize -= 2; - buffer += 2; - } - - if(digits >= bufferSize) { - digits = bufferSize - 1; - } - - int i = 0; - while(bufferSize && i < digits) { - buffer[(digits-1) - i] = hexChar(input & 0x0f); - input = input >> 4; - i++; - } - buffer[i] = 0; -} - -uint8_t hexValueOf(char val) { - if(val >= '0' && val <= '9') return val - '0'; - val = (char)toupper(val); - if(val >= 'A' && val <= 'F') return val - ('A' - 10); - return 0; -} \ No newline at end of file diff --git a/src/TextUtilities.h b/src/TextUtilities.h deleted file mode 100644 index 73ea0bd..0000000 --- a/src/TextUtilities.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry). - * This product is licensed under an Apache license, see the LICENSE file in the top-level directory. - */ - -#ifndef IOABSTRACTION_TEXTUTILITIES_H -#define IOABSTRACTION_TEXTUTILITIES_H - -#include - -/** - * @file TextUtilities.h - * @brief A series of text and numeric utilities useful for many purposes. - */ - -/** - * appends a character at the end of the string, if there is space according to len - */ -void appendChar(char* str, char val, int len); - -/** - * used with the below ltoa functions, pass this in padChar when not padded. - */ -#define NOT_PADDED 0 - -/** - * A fast long to ascii function that more feature complete than the standard library. - * Supports zero padding and maximum number of decimal places. This version always - * starts at position 0 in the provided buffer and goes up to position len always leaving - * space for a terminator. The other two versions below support appending instead. - * - * @param str the buffer to be output to - * @param val the value to be converted - * @param divisor the power of 10 largest value (eg 10000, 1000000L etc) - * @param padChar the character to pad with (or NOT_PADDED which is 0) - * @param len the length of the buffer passed in, it will not be exceeded. - */ -void ltoaClrBuff(char* str, long val, uint8_t dp, char padChar, int len); - -/** - * A fast long to ascii function that more feature complete than the standard library. - * Supports zero padding and the largest actual value to use normally a power of 10. - * Absolute largest value displayable is 1000000000 - 1. NOTE that this function will - * append at the end of the current string. Use ltoaClrBuff to start at position 0. - * This call will not exceed the length provided and will properly terminate the string. - * - * @param str the buffer to be appended to - * @param val the value to be converted - * @param divisor the power of 10 largest value (eg 10000, 1000000L etc) - * @param padChar the character to pad with (or NOT_PADDED which is 0) - * @param len the length of the buffer passed in, it will not be exceeded. - */ -void fastltoa_mv(char* str, long val, long divisor, char padChar, int len); - -/** - * A fast long to ascii function that more feature complete than the standard library. - * Supports zero padding and the number of decimal places to use. Maximum number of - * decimal places is 9. NOTE that this function will append at the end of the current - * string and will not exceed the length provided, it will also properly terminate the - * string. Use ltoaClrBuff to start at position 0 in the buffer. - * - * @param str the buffer to be appended to - * @param val the value to be converted - * @param dp the number of decimal places allowed - * @param padChar the character to pad with (or NOT_PADDED which is 0) - * @param len the length of the buffer passed in, it will not be exceeded. - */ -void fastltoa(char* str, long val, uint8_t dp, char padChar, int len); - -/** - * A very simple floating point string function based on the fastltoa above. It can print - * floating point values up to 9 whole digits and 9 decimal places. Note this function - * appends the floating point value at the end of the string, to put the value at the - * beginning, ensure the string is zero length. - * @param sz the string to append to, - * @param fl the float to convert - * @param dp the numer of decimal places (max 9) - * @param strSize the string maximum length (usually from sizeof) - */ -void fastftoa(char* sz, float fl, int dp, int strSize); - -/** - * converts decimal places into a suitable divisor, eg: 2 -> 100, 4 -> 10000 - */ -long dpToDivisor(int dp); - -/** - * Indicates how many integers are needed to represent the value and negative flag if provided - * @param value the value to represent as unsigned. - * @param negative if the value is negative - * @return the number of characters including the sign needed - */ -long valueToSignificantPlaces(unsigned long value, bool negative); - -/** - * Get the hex equivalent of a single digit, input must be between 0 and 15 - * @param val the input unsigned integer between 0 and 15 - * @return a hex character from 0..F - */ -char hexChar(uint8_t val); - -/** - * Get the integer representation of a hex digit, between 0..F - * @param val the input character - * @return the numeric representation. - */ -uint8_t hexValueOf(char val); - -/** - * Get the hex string for a number to a given number of fixed places, EG 4 digits. You can optionally include the - * '0x' at the beginning. - * @param buffer the buffer to copy into - * @param bufferSize the size of the buffer - * @param input the input number - * @param digits the number of FIXED digits - * @param with0x if 0x should be included at the beginning - */ -void intToHexString(char* buffer, size_t bufferSize, unsigned int input, int digits, bool with0x); - -/** - * Ensure that a float is always positive. - * @param f1 the float that could be positive or negative - * @return the positive version of the float. - */ -inline float tcFltAbs(float f1) { - return f1 > 0.0F ? f1 : -f1; -} - -#if defined(IOA_USE_MBED) || defined(BUILD_FOR_PICO_CMAKE) -#define strcmp_P(x,y) strcmp(x,y) -#define strncpy_P(x,y,z) strncpy(x,y,z) -#define strcpy_P(x,y) strcpy(x,y) -#define strlen_P(x) strlen(x) -#define highByte(x) ((x) >> 8) -#define lowByte(x) ((x) & 0xff) -#define ltoa(a,b,c) itoa(a,b,c) -# ifndef min -# define min(x, y) (((x) < (y))?(x):(y)) -# define max(x, y) (((x) > (y))?(x):(y)) -# endif //TCMENU_MBED_NO_MINMAX -#endif // IOA_USE_MBED - -#ifdef IOA_ARDUINO_MBED -#define ltoa(a,b,c) itoa(a,b,c) -#endif - -#endif //IOABSTRACTION_TEXTUTILITIES_H diff --git a/src/extras/SPIHelper.h b/src/extras/SPIHelper.h index cb6ceb3..f018600 100644 --- a/src/extras/SPIHelper.h +++ b/src/extras/SPIHelper.h @@ -101,8 +101,62 @@ class SPIWithSettings { return written == len; } }; +#elif __MBED__ +#define TC_SPI_WRITE_AVAILABLE +class SPIWithSettings { +private: + SPI* spiBus; + uint32_t speed; + pinid_t csPin = 0; + bool initializedYet = false; +public: + SPIWithSettings(SPI* bus, pinid_t cs) : spiBus(bus), speed(10000000), csPin(cs) {} + SPIWithSettings(SPI* bus, pinid_t cs, uint32_t speed) : spiBus(bus), speed(speed), csPin(cs) {} + SPIWithSettings(const SPIWithSettings&) = default; + SPIWithSettings& operator=(const SPIWithSettings&)=default; + + void init() { + internalDigitalDevice().pinMode(csPin, OUTPUT); + internalDigitalDevice().digitalWrite(csPin, HIGH); + initializedYet=true; + } + + void waitABit() { + asm volatile("nop \n nop \n nop"); + } + + void waitAndActiveCS() { + if(!initializedYet) { + init(); + } + + internalDigitalDevice().digitalWrite(csPin, LOW); + waitABit(); + } + + void waitAndDeactivateCS() { + waitABit(); + internalDigitalDevice().digitalWrite(csPin, HIGH); + waitABit(); + } + + bool write(const uint8_t* data, size_t size) { + waitAndActiveCS(); + char sz[1]; + int written = spiBus->write((const char*)data, size, sz, 0); + waitAndDeactivateCS(); + return written == size; + } + + bool transferSPI(uint8_t* rdwr, size_t len) { + waitAndActiveCS(); + int written = spiBus->write((const char*)rdwr, len, (char*)rdwr, len); + waitAndDeactivateCS(); + return written == len; + } +}; #else -#error "Not implemented yet for mbed" +#error "Not implemented yet for chosen platform" #endif #endif //IOABSTRACTION_SPIHELPER_H diff --git a/src/testing/SimpleTest.cpp b/src/testing/SimpleTest.cpp deleted file mode 100644 index c7730f4..0000000 --- a/src/testing/SimpleTest.cpp +++ /dev/null @@ -1,177 +0,0 @@ - -#include "../IoAbstraction.h" -#include "SimpleTest.h" -#include "../IoLogging.h" -#include "TextUtilities.h" -#include - -namespace SimpleTest { - - const char* niceStatus(TestStatus s) { - switch(s) { - case NOT_RUN: - return "Not run"; - case RUNNING: - return "Running"; - case FAILED: - return "Failed"; - case PASSED: - return "Passed"; - case IGNORED: - return "Ignored"; - default: - return "????"; - } - } - - UnitTestExecutor *UnitTestExecutor::currentlyRunning = nullptr; - - void UnitTestExecutor::exec() { - currentlyRunning = this; - testStatus = RUNNING; - serlogF2(SER_DEBUG, "Starting test ", testName); - setup(); - performTest(); - teardown(); - if (testStatus != FAILED) { - testStatus = PASSED; - } - serlogF3(SER_DEBUG, "Test ", testName, niceStatus(testStatus)); - currentlyRunning = nullptr; - } - - void UnitTestExecutor::setFailed(PGM_TYPE file, int line, const char *reason) { - testStatus = FAILED; - failureReason.withFileAndLine(file, line); - } - - void UnitTestExecutor::init(const char *name, bool ignored) { - testName = name; - if (ignored) { - testStatus = IGNORED; - } else { - TestManager::getInstance()->addTest(this); - } - } - - TestManager* TestManager::instance = nullptr; - - void TestManager::printSummary() { - int total = testsRecorded.count(); - int ignored = 0; - int failed = 0; - int passed = 0; - int unknown = 0; - - for (auto tst: testsRecorded) { - if (tst.getTest()->getTestStatus() == PASSED) passed++; - else if (tst.getTest()->getTestStatus() == IGNORED) ignored++; - else if (tst.getTest()->getTestStatus() == SimpleTest::FAILED) failed++; - else unknown++; - } - - if (unknown == 0) { - char sz[50]; - strncpy(sz, "total=", sizeof sz); - fastltoa(sz, total, 5, NOT_PADDED, sizeof sz); - strncat(sz, ", passed=", sizeof(sz) - strlen(sz) - 1); - fastltoa(sz, passed, 5, NOT_PADDED, sizeof sz); - strncat(sz, ", failed=", sizeof(sz) - strlen(sz) - 1); - fastltoa(sz, failed, 5, NOT_PADDED, sizeof sz); - strncat(sz, ", ignored=", sizeof(sz) - strlen(sz) - 1); - fastltoa(sz, ignored, 5, NOT_PADDED, sizeof sz); - serlogF2(SER_DEBUG, "Tests finished - ", sz); - } - - if(failed > 0) { - serlogF(SER_DEBUG, "T E S T S F A I L E D") - } - } - - void TestManager::begin() { - serlogF(SER_DEBUG, "==== 8< ==== 8< ==== START EXECUTION ==== 8< ==== 8< ===="); - serlogF3(SER_DEBUG, "Starting test execution on ", testsRecorded.count(), "tests"); - currentIndex = 0; - needsSummary = true; - - if(serLevelEnabled(SER_IOA_DEBUG)) { - serlogF(SER_IOA_DEBUG, "The following tests were added"); - for(auto t : testsRecorded) { - serlogF2(SER_IOA_DEBUG, "Test: ", t.getTest()->getTestName()) - } - } - } - - void TestManager::runLoop() { - if((bsize_t)currentIndex < testsRecorded.count()) { - auto t = testsRecorded.itemAtIndex(currentIndex); - if (t->getTest()->getTestStatus() != IGNORED && (filterPredicate == nullptr || filterPredicate(t->getTest()))) { - t->getTest()->exec(); - } - currentIndex = currentIndex + 1; - } else if(needsSummary) { - needsSummary = false; - printSummary(); - } - } - - TestManager *TestManager::getInstance() { - if(instance == nullptr) { - instance = new TestManager(); - } - return instance; - } -} - -namespace STestInternal { - void assertBoolInternal(PGM_TYPE file, int line, bool valid, const char* reason) { - auto current = SimpleTest::UnitTestExecutor::getCurrentTest(); - if(current == nullptr || current->getTestStatus() != SimpleTest::RUNNING) return; - - if(!valid) { - current->setFailed(file, line, reason); - serlogF4(SER_DEBUG, "Assertion failure at ", file, ", line", line ); - serlogF2(SER_DEBUG, "Detail: ", reason); - } - } - - void assertFloatInternal(PGM_TYPE file, int line, float x, float y, float allowable) { - auto current = SimpleTest::UnitTestExecutor::getCurrentTest(); - if(current == nullptr || current->getTestStatus() != SimpleTest::RUNNING) return; - - if(tcFltAbs(x - y) > allowable) { - current->setFailed(file, line, "flt!="); - serlogF4(SER_DEBUG, "Assertion failure at ", file, ", line", line ); - serlogF4(SER_DEBUG, "Detail: ", x, "==", y); - } - } - - void internalEquality(PGM_TYPE file, int line, bool eq, uint32_t x, uint32_t y, const char* how) { - auto current = SimpleTest::UnitTestExecutor::getCurrentTest(); - if(current == nullptr || current->getTestStatus() != SimpleTest::RUNNING) return; - - if(!eq) { - current->setFailed(file, line, how); - serlogF4(SER_DEBUG, "Assertion failure at ", file, ", line", line); - serlogF4(SER_DEBUG, "Details: ", y, how, x); - } - } - - void assertStringInternal(PGM_TYPE file, int line, const char* x, const char* y) { - auto current = SimpleTest::UnitTestExecutor::getCurrentTest(); - if(current == nullptr || current->getTestStatus() != SimpleTest::RUNNING) return; - - if(strcmp(x, y) != 0) { - current->setFailed(file, line, "=="); - serlogF4(SER_DEBUG, "Assertion failure at ", file, ", line", line); - serlogF4(SER_DEBUG, "Details: ", x, "eq", y); - } - } - - void failInternal(PGM_TYPE file, int line, const char* reason) { - auto current = SimpleTest::UnitTestExecutor::getCurrentTest(); - if(current == nullptr || current->getTestStatus() != SimpleTest::RUNNING) return; - current->setFailed(file, line, "fail()"); - serlogF4(SER_DEBUG, "Assertion failure at ", file, line, "fail() was called"); - } -} \ No newline at end of file diff --git a/src/testing/SimpleTest.h b/src/testing/SimpleTest.h deleted file mode 100644 index 4c84d6b..0000000 --- a/src/testing/SimpleTest.h +++ /dev/null @@ -1,275 +0,0 @@ -#ifndef IOA_SIMPLE_TEST_H -#define IOA_SIMPLE_TEST_H - -/** - * @file SimpleTest.h - a very simple test framework for all platforms that IoAbstraction supports using testmanager as - * the executor queue. This is enough of a test framework for me to test my libraries, it may well be enough for you - * as well, but it is far from complete. Unfortunately, aunit just does not work on the boards I need to test on, I've - * excused it for a long time, but now it's more than half and will get worse as more boards move to the API. This - * replaces enough to just about do the job for our stuff. - */ - -#include -#include -#include -#include - -#define FAIL_REASON_SIZE 32 - -#ifdef __AVR__ -#include -#define FromPgm(x) F(x) -#define PGM_TYPE const __FlashStringHelper* -#else -#define FromPgm(x) (x) -#define PGM_TYPE const char* -#endif - -namespace SimpleTest { - - enum TestStatus { - NOT_RUN, RUNNING, FAILED, PASSED, IGNORED - }; - - const char* niceStatus(TestStatus s); - - class FailureInfo { - private: - PGM_TYPE file; - int line = 0; - public: - FailureInfo() {} - void withFileAndLine(PGM_TYPE f, int l) { - file = f; - line = l; - } - }; - - class UnitTestExecutor { - private: - static UnitTestExecutor *currentlyRunning; - TestStatus testStatus = NOT_RUN; - FailureInfo failureReason; - const char* testName; - public: - void init(const char* name, bool ignored = false); - - virtual void performTest() = 0; - - TestStatus getTestStatus() const { return testStatus; } - const char* getTestName() const { return testName; } - - void exec(); - void setFailed(PGM_TYPE file, int line, const char* reason); - - virtual void setup() {} - virtual void teardown() {} - - static UnitTestExecutor* getCurrentTest() { - return currentlyRunning; - } - }; - - class ExecutionWithId { - private: - uint16_t key; - UnitTestExecutor* executor; - public: - ExecutionWithId(): key(-1), executor(nullptr) {} - ExecutionWithId(const ExecutionWithId& other) = default; - ExecutionWithId& operator=(const ExecutionWithId& other) = default; - ExecutionWithId(uint16_t key, UnitTestExecutor* exec): key(key), executor(exec) {} - - uint16_t getKey() const { return key; } - UnitTestExecutor* getTest() { return executor; } - }; - - /** - * Implement this predicate to be able to filter out tests based on the name or any other parameter. - * You are given a reference to the test and can return true = run test, false = dont run. - */ - typedef bool (*TestFilterPredicate)(UnitTestExecutor* theTest); - - class TestManager { - private: - BtreeList testsRecorded; - static TestManager* instance; - int currentIndex = 0; - bool needsSummary = true; - TestFilterPredicate filterPredicate = nullptr; - - TestManager(): testsRecorded(32) {} - - public: - static TestManager* getInstance(); - - void begin(); - - void runLoop(); - - void addTest(UnitTestExecutor* t) { - testsRecorded.add(ExecutionWithId(testsRecorded.count(), t)); - } - - void printSummary(); - - void setTestFilterPredicate(TestFilterPredicate predicate) { - filterPredicate = predicate; - } - }; - - inline void startTesting() { - TestManager::getInstance()->begin(); - } -} - -namespace STestInternal { - - void internalEquality(PGM_TYPE file, int line, bool success, uint32_t x, uint32_t y, const char *how); - - void assertStringInternal(PGM_TYPE file, int line, const char *x, const char *y); - - void failInternal(PGM_TYPE file, int line, const char *reason); - - void assertBoolInternal(PGM_TYPE file, int line, bool valid, const char *reason); - - void assertFloatInternal(PGM_TYPE file, int line, float x, float y, float allowable); - - inline void assertEqualityInternal(PGM_TYPE file, int line, short x, short y) { - internalEquality(file, line, x == y, x, y, "=="); - } - inline void assertEqualityInternal(PGM_TYPE file, int line, unsigned short x, unsigned short y) { - internalEquality(file, line, x == y, x, y, "=="); - } - - inline void assertEqualityInternal(PGM_TYPE file, int line, int x, int y) { - internalEquality(file, line, x == y, x, y, "=="); - } - inline void assertEqualityInternal(PGM_TYPE file, int line, unsigned int x, unsigned int y) { - internalEquality(file, line, x == y, x, y, "=="); - } - - inline void assertEqualityInternal(PGM_TYPE file, int line, long x, long y) { - internalEquality(file, line, x == y, x, y, "=="); - } - inline void assertEqualityInternal(PGM_TYPE file, int line, unsigned long x, unsigned long y) { - internalEquality(file, line, x == y, x, y, "=="); - } - - inline void assertNonEqualityInternal(PGM_TYPE file, int line, short x, short y) { - internalEquality(file, line, x != y, x, y, "!="); - } - inline void assertNonEqualityInternal(PGM_TYPE file, int line, unsigned short x, unsigned short y) { - internalEquality(file, line, x != y, x, y, "!="); - } - - inline void assertNonEqualityInternal(PGM_TYPE file, int line, int x, int y) { - internalEquality(file, line, x != y, x, y, "!="); - } - inline void assertNonEqualityInternal(PGM_TYPE file, int line, unsigned int x, unsigned int y) { - internalEquality(file, line, x != y, x, y, "!="); - } - - inline void assertNonEqualityInternal(PGM_TYPE file, int line, long x, long y) { - internalEquality(file, line, x != y, x, y, "!="); - } - inline void assertNonEqualityInternal(PGM_TYPE file, int line, unsigned long x, unsigned long y) { - internalEquality(file, line, x != y, x, y, "!="); - } - - - inline void assertLessInternal(PGM_TYPE file, int line, short x, short y) { - internalEquality(file, line, y < x, x, y, "<"); - } - inline void assertLessInternal(PGM_TYPE file, int line, unsigned short x, unsigned short y) { - internalEquality(file, line, y < x, x, y, "<"); - } - inline void assertLessInternal(PGM_TYPE file, int line, int x, int y) { - internalEquality(file, line, y < x, x, y, "<"); - } - inline void assertLessInternal(PGM_TYPE file, int line, unsigned int x, unsigned int y) { - internalEquality(file, line, y < x, x, y, "<"); - } - inline void assertLessInternal(PGM_TYPE file, int line, long x, long y) { - internalEquality(file, line, y < x, x, y, "<"); - } - inline void assertLessInternal(PGM_TYPE file, int line, unsigned long x, unsigned long y) { - internalEquality(file, line, y < x, x, y, "<"); - } - - inline void assertMoreInternal(PGM_TYPE file, int line, short x, short y) { - internalEquality(file, line, y > x, x, y, ">"); - } - inline void assertMoreInternal(PGM_TYPE file, int line, unsigned short x, unsigned short y) { - internalEquality(file, line, y > x, x, y, ">"); - } - inline void assertMoreInternal(PGM_TYPE file, int line, int x, int y) { - internalEquality(file, line, y > x, x, y, ">"); - } - inline void assertMoreInternal(PGM_TYPE file, int line, unsigned int x, unsigned int y) { - internalEquality(file, line, y > x, x, y, ">"); - } - inline void assertMoreInternal(PGM_TYPE file, int line, long x, long y) { - internalEquality(file, line, y > x, x, y, ">"); - } - inline void assertMoreInternal(PGM_TYPE file, int line, unsigned long x, unsigned long y) { - internalEquality(file, line, y > x, x, y, ">"); - } - - // pointers - - inline void assertEqualityInternal(PGM_TYPE file, int line, const void* x, const void* y) { - internalEquality(file, line, x == y, (int)x, (int)y, "=="); - } - - inline void assertNonEqualityInternal(PGM_TYPE file, int line, const void* x, const void* y) { - internalEquality(file, line, x != y, (int)x, (int)y, "!="); - } - - inline void assertEqualityInternal(PGM_TYPE file, int line, const char* x, const char* y) { - assertStringInternal(file, line, x, y); - } -} - -#define assertTrue(actual) STestInternal::assertBoolInternal(FromPgm(__FILE__), __LINE__, actual, "True") -#define assertFalse(actual) STestInternal::assertBoolInternal(FromPgm(__FILE__), __LINE__, !(actual), "False") -#define assertEquals(expected, actual) STestInternal::assertEqualityInternal(FromPgm(__FILE__), __LINE__, expected, actual) -#define assertNotEquals(expected, actual) STestInternal::assertNonEqualityInternal(FromPgm(__FILE__), __LINE__, expected, actual) -#define assertLessThan(expected, actual) STestInternal::assertLessInternal(FromPgm(__FILE__), __LINE__, expected, actual) -#define assertMoreThan(expected, actual) STestInternal::assertMoreInternal(FromPgm(__FILE__), __LINE__, expected, actual) -#define assertStringEquals(expected, actual) STestInternal::assertStringInternal(FromPgm(__FILE__), __LINE__, expected, actual) -#define assertFloatNear(expected, actual, allowable) STestInternal::assertFloatInternal(FromPgm(__FILE__), __LINE__, expected, actual, allowable) -#define fail(reason) STestInternal::failInternal(FromPgm(__FILE__), __LINE__, reason) - -#define testi(name, ignored) \ -class UnitTest_##name : public SimpleTest::UnitTestExecutor {\ -public:\ - UnitTest_##name();\ - void performTest() override;\ -} unitTest_##name##_instance;\ -UnitTest_##name :: UnitTest_##name() {\ - init(#name, ignored); \ -}\ -void UnitTest_##name::performTest() - -#define testFi(testClass, name, ignored) \ -class testClass ## _ ## name : public testClass {\ -public:\ - testClass ## _ ## name();\ - void performTest() override;\ -} testClass ## _ ## name ## _instance;\ -testClass ## _ ## name :: testClass ## _ ## name() {\ - init(#name, ignored); \ -}\ -void testClass ## _ ## name :: performTest() - -#define test(name) testi(name, false) -#define testF(clazz, name) testFi(clazz, name, false) - -#ifdef IOA_USE_ARDUINO -#define DEFAULT_TEST_RUNLOOP void loop() { TestManager::getInstance()->runLoop(); } -#else -#define DEFAULT_TEST_RUNLOOP int main() { setup(); while(1) {TestManager::getInstance()->runLoop();} } -#endif //IOA_USE_ARDUINO - -#endif //IOA_SIMPLE_TEST_H diff --git a/test/test_ioa_core/TextUtilsTests.cpp b/test/test_ioa_core/TextUtilsTests.cpp deleted file mode 100644 index e4a3478..0000000 --- a/test/test_ioa_core/TextUtilsTests.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -#include -#include - -void testTcUtilIntegerConversions() { - char szBuffer[20]; - - // first check the basic cases for the version that always starts at pos 0 - strcpy(szBuffer, "abc"); - ltoaClrBuff(szBuffer, 1234, 4, ' ', sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "1234"); - ltoaClrBuff(szBuffer, 907, 4, ' ', sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, " 907"); - ltoaClrBuff(szBuffer, 22, 4, '0', sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "0022"); - ltoaClrBuff(szBuffer, -22, 4, '0', sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "-0022"); - ltoaClrBuff(szBuffer, -93, 2, NOT_PADDED, sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "-93"); - ltoaClrBuff(szBuffer, 0, 4, NOT_PADDED, sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "0"); - - // and now test the appending version with zero padding - strcpy(szBuffer, "val = "); - fastltoa(szBuffer, 22, 4, '0', sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "val = 0022"); - - // and now test the appending version with an absolute divisor. - strcpy(szBuffer, "val = "); - fastltoa_mv(szBuffer, 22, 1000, '0', sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "val = 022"); - - // and lasty try the divisor version without 0. - strcpy(szBuffer, "val = "); - fastltoa_mv(szBuffer, 22, 10000, NOT_PADDED, sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "val = 22"); - - // and now try something bigger than the divisor - strcpy(szBuffer, "val = "); - fastltoa_mv(szBuffer, 222222, 10000, NOT_PADDED, sizeof(szBuffer)); - TEST_ASSERT_EQUAL_STRING(szBuffer, "val = 2222"); -} - -void testTcUtilHexCoversions() { - char szBuffer[20]; - TEST_ASSERT_EQUAL('0', hexChar(0)); - TEST_ASSERT_EQUAL('9', hexChar(9)); - TEST_ASSERT_EQUAL('A', hexChar(10)); - TEST_ASSERT_EQUAL('F', hexChar(15)); - - intToHexString(szBuffer, sizeof szBuffer, 0xfade, 4, true); - TEST_ASSERT_EQUAL_STRING("0xFADE", szBuffer); - - intToHexString(szBuffer, sizeof szBuffer, 0x0000, 4, true); - TEST_ASSERT_EQUAL_STRING("0x0000", szBuffer); - - intToHexString(szBuffer, 6, 0xFFFF, 4, true); - TEST_ASSERT_EQUAL_STRING("0xFFF", szBuffer); - - intToHexString(szBuffer, 3, 0xFFFF, 4, false); - TEST_ASSERT_EQUAL_STRING("FF", szBuffer); -} \ No newline at end of file From 830b012e5f9630ecddf8f5da857f689f74481d74 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 15 Sep 2024 09:51:11 +0100 Subject: [PATCH 2/5] #208 #207 Remove SimpleTest, Move logging to TcMenuLog library, Add mbed SPI impl --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 1b86ae3..89f44ab 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ framework = arduino lib_deps = - davetcc/TcMenuLogging + davetcc/TcMenuLog davetcc/TaskManagerIO@^1.4.3 davetcc/SimpleCollections@^1.2.3 davetcc/LiquidCrystalIO@^1.4.3 From f268ae0d59421db72577d24035ac51706cf459b5 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 30 Sep 2024 15:21:54 +0100 Subject: [PATCH 3/5] Small fix for R4 --- src/PlatformDetermination.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PlatformDetermination.h b/src/PlatformDetermination.h index 9a3c3b7..1e6dbfa 100644 --- a/src/PlatformDetermination.h +++ b/src/PlatformDetermination.h @@ -79,6 +79,9 @@ typedef uint8_t pinid_t; #elif defined(ESP8266) # define IOA_ANALOGIN_RES 10 # define IOA_ANALOGOUT_RES 10 +#elif defined(ARDUINO_ARCH_RENESAS_UNO) && !defined(IO_MKR_FORCE_LOWRES_ANALOG) +#define IOA_ANALOGIN_RES 14 +#define IOA_ANALOGOUT_RES 12 #else # define IOA_ANALOGIN_RES 10 # define IOA_ANALOGOUT_RES 8 From 76178be25da79c1cf6d363fc96a718ece386ae6f Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 12 Oct 2024 08:49:41 +0100 Subject: [PATCH 4/5] Fix compilation for cmake / pure C++ --- src/EepromAbstractionWire.cpp | 4 ++-- src/SwitchInput.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EepromAbstractionWire.cpp b/src/EepromAbstractionWire.cpp index 34f57fb..49f8f52 100644 --- a/src/EepromAbstractionWire.cpp +++ b/src/EepromAbstractionWire.cpp @@ -67,11 +67,11 @@ uint8_t I2cAt24Eeprom::findMaximumInPage(uint16_t destEeprom, uint8_t len) const // We can read/write in bulk, but do no exceed the page size or we will read / write // the wrong bytes uint16_t offs = destEeprom % pageSize; - uint16_t currentGo = min((uint16_t)pageSize, uint16_t(offs + len)) - offs; + uint16_t currentGo = internal_min((uint16_t)pageSize, uint16_t(offs + len)) - offs; // dont exceed the buffer length of the wire library auto absoluteMax = MAX_BUFFER_SIZE_TO_USE - 2; - return min(currentGo, (uint16_t) absoluteMax); + return internal_min(currentGo, (uint16_t) absoluteMax); } uint8_t I2cAt24Eeprom::read8(EepromPosition position) { diff --git a/src/SwitchInput.cpp b/src/SwitchInput.cpp index 93a2c20..a89f560 100644 --- a/src/SwitchInput.cpp +++ b/src/SwitchInput.cpp @@ -100,7 +100,7 @@ void KeyboardItem::checkAndTrigger(uint8_t buttonState){ else if (getState() == BUTTON_HELD && repeatInterval != NO_REPEAT && notify.callback != nullptr) { counter = counter + (acceleration >> SWITCHES_ACCELERATION_DIVISOR) + 1; if (counter > repeatInterval) { - acceleration = min(255, acceleration + 1); + acceleration = internal_min(255, acceleration + 1); trigger(true); counter = 0; } @@ -326,7 +326,7 @@ void RotaryEncoder::increment(int8_t incVal) { currentReading = (currentReading + incVal); if (currentReading > maximumValue) currentReading = currentReading - maximumValue - 1; } else { - currentReading = min((uint16_t)(currentReading + incVal), maximumValue); + currentReading = internal_min((uint16_t)(currentReading + incVal), maximumValue); } } else if(currentReading < abs(incVal)) { currentReading = rollover? maximumValue - safeAbs(incVal) + 1 : 0; From 0e6707fbfc6919b13ab6bbc756371ba61b22762a Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 12 Oct 2024 13:02:38 +0100 Subject: [PATCH 5/5] Remove all references to davetcc libraries --- platformio.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 89f44ab..c4a5c6b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -3,9 +3,9 @@ framework = arduino lib_deps = davetcc/TcMenuLog - davetcc/TaskManagerIO@^1.4.3 - davetcc/SimpleCollections@^1.2.3 - davetcc/LiquidCrystalIO@^1.4.3 + tcmenu/TaskManagerIO@^1.4.3 + tcmenu/SimpleCollections@^1.2.3 + tcmenu/LiquidCrystalIO@^1.4.3 adafruit/Adafruit GFX Library@^1.11.9 adafruit/Adafruit ILI9341@^1.6.1 adafruit/Adafruit FT6206 Library@^1.1.0