EMIR - Ekvitermní mikroprocesorová regulace https://code.google.com/p/emir/ https://code.google.com/p/emir/wiki/DesignV3

Dependencies:   ConfigFile DS1307 OneWire SDFileSystem USBDeviceLite mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sensor.cpp Source File

sensor.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "1wire.h"
00004 #include "sensor.h"
00005 #include "sd.h"
00006 
00007 uint8_t sensor_roms[MAX_SENSORS][8];
00008 int16_t sensor_temps[MAX_SENSORS];
00009 int sensor_count;
00010 
00011 Mutex sensor_mutex;
00012 
00013 void sensor_thread(void const *args)
00014 {
00015     OneWire ow(A4, A2, A3);
00016     int result, temp;
00017     uint8_t rom[8];
00018     
00019     while (1) {
00020         ow.ConvertAll(false);
00021         Thread::wait(CONVERT_T_DELAY);
00022 
00023         sensor_mutex.lock();
00024         sensor_count = 0;
00025         memset(rom, 0, sizeof(rom));
00026         result = ow.First(rom);
00027         while (result == OW_FOUND && sensor_count < MAX_SENSORS) {
00028             if (ow.ReadTemperature(rom, &temp) == 0) {
00029                 memcpy(sensor_roms[sensor_count], rom, sizeof(rom));
00030                 sensor_temps[sensor_count] = temp;
00031                 sensor_count++;
00032                 
00033                 int id = get_sensor_cfg(rom, NULL);
00034                 log_temperature(id, temp);
00035             }
00036             result = ow.Next(rom);
00037         }
00038         sensor_mutex.unlock();
00039     }
00040 }
00041