-

Dependencies:   DHT DS18B20 Decagon10HS DecagonEC-5 FastIO LightSensorALS-PT19 WaterMark200ss WeatherMeters mbed-src floathex1

Fork of testgeneral by Javier Sing

Files at this revision

API Documentation at this revision

Comitter:
agrosmart
Date:
Thu Dec 15 11:58:10 2016 +0000
Parent:
1:7f1e6470cc93
Commit message:
test general sensores;

Changed in this revision

floathex.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/floathex.lib	Thu Dec 15 11:58:10 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/agrosmart/code/floathex1/#8638868343e7
--- a/main.cpp	Wed Dec 14 09:49:17 2016 +0000
+++ b/main.cpp	Thu Dec 15 11:58:10 2016 +0000
@@ -8,6 +8,7 @@
 #include "WaterMark200ss.h"
 #include "WeatherMeters.h"
 #include "Anemometer.h"
+#include "floathex.h"
 
 
 //Declaración de Puertos para cada sensor
@@ -24,18 +25,32 @@
 CWeatherMeters WeatherMeters(D4, D5, A5); //Weather Station Anemómetro D4, Veleta D5, Pluviómetro A5
 
 //Declaración variables para sensores:
-float lightLvl      = 0;    // Sensor LUZ               //Rango: 0.0 a 3.3 //2
-float VWC10HS       = 0;    // Sensor 10HS              //Rango: 0.0 a 3.4  //2
-float VWCEC5        = 0;    // Sensor EC-5              //Rango: 0.0 a 4 //2
+float lightLvl      = 0;    // Sensor LUZ               //Rango: 0.0 a 3.3 //3
+float VWC10HS       = 0;    // Sensor 10HS              //Rango: 0.0 a 3.4  //3
+float VWCEC5        = 0;    // Sensor EC-5              //Rango: 0.0 a 4 //3
 float tempdht22     = 0;    // Sensor DHT22             //Rango: -40.0 a 80 //4
 float humdht22      = 0;    // Sensor DHT22             //Rango: 0 a 100% //2
-float tempDS18B20   = 0;    // Sensor DS18B20           //Rango: -55.0 a 125.0 //3 
-float centibar      = 0;    // Sensor WaterMark 200ss   //Rango: 0 a 240 //2
-float rainfall      = 0;    // Weather Station          //Rango: 0 a 100  //3 
-float windSpeed     = 0;    // Weather Station          //Rango: 0 a 2000 //3  
+float tempDS18B20   = 0;    // Sensor DS18B20           //Rango: -55.0 a 125.0 //4
+float centibar      = 0;    // Sensor WaterMark 200ss   //Rango: 0.0 a 240.0 //2
+float rainfall      = 0;    // Weather Station          //Rango: 0 a 100  //3
+float windSpeed     = 0;    // Weather Station          //Rango: 0 a 2000 //3
 float maxWindSpeed  = 0;    // Weather Station          //Rango: 0 a 2000 //3
 float windDir  = 0;         // Weather Station          //Rango: 0 a 337.5 //3
 float value;
+string lightLvlh;
+string VWC10HSh;
+string VWCEC5h;
+string tempdht22h;
+string humdht22h;
+string tempDS18B20h;
+string centibarh;
+string rainfallh;
+string windSpeedh;
+string maxWindSpeedh;
+string windDirh;
+char buffer1[11]= " ";
+char buffer2[11]= " ";
+char buffer3[11]= " ";
 
 void ReadSensors();
 
@@ -67,22 +82,29 @@
         pc.printf("EC-5 VWC: %2.2f VMC\r\n", VWCEC5);
         pc.printf("10HS VWC: %2.2f\r\n", VWC10HS);
         pc.printf("Light: %3.2f \r\n", lightLvl);
