From eb82fd70347b1aa606ed13cad750a30e1d02831e Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Fri, 11 Apr 2014 15:19:29 +0000 Subject: [PATCH] --- Project/applications/smartcities/.cproject | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Project/applications/smartcities/.project | 26 ++++++++++++++++++++++++++ Project/applications/smartcities/include/sensors.h | 11 ++++++++++- Project/applications/smartcities/main_demo.c | 41 ----------------------------------------- Project/applications/smartcities/sensors.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 194 insertions(+), 43 deletions(-) create mode 100644 Project/applications/smartcities/.cproject create mode 100644 Project/applications/smartcities/.project diff --git a/Project/applications/smartcities/.cproject b/Project/applications/smartcities/.cproject new file mode 100644 index 0000000..7504081 --- /dev/null +++ b/Project/applications/smartcities/.cproject @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Project/applications/smartcities/.project b/Project/applications/smartcities/.project new file mode 100644 index 0000000..8e4b003 --- /dev/null +++ b/Project/applications/smartcities/.project @@ -0,0 +1,26 @@ + + + smartcities + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index cc11e46..2d301a1 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -2,6 +2,9 @@ #define SENSORS_H #include +#include +#include "i2c.h" +#include "libwismart.h" typedef struct { @@ -11,7 +14,13 @@ typedef struct { char* unit; } sensor; -extern sensor humidity_sensor; +// PRESSURE SENSOR FUNCTIONS +extern sensor pressure_sensor; +uint16_t get_pressure_data(void); +void pressure_start_conversion(void); +void pressure_get_coefficients(void); +uint16_t pressure_read_pressure_data(void); +uint16_t pressure_process_data(uint16_t data); #endif \ No newline at end of file diff --git a/Project/applications/smartcities/main_demo.c b/Project/applications/smartcities/main_demo.c index db4a68f..dc11452 100644 --- a/Project/applications/smartcities/main_demo.c +++ b/Project/applications/smartcities/main_demo.c @@ -47,26 +47,6 @@ int main(void) I2C_init(); printf("I2C Initialized\r\n"); - /*I2C_start(I2C1,0x77 << 1, I2C_Direction_Transmitter); - I2C_write(I2C1, 0xF4); - I2C_write(I2C1, 0x2E); - I2C_stop(I2C1); - printf("I2C Temperature measurment started\r\n"); - - I2C_start(I2C1,0x77 << 1, I2C_Direction_Transmitter); - I2C_write(I2C1, 0xF6); - I2C_stop(I2C1); - printf("I2C Temperature measurment request sent\r\n"); - - I2C_start(I2C1, 0x77<<1, I2C_Direction_Receiver); - printf("I2C Read request sent\r\n"); - received_data = I2C_read_ack(I2C1); - received_data = received_data << 8; - received_data = received_data | I2C_read_ack(I2C1); - printf("I2C data received\r\n"); - - sprintf(answer,"%d",received_data); - printf("Data: %s\r\n",answer);*/ I2C_start(I2C1,0x39 << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0x0C); @@ -118,27 +98,6 @@ int main(void) for(;;) { - /*// i2c get info= data - char* data=NULL; - put_message(data, buffer ,&ind); - int res=check_memory(); - if(res==SOFT_REACHED){ - - int ok=send(buffer, ind, "", ""); - if(ok==JSON_COMM_ERROR) - { - printf("wismart is not connected\r\n"); - } - else if( ok==JSON_OTHER_ERROR){ - printf("some error ocurred\r\n"); - } - else if(ok ==JSON_POST_OK){ - printf(" send OK \r\n"); - } - } - else if(res==HARD_REACHED){ - destroy(buffer); - }*/ chThdSleepMilliseconds(500); } } diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index b4517b4..780eef4 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -1,3 +1,57 @@ #include "sensors.h" -sensor humidity_sensor = {0x77, "Humidity sensor", "humidity", "%"}; /* append 0/1 flag for read write */ +sensor pressure_sensor = {0xC0, "Presure sensor", "pressure", "KPa"}; /* append 0/1 flag for read write */ + +uint16_t get_pressure_data() +{ + I2C_init(); + printf("I2C Initialized\r\n"); + pressure_start_conversion(); + chThdSleepMilliseconds(10000); + pressure_get_coefficients(); + return pressure_process_data(pressure_read_pressure_data()); +} + +void pressure_start_conversion() +{ + I2C_start(I2C1,pressure_sensor.ID << 1, I2C_Direction_Transmitter); + I2C_write(I2C1, 0x12); + I2C_stop(I2C1); + printf("I2C Pressure measurment request sent\r\n"); +} + +void pressure_get_coefficients() +{ + +} + +uint16_t pressure_read_pressure_data() +{ + uint16_t received_data; + I2C_start(I2C1,pressure_sensor.ID << 1, I2C_Direction_Transmitter); + I2C_write(I2C1, 0x00); + I2C_stop(I2C1); + printf("I2C Read MSB pressure data sent\r\n"); + + I2C_start(I2C1, pressure_sensor.ID << 1, I2C_Direction_Receiver); + printf("I2C Read request sent\r\n"); + received_data = I2C_read_ack(I2C1); + received_data = received_data << 8; + printf("I2C data received\r\n"); + + I2C_start(I2C1,pressure_sensor.ID << 1, I2C_Direction_Transmitter); + I2C_write(I2C1, 0x01); + I2C_stop(I2C1); + printf("I2C Read LSB pressure data sent\r\n"); + + I2C_start(I2C1, pressure_sensor.ID << 1, I2C_Direction_Receiver); + printf("I2C Read request sent\r\n"); + received_data = received_data | I2C_read_ack(I2C1); + printf("I2C data received\r\n"); + return received_data; +} + +uint16_t pressure_process_data(uint16_t data) +{ + return data; +} \ No newline at end of file -- libgit2 0.22.2