Skip to content

Issues 475 & 484 fixes #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 24 additions & 15 deletions hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_noniso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions hardware/esp8266com/esp8266/cores/esp8266/pgmspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion hardware/esp8266com/esp8266/cores/esp8266/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down