-        ConvT();                        // Todos los DS18B20 inician la conversión a temp
-        wait_ms(750);                   // Tiempo minimo de conversion a 12-bit
-        for(int i=1; i<=numROMs; i++) { // Bucle para todos los DS18B20
-            tempDS18B20 = Get_Temp(i);
-            pc.printf("DS18B20 Temp: %08.4f Device: %02X%02X%02X%02X%02X%02X %03d\r\n",tempDS18B20,FoundROM[i][6],FoundROM[i][5],FoundROM[i][4],FoundROM[i][3],FoundROM[i][2],FoundROM[i][1],i);
-        }
-        pc.printf("\r\n");
+       
+        //Convierto a Hex
+        lightLvlh = float2dHex(lightLvl);           // 2 - 1 int 1 dec
+        VWC10HSh = float2dHex(VWC10HS);             // 2 - 1 int 1 dec
+        VWCEC5h = float2dHex(VWCEC5);               // 2 - 1 int 1 dec
+        tempdht22h = float4Hex(tempdht22);          // 4 - 1 signo (1 negativo, 0 positivo) 2 enteros 1 dec
+        tempDS18B20h = float4Hex(tempDS18B20);      // 4 - 1 signo (1 negativo, 0 positivo) 2 enteros 1 dec
+        humdht22h = float2Hex(humdht22);           // 2 - 2 enteros
+        rainfallh = float2Hex(rainfall);            // 2 - 2 enteros
+        centibarh = float3dHex(centibar);           // 3 - 2 enteros, 1 dec
+        windDirh = float3dHex(windDir);             // 3 - 2 enteros, 1 dec
+        windSpeedh = float3Hex(windSpeed);          // 3 - 3 enteros
+        maxWindSpeedh = float3Hex(maxWindSpeed);    // 3 - 3 enteros
+        //Creo las cadenas de Hex
+        snprintf(buffer1, 12, "%s%s%s%s", rainfallh, windDirh, windSpeedh, maxWindSpeedh); //con %.4s puedo definir cuantos caracteres se pasan
+        snprintf(buffer2, 12, "%s%s%s%s", centibarh, VWC10HSh, VWCEC5h, lightLvlh);
+        snprintf(buffer3, 12, "%s,%s,%s", tempDS18B20h, tempdht22h, humdht22h);
         wait(5.0f);
     }
 }
 
 /*
-Hay que organizar con funciones, una para petición de datos, otra para cambiarlos a HEX todo
 
-Hay que definir los datos en HEX, para que ocupen lo menos posibles, la temperatura x2 y a hex, y cosas así, para ocupar los menores bytes posibles uniendo
-todos y generando un buffer de envío
 
 Las definiciones de la placa tienen que estar como externas, para poder exportar el ejemplo e integrarlo con otros (algo así como el marlin) hay ejemplos
 de como se hace
@@ -101,41 +123,16 @@
     windSpeed = Measurements.WindSpeed;             //Weather Station
     maxWindSpeed = Measurements.MaximumWindSpeed;   //Weather Station
     windDir = Measurements.WindDirectionAngle;      //Weather Station
-}
-char *float2Hex(float value)
-{
-    int signo; // para las temperaturas
-    int ent1;
-    int dec1;
-    char value2[5];
-    
-    if(value<0) { 
-        signo = 1; // 1 es negativo, 0 es positivo
-        value = value * -1;
-    } else {
-        signo = 0;
+    ConvT();                        // Todos los DS18B20 inician la conversión a temp
+    wait_ms(750);                   // Tiempo minimo de conversion a 12-bit
+    for(int i=1; i<=numROMs; i++) { // Bucle para todos los DS18B20
+        tempDS18B20 = Get_Temp(i);
+        pc.printf("DS18B20 Temp: %08.4f Device: %02X%02X%02X%02X%02X%02X %03d\r\n",tempDS18B20,FoundROM[i][6],FoundROM[i][5],FoundROM[i][4],FoundROM[i][3],FoundROM[i][2],FoundROM[i][1],i);
     }
-    ent1 = value;
-    dec1 = (value - ent1)*16;
-    sprintf(value2, "%.1X.%.2X.%.1X\n\r", signo, ent1,dec1); //solo queda un decimal. para que queden dos decimales hay que multiplicar decimal por 10
-    return value2;
+    pc.printf("\r\n");
 }
 
 /* CALL  char *temphex = temp2Hex(dht22);
 
-FUNCTION
 
-char * createStr() {
-
-    char char1= 'm';
-    char char2= 'y';
-
-    char *str = (char *) malloc(sizeof(char) * 3);
-    str[0] = char1;
-    str[1] = char2;
-    str[2] = '\0';
-
-    return str;
-
-}
 */
\ No newline at end of file