MCPcopy Create free account
hub / github.com/Blueforcer/awtrix3 / toStr

Method toStr

lib/home-assistant-integration/src/utils/HANumeric.cpp:170–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170uint16_t HANumeric::toStr(char* dst) const
171{
172 char* prefixCh = &dst[0];
173 if (!_isSet || _value == 0) {
174 *prefixCh = '0';
175 return 1;
176 }
177
178 int64_t value = _value;
179 const uint8_t numberLength = calculateSize();
180 if (value < 0) {
181 value *= -1;
182 *prefixCh = '-';
183 prefixCh++;
184 }
185
186 if (_precision > 0) {
187 uint8_t i = _precision;
188 char* dotPtr = prefixCh + 1;
189 do {
190 *prefixCh = '0';
191 prefixCh++;
192 } while(i-- > 0);
193
194 *dotPtr = '.';
195 }
196
197 char* ch = &dst[numberLength - 1];
198 char* lastCh = ch;
199 char* dotPos = _precision > 0 ? &dst[numberLength - 1 - _precision] : nullptr;
200
201 while (value != 0) {
202 if (ch == dotPos) {
203 *dotPos = '.';
204 ch--;
205 continue;
206 }
207
208 *ch = (value % 10) + '0';
209 value /= 10;
210 ch--;
211 }
212
213 return lastCh - &dst[0] + 1;
214}

Callers 10

flushEntryValueMethod · 0.80
publishValueMethod · 0.80
publishPositionMethod · 0.80
publishSpeedMethod · 0.80
publishBrightnessMethod · 0.80
publishRGBColorMethod · 0.80
publishStateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected