tcMenu
tcUtil.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Nutricherry LTD).
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 #ifdef IOA_USE_MBED
11 #include <mbed.h>
12 #ifndef TCMENU_MBED_NO_MINMAX
13 #define min(x, y) (((x) < (y))?(x):(y))
14 #define max(x, y) (((x) > (y))?(x):(y))
15 #endif //TCMENU_MBED_NO_MINMAX
16 #define highByte(x) ((x) >> 8)
17 #define lowByte(x) ((x) & 0xff)
18 #define ltoa(a,b,c) itoa(a,b,c)
19 #define strcmp_P(x,y) strcmp(x,y)
20 #define strncpy_P(x,y,z) strncpy(x,y,z)
21 #define strcpy_P(x,y) strcpy(x,y)
22 #define strlen_P(x) strlen(x)
23 #endif
24 
25 #ifdef IOA_ARDUINO_MBED
26 #define ltoa(a,b,c) itoa(a,b,c)
27 #endif
28 
29 #include <BasicIoAbstraction.h>
30 #include "RemoteTypes.h"
31 
32 // forward reference.
33 class MenuItem;
34 
46  char name[20];
47  char uuid[38];
48 };
49 
53 void appendChar(char* str, char val, int len);
54 
58 #define NOT_PADDED 0
59 
72 void ltoaClrBuff(char* str, long val, uint8_t dp, char padChar, int len);
73 
87 void fastltoa_mv(char* str, long val, long divisor, char padChar, int len);
88 
102 void fastltoa(char* str, long val, uint8_t dp, char padChar, int len);
103 
114 void fastftoa(char* sz, float fl, int dp, int strSize);
115 
119 long dpToDivisor(int dp);
120 
121 // There now follows pretty much internal code for dealing with program memory
122 // never use direct program memory commands, always prefer these, it allows us
123 // to compile it out much easier.
124 
132 uint8_t safeProgCpy(char* dst, const char* pgmSrc, uint8_t size);
133 
134 // for AVR only definitions
135 #ifdef __AVR__
136 #include <avr/pgmspace.h>
137 #define get_info_callback(x) ((MenuCallbackFn)pgm_read_ptr_near(x))
138 #define TCMENU_DEFINED_PLATFORM PLATFORM_ARDUINO_8BIT
139 #endif
140 
141 // for ESP only definitions
142 #ifdef ESP_H
143 #include <pgmspace.h>
144 #define get_info_callback(x) ((MenuCallbackFn)(*x))
145 #define TCMENU_DEFINED_PLATFORM PLATFORM_ARDUINO_32BIT
146 #endif
147 
148 // for things that are the same between AVR and ESP
149 #if (defined __AVR__ || defined ESP_H) && !defined __MBED__
150 #define PGM_TCM PROGMEM
151 extern char szGlobalBuffer[];
152 inline char* potentialProgramMemory(const char *x) {
153  safeProgCpy(szGlobalBuffer, x, 16);
154  return szGlobalBuffer;
155 }
156 #define get_info_char(x) ((char) pgm_read_byte_near(x))
157 #define get_info_int(x) ((int16_t)pgm_read_word_near(x))
158 #define get_info_uint(x) ((unsigned int)pgm_read_word_near(x))
159 #define safeProgStrLen(x) (strlen_P(x))
160 #else
161 #define TCMENU_DEFINED_PLATFORM PLATFORM_ARDUINO_32BIT
162 #define PGM_TCM
163 #define potentialProgramMemory(x) (x)
164 #define get_info_char(x) ((char)(*x))
165 #define get_info_int(x) ((int16_t)(*x))
166 #define get_info_uint(x) ((unsigned int)(*x))
167 #define get_info_callback(x) ((MenuCallbackFn)(*x))
168 #define safeProgStrLen(x) (strlen(x))
169 #endif
170 
171 #endif
Definition: MenuItems.h:324
long dpToDivisor(int dp)
Definition: tcUtil.cpp:21
void fastltoa_mv(char *str, long val, long divisor, char padChar, int len)
Definition: tcUtil.cpp:45
void fastltoa(char *str, long val, uint8_t dp, char padChar, int len)
Definition: tcUtil.cpp:41
void appendChar(char *str, char val, int len)
Definition: tcUtil.cpp:10
void ltoaClrBuff(char *str, long val, uint8_t dp, char padChar, int len)
Definition: tcUtil.cpp:36
Definition: tcUtil.h:45
uint8_t safeProgCpy(char *dst, const char *pgmSrc, uint8_t size)
Definition: tcUtil.cpp:97
void fastftoa(char *sz, float fl, int dp, int strSize)
Definition: tcUtil.cpp:74