-
Dependencies: DHT DS18B20 Decagon10HS DecagonEC-5 FastIO LightSensorALS-PT19 WaterMark200ss WeatherMeters mbed-src floathex1
Fork of testgeneral by
Diff: main.cpp
- Revision:
- 1:7f1e6470cc93
- Parent:
- 0:232c507002f4
- Child:
- 2:a13c531579dd
diff -r 232c507002f4 -r 7f1e6470cc93 main.cpp --- a/main.cpp Mon Nov 28 13:28:26 2016 +0000 +++ b/main.cpp Wed Dec 14 09:49:17 2016 +0000 @@ -23,21 +23,21 @@ DHT dht22(PB_3,DHT22); //DHT22 en el D3 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 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 maxWindSpeed = 0; // Weather Station //Rango: 0 a 2000 //3 +float windDir = 0; // Weather Station //Rango: 0 a 337.5 //3 +float value; -//Declaración variables para sensores: -float lightLvl = 0; // Sensor LUZ -float VWC10HS = 0; // Sensor 10HS -float VWCEC5 = 0; // Sensor EC-5 -float tempdht22 = 0; // Sensor DHT22 -float humdht22 = 0; // Sensor DHT22 -float tempDS18B20 = 0; // Sensor DS18B20 -float centibar = 0; // Snsor WaterMark 200ss -float rainfall = 0; -float windSpeed = 0; -float maxWindSpeed = 0; - - +void ReadSensors(); int main() { @@ -56,18 +56,8 @@ while(1) { //Leer Sensores wait(1); - lightLvl = readLightSensor(light,lightref); //Sensor de Luz - VWC10HS = Moist10HS(moisture10HS); //Sensor 10HS - VWCEC5 = MoistEC5(moistureEC5); //Sensor EC-5 - tempdht22 = dht22.ReadTemperature(CELCIUS); //Sensor DHT22 - humdht22 = dht22.ReadHumidity(); //Sensor DHT22 - centibar = Moist200ss(moisture200ss); //Sensor WaterMark 200ss - CWeatherMeters::SMeasurements Measurements; //Weather Station - WeatherMeters.GetMeasurements(&Measurements); //Weather Station - rainfall = Measurements.Rainfall; //Weather Station - windSpeed = Measurements.WindSpeed; //Weather Station - maxWindSpeed = Measurements.MaximumWindSpeed; //Weather Station - pc.printf("Direction: %s\n", Measurements.WindDirectionString); + ReadSensors(); //No hace lectura de la Temperatura con la ds18b20?? + pc.printf("Direction: %s\n",windDir); pc.printf("Depth: %f\n",rainfall); pc.printf("Current speed: %f\n", windSpeed); pc.printf("Maximum speed: %f\n", maxWindSpeed); @@ -88,3 +78,64 @@ } } +/* +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 +*/ +void ReadSensors() +{ + lightLvl = readLightSensor(light,lightref); //Sensor de Luz + VWC10HS = Moist10HS(moisture10HS); //Sensor 10HS + VWCEC5 = MoistEC5(moistureEC5); //Sensor EC-5 + tempdht22 = dht22.ReadTemperature(CELCIUS); //Sensor DHT22 + humdht22 = dht22.ReadHumidity(); //Sensor DHT22 + centibar = Moist200ss(moisture200ss); //Sensor WaterMark 200ss + CWeatherMeters::SMeasurements Measurements; //Weather Station + WeatherMeters.GetMeasurements(&Measurements); //Weather Station + rainfall = Measurements.Rainfall; //Weather Station + 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; + } + 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; +} + +/* 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