diff --git a/README.md b/README.md index 64ab42892..201d0f250 100644 --- a/README.md +++ b/README.md @@ -213,8 +213,8 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)). - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [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);``` -- [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). -- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266. +- [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). +- [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. - [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266. - [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB. diff --git a/cores/esp8266/core_esp8266_noniso.c b/cores/esp8266/core_esp8266_noniso.c index eddac25a5..40fe5e6dd 100644 --- a/cores/esp8266/core_esp8266_noniso.c +++ b/cores/esp8266/core_esp8266_noniso.c @@ -149,49 +149,58 @@ char* ultoa(unsigned long value, char* result, int base) { char * dtostrf(double number, signed char width, unsigned char prec, char *s) { - if(isnan(number)) { + if (isnan(number)) { strcpy(s, "nan"); return s; } - if(isinf(number)) { + if (isinf(number)) { strcpy(s, "inf"); return s; } - if(number > 4294967040.0 || number < -4294967040.0) { + if (number > 4294967040.0 || number < -4294967040.0) { strcpy(s, "ovf"); return s; } + char* out = s; + int signInt_Part = 1; + // Handle negative numbers - if(number < 0.0) { - *out = '-'; - ++out; + if (number < 0.0) { + signInt_Part = -1; number = -number; } + // calc left over digits + if (prec > 0) + { + width -= (prec + 1); + } + // Round correctly so that print(1.999, 2) prints as "2.00" double rounding = 0.5; - for(uint8_t i = 0; i < prec; ++i) + for (uint8_t i = 0; i < prec; ++i) rounding /= 10.0; number += rounding; // Extract the integer part of the number and print it - unsigned long int_part = (unsigned long) number; - double remainder = number - (double) int_part; - out += sprintf(out, "%ld", int_part); + unsigned long int_part = (unsigned long)number; + double remainder = number - (double)int_part; + out += sprintf(out, "%*ld", width, int_part * signInt_Part); // Print the decimal point, but only if there are digits beyond - if(prec > 0) { + if (prec > 0) { *out = '.'; ++out; - } - for (unsigned char decShift = prec; decShift > 0; decShift--) { - remainder *= 10.0; + + for (unsigned char decShift = prec; decShift > 0; decShift--) { + remainder *= 10.0; + } + sprintf(out, "%0*d", prec, (int)remainder); } - sprintf(out, "%0*d", prec, (int)remainder); return s; } diff --git a/cores/esp8266/pgmspace.cpp b/cores/esp8266/pgmspace.cpp index c2b5781f1..b91dd5912 100644 --- a/cores/esp8266/pgmspace.cpp +++ b/cores/esp8266/pgmspace.cpp @@ -135,6 +135,17 @@ int printf_P(const char* formatP, ...) { return ret; } +int sprintf_P(char* str, const char* formatP, ...) { + int ret; + va_list arglist; + va_start(arglist, formatP); + + ret = vsnprintf_P(str, SIZE_IRRELEVANT, formatP, arglist); + + va_end(arglist); + return ret; +} + int snprintf_P(char* str, size_t strSize, const char* formatP, ...) { int ret; va_list arglist; diff --git a/cores/esp8266/pgmspace.h b/cores/esp8266/pgmspace.h index e6db10fbd..7669058be 100644 --- a/cores/esp8266/pgmspace.h +++ b/cores/esp8266/pgmspace.h @@ -50,7 +50,8 @@ size_t strnlen_P(const char *s, size_t size); #define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT) int printf_P(const char *formatP, ...) __attribute__ ((format (printf, 1, 2))); -int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__ ((format (printf, 3, 4))); +int sprintf_P(char *str, const char *formatP, ...) __attribute__((format(printf, 2, 3))); +int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__((format(printf, 3, 4))); int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap) __attribute__ ((format (printf, 3, 0))); // flash memory must be read using 32 bit aligned addresses else a processor