tcMenu
tcUtil.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
6 #ifndef _TCUTIL_H
7 #define _TCUTIL_H
8 
9 #include <PlatformDetermination.h>
10 #include <TextUtilities.h>
11 #include <MenuItems.h>
12 
13 #include <BasicIoAbstraction.h>
14 #include "RemoteTypes.h"
15 
26  char name[30];
27  char uuid[38];
28 };
29 
41 uint32_t getBoardSerialNumber();
42 
47 void showVersionDialog(const ConnectorLocalInfo* localInfo);
48 
57 AnyMenuInfo *newAnyMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max = 0);
58 
67 AnyMenuInfo *newAnyMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max = 0);
68 
81 AnalogMenuInfo* newAnalogMenuInfoP(const char* name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max, uint16_t offset, uint16_t divisor, const char* unit);
82 
95 AnalogMenuInfo* newAnalogMenuInfo(const char* name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max, uint16_t offset, uint16_t divisor, const char* unit);
96 
106 BooleanMenuInfo *newBooleanMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, BooleanNaming naming);
107 
117 BooleanMenuInfo *newBooleanMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, BooleanNaming naming);
118 
128 FloatMenuInfo *newFloatMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, int decimalPlaces);
129 
139 FloatMenuInfo *newFloatMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, int decimalPlaces);
140 
141 
142 // There now follows pretty much internal code, boolean negative for dealing with program memory
143 // never use direct program memory commands, always prefer these, it allows us
144 // to compile it out much easier.
145 
153 uint8_t safeProgCpy(char* dst, const char* pgmSrc, uint8_t size);
154 
155 // for AVR only definitions
156 #ifdef __AVR__
157 #include <avr/pgmspace.h>
158 #define get_info_callback(x) ((MenuCallbackFn)pgm_read_ptr_near(x))
159 #define TCMENU_DEFINED_PLATFORM PLATFORM_ARDUINO_8BIT
160 #endif
161 
162 // for ESP only definitions
163 #ifdef ESP_H
164 #include <pgmspace.h>
165 #define get_info_callback(x) ((MenuCallbackFn)(*x))
166 #define TCMENU_DEFINED_PLATFORM PLATFORM_ARDUINO_32BIT
167 #endif
168 
169 // for things that are the same between AVR and ESP
170 #if (defined __AVR__ || defined ESP_H) && !defined __MBED__
171 #define PGM_TCM PROGMEM
172 extern char szGlobalBuffer[];
173 inline char* potentialProgramMemory(const char *x) {
174  safeProgCpy(szGlobalBuffer, x, 16);
175  return szGlobalBuffer;
176 }
177 #define get_info_char(x) ((char) pgm_read_byte_near(x))
178 #define get_info_int(x) ((int16_t)pgm_read_word_near(x))
179 #define get_info_uint(x) ((unsigned int)pgm_read_word_near(x))
180 #define safeProgStrLen(x) (strlen_P(x))
181 #else
182 #define TCMENU_DEFINED_PLATFORM PLATFORM_ARDUINO_32BIT
183 #define PGM_TCM
184 #define potentialProgramMemory(x) (x)
185 #define get_info_char(x) ((char)(*x))
186 #define get_info_int(x) ((int16_t)(*x))
187 #define get_info_uint(x) ((unsigned int)(*x))
188 #define get_info_callback(x) ((MenuCallbackFn)(*x))
189 #define safeProgStrLen(x) (strlen(x))
190 
191 #if !defined(pgm_read_dword) && (defined(__MBED__) || defined(BUILD_FOR_PICO_CMAKE))
192 # define pgm_read_byte(addr) (*(const unsigned char *)(addr))
193 # define pgm_read_word(addr) (*(const unsigned short *)(addr))
194 # define pgm_read_dword(addr) (*(const unsigned long *)(addr))
195 # define pgm_read_float(addr) (*(const float *)(addr))
196 # define pgm_read_ptr(addr) (*(addr))
197 # define memcpy_P memcpy
198 #endif // pgm_read_byte
199 #endif
200 
201 #endif
In TcMenu, MenuItem storage is shared between program memory and RAM. Usually each MenuItem has assoc...
void(* MenuCallbackFn)(int id)
Definition: MenuItems.h:45
BooleanNaming
Definition: MenuItems.h:134
Definition: MenuItems.h:71
Definition: MenuItems.h:51
Definition: MenuItems.h:151
Definition: MenuItems.h:182
contains the definitions of each message and field.
uint32_t getBoardSerialNumber()
Definition: tcUtil.cpp:27
BooleanMenuInfo * newBooleanMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, BooleanNaming naming)
Definition: tcUtil.cpp:107
uint8_t safeProgCpy(char *dst, const char *pgmSrc, uint8_t size)
Definition: tcUtil.cpp:32
void showVersionDialog(const ConnectorLocalInfo *localInfo)
Definition: tcUtil.cpp:45
AnalogMenuInfo * newAnalogMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max, uint16_t offset, uint16_t divisor, const char *unit)
Definition: tcUtil.cpp:91
FloatMenuInfo * newFloatMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, int decimalPlaces)
Definition: tcUtil.cpp:120
AnyMenuInfo * newAnyMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max=0)
Definition: tcUtil.cpp:76
FloatMenuInfo * newFloatMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, int decimalPlaces)
Definition: tcUtil.cpp:114
BooleanMenuInfo * newBooleanMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, BooleanNaming naming)
Definition: tcUtil.cpp:100
AnyMenuInfo * newAnyMenuInfoP(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max=0)
Definition: tcUtil.cpp:70
AnalogMenuInfo * newAnalogMenuInfo(const char *name, menuid_t id, uint16_t eeprom, MenuCallbackFn cb, uint16_t max, uint16_t offset, uint16_t divisor, const char *unit)
Definition: tcUtil.cpp:82
Definition: tcUtil.h:25