* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utility.cpp Source File

utility.cpp

00001 #include <Blynk/BlynkDebug.h>
00002 
00003 #if defined(ESP8266) && !defined(BLYNK_NO_FLOAT)
00004 #include <string.h>
00005 #include <math.h>
00006 
00007 char* dtostrf_internal(double number, signed char width, unsigned char prec, char *s) {
00008     if(isnan(number)) {
00009         strcpy(s, "nan");
00010         return s;
00011     }
00012     if(isinf(number)) {
00013         strcpy(s, "inf");
00014         return s;
00015     }
00016 
00017     if(number > 4294967040.0 || number < -4294967040.0) {
00018         strcpy(s, "ovf");
00019         return s;
00020     }
00021     char* out = s;
00022     // Handle negative numbers
00023     if(number < 0.0) {
00024         *out = '-';
00025         ++out;
00026         number = -number;
00027     }
00028 
00029     // Round correctly so that print(1.999, 2) prints as "2.00"
00030     double rounding = 0.5;
00031     for(uint8_t i = 0; i < prec; ++i)
00032         rounding /= 10.0;
00033 
00034     number += rounding;
00035 
00036     // Extract the integer part of the number and print it
00037     unsigned long int_part = (unsigned long) number;
00038     double remainder = number - (double) int_part;
00039     out += sprintf(out, "%d", int_part);
00040 
00041     // Print the decimal point, but only if there are digits beyond
00042     if(prec > 0) {
00043         *out = '.';
00044         ++out;
00045     }
00046 
00047     while(prec-- > 0) {
00048         remainder *= 10.0;
00049         if((int)remainder == 0){
00050                 *out = '0';
00051                  ++out;
00052         }
00053     }
00054     sprintf(out, "%d", (int) remainder);
00055 
00056     return s;
00057 }
00058 
00059 #endif
00060 
00061