![](/media/cache/profiles/f095cedd23b99f1696fc8caecbcf257e.jpg.50x50_q85.jpg)
mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/
Dependencies: EthernetNetIf SDHCFileSystem I2CLEDDisp Agentbed NTPClient_NetServices mbed BMP085 HTTPClient ConfigFile I2CLCD
SHT_v1/SHT.h@0:d7b4484099bf, 2011-05-18 (annotated)
- Committer:
- okini3939
- Date:
- Wed May 18 15:01:56 2011 +0000
- Revision:
- 0:d7b4484099bf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:d7b4484099bf | 1 | /* mbed module to use a Sensirion SHT1x /SHT7x sensor |
okini3939 | 0:d7b4484099bf | 2 | * Copyright (c) 2007-2009 Stephen McGarry |
okini3939 | 0:d7b4484099bf | 3 | * Released under the MIT License: http://mbed.org/license/mit |
okini3939 | 0:d7b4484099bf | 4 | */ |
okini3939 | 0:d7b4484099bf | 5 | #ifndef SHT_H |
okini3939 | 0:d7b4484099bf | 6 | #define SHT_H |
okini3939 | 0:d7b4484099bf | 7 | |
okini3939 | 0:d7b4484099bf | 8 | #include "mbed.h" |
okini3939 | 0:d7b4484099bf | 9 | |
okini3939 | 0:d7b4484099bf | 10 | enum SHT_acc { |
okini3939 | 0:d7b4484099bf | 11 | SHT_low=0, |
okini3939 | 0:d7b4484099bf | 12 | SHT_high=1 |
okini3939 | 0:d7b4484099bf | 13 | }; |
okini3939 | 0:d7b4484099bf | 14 | |
okini3939 | 0:d7b4484099bf | 15 | typedef unsigned char byte; |
okini3939 | 0:d7b4484099bf | 16 | |
okini3939 | 0:d7b4484099bf | 17 | class SHT : public Base { |
okini3939 | 0:d7b4484099bf | 18 | public: |
okini3939 | 0:d7b4484099bf | 19 | /* Constructor: SHT |
okini3939 | 0:d7b4484099bf | 20 | * Creates an SHT interface connected to specific pins. |
okini3939 | 0:d7b4484099bf | 21 | * |
okini3939 | 0:d7b4484099bf | 22 | */ |
okini3939 | 0:d7b4484099bf | 23 | SHT(PinName p_sclk, PinName p_data, SHT_acc p_accuracy); |
okini3939 | 0:d7b4484099bf | 24 | |
okini3939 | 0:d7b4484099bf | 25 | /* Functions |
okini3939 | 0:d7b4484099bf | 26 | */ |
okini3939 | 0:d7b4484099bf | 27 | float get_temperature(); // get the most recent temp reading |
okini3939 | 0:d7b4484099bf | 28 | float get_humidity(); // get the most recent humidity reading |
okini3939 | 0:d7b4484099bf | 29 | float get_dewpoint(); // get the most recent dewpoint value |
okini3939 | 0:d7b4484099bf | 30 | void update(SHT_acc accuracy); // update stored values from sensor |
okini3939 | 0:d7b4484099bf | 31 | |
okini3939 | 0:d7b4484099bf | 32 | protected: |
okini3939 | 0:d7b4484099bf | 33 | byte read_byte(bool send_ack); |
okini3939 | 0:d7b4484099bf | 34 | char write_byte(byte value); |
okini3939 | 0:d7b4484099bf | 35 | void trans_start(void); |
okini3939 | 0:d7b4484099bf | 36 | void connection_reset(void); |
okini3939 | 0:d7b4484099bf | 37 | char soft_reset(); |
okini3939 | 0:d7b4484099bf | 38 | char read_status(byte &value); |
okini3939 | 0:d7b4484099bf | 39 | char write_status(byte value); |
okini3939 | 0:d7b4484099bf | 40 | char measure(int &value, byte mode); |
okini3939 | 0:d7b4484099bf | 41 | void calculate(); |
okini3939 | 0:d7b4484099bf | 42 | |
okini3939 | 0:d7b4484099bf | 43 | DigitalOut sclk; |
okini3939 | 0:d7b4484099bf | 44 | DigitalInOut data; |
okini3939 | 0:d7b4484099bf | 45 | SHT_acc accuracy; // will we use high or low accuracy mode on the sensor |
okini3939 | 0:d7b4484099bf | 46 | |
okini3939 | 0:d7b4484099bf | 47 | float temperature; // calculated from sensor reading |
okini3939 | 0:d7b4484099bf | 48 | float humidity; |
okini3939 | 0:d7b4484099bf | 49 | float dewpoint; |
okini3939 | 0:d7b4484099bf | 50 | int temp,hum; // integer values from sensor before conversion |
okini3939 | 0:d7b4484099bf | 51 | |
okini3939 | 0:d7b4484099bf | 52 | enum commands { |
okini3939 | 0:d7b4484099bf | 53 | com_read_status_reg=0x06, |
okini3939 | 0:d7b4484099bf | 54 | com_write_status_reg=0x07, |
okini3939 | 0:d7b4484099bf | 55 | com_measure_temp=0x03, |
okini3939 | 0:d7b4484099bf | 56 | com_measure_humid=0x05, |
okini3939 | 0:d7b4484099bf | 57 | com_reset=0x1E |
okini3939 | 0:d7b4484099bf | 58 | }; |
okini3939 | 0:d7b4484099bf | 59 | |
okini3939 | 0:d7b4484099bf | 60 | enum acks { |
okini3939 | 0:d7b4484099bf | 61 | no_ack=0, |
okini3939 | 0:d7b4484099bf | 62 | send_ack=1 |
okini3939 | 0:d7b4484099bf | 63 | }; |
okini3939 | 0:d7b4484099bf | 64 | }; |
okini3939 | 0:d7b4484099bf | 65 | |
okini3939 | 0:d7b4484099bf | 66 | #endif |