Skip to content

Commit 1154545

Browse files
Makunaigrr
authored andcommitted
Issue fixes
#475 #484
1 parent 3291054 commit 1154545

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ Libraries that don't rely on low-level access to AVR registers should work well.
213213
- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)).
214214
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
215215
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - Download latest v1.1.0 library and no changes are necessary. Older versions should initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
216-
- [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel libray, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager).
217-
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.
216+
- [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel library, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager).
217+
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266. Use the "NeoPixelAnimator" branch for esp8266 to get HSL color support and more.
218218
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
219219
- [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266.
220220
- [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB.

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_noniso.c

+24-15
Original file line numberDiff line numberDiff line change
@@ -149,49 +149,58 @@ char* ultoa(unsigned long value, char* result, int base) {
149149

150150
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
151151

152-
if(isnan(number)) {
152+
if (isnan(number)) {
153153
strcpy(s, "nan");
154154
return s;
155155
}
156-
if(isinf(number)) {
156+
if (isinf(number)) {
157157
strcpy(s, "inf");
158158
return s;
159159
}
160160

161-
if(number > 4294967040.0 || number < -4294967040.0) {
161+
if (number > 4294967040.0 || number < -4294967040.0) {
162162
strcpy(s, "ovf");
163163
return s;
164164
}
165+
165166
char* out = s;
167+
int signInt_Part = 1;
168+
166169
// Handle negative numbers
167-
if(number < 0.0) {
168-
*out = '-';
169-
++out;
170+
if (number < 0.0) {
171+
signInt_Part = -1;
170172
number = -number;
171173
}
172174

175+
// calc left over digits
176+
if (prec > 0)
177+
{
178+
width -= (prec + 1);
179+
}
180+
173181
// Round correctly so that print(1.999, 2) prints as "2.00"
174182
double rounding = 0.5;
175-
for(uint8_t i = 0; i < prec; ++i)
183+
for (uint8_t i = 0; i < prec; ++i)
176184
rounding /= 10.0;
177185

178186
number += rounding;
179187

180188
// Extract the integer part of the number and print it
181-
unsigned long int_part = (unsigned long) number;
182-
double remainder = number - (double) int_part;
183-
out += sprintf(out, "%ld", int_part);
189+
unsigned long int_part = (unsigned long)number;
190+
double remainder = number - (double)int_part;
191+
out += sprintf(out, "%*ld", width, int_part * signInt_Part);
184192

185193
// Print the decimal point, but only if there are digits beyond
186-
if(prec > 0) {
194+
if (prec > 0) {
187195
*out = '.';
188196
++out;
189-
}
190197

191-
for (unsigned char decShift = prec; decShift > 0; decShift--) {
192-
remainder *= 10.0;
198+
199+
for (unsigned char decShift = prec; decShift > 0; decShift--) {
200+
remainder *= 10.0;
201+
}
202+
sprintf(out, "%0*d", prec, (int)remainder);
193203
}
194-
sprintf(out, "%0*d", prec, (int)remainder);
195204

196205
return s;
197206
}

hardware/esp8266com/esp8266/cores/esp8266/pgmspace.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ int printf_P(const char* formatP, ...) {
135135
return ret;
136136
}
137137

138+
int sprintf_P(char* str, const char* formatP, ...) {
139+
int ret;
140+
va_list arglist;
141+
va_start(arglist, formatP);
142+
143+
ret = vsnprintf_P(str, SIZE_IRRELEVANT, formatP, arglist);
144+
145+
va_end(arglist);
146+
return ret;
147+
}
148+
138149
int snprintf_P(char* str, size_t strSize, const char* formatP, ...) {
139150
int ret;
140151
va_list arglist;

hardware/esp8266com/esp8266/cores/esp8266/pgmspace.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ size_t strnlen_P(const char *s, size_t size);
5050
#define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT)
5151

5252
int printf_P(const char *formatP, ...) __attribute__ ((format (printf, 1, 2)));
53-
int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__ ((format (printf, 3, 4)));
53+
int sprintf_P(char *str, const char *formatP, ...) __attribute__((format(printf, 2, 3)));
54+
int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__((format(printf, 3, 4)));
5455
int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap) __attribute__ ((format (printf, 3, 0)));
5556

5657
// flash memory must be read using 32 bit aligned addresses else a processor

0 commit comments

Comments
 (0)