Dependencies:   mbed

Committer:
roselea
Date:
Sun Jan 24 22:00:35 2010 +0000
Revision:
0:df1c8f2961a1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roselea 0:df1c8f2961a1 1 /* mbed module to use a Sensirion SHT1x /SHT7x sensor
roselea 0:df1c8f2961a1 2 * Copyright (c) 2007-2009 Stephen McGarry
roselea 0:df1c8f2961a1 3 * Released under the MIT License: http://mbed.org/license/mit
roselea 0:df1c8f2961a1 4 */
roselea 0:df1c8f2961a1 5 #ifndef SHT_H
roselea 0:df1c8f2961a1 6 #define SHT_H
roselea 0:df1c8f2961a1 7
roselea 0:df1c8f2961a1 8 #include "mbed.h"
roselea 0:df1c8f2961a1 9
roselea 0:df1c8f2961a1 10 enum SHT_acc {
roselea 0:df1c8f2961a1 11 SHT_low=0,
roselea 0:df1c8f2961a1 12 SHT_high=1
roselea 0:df1c8f2961a1 13 };
roselea 0:df1c8f2961a1 14
roselea 0:df1c8f2961a1 15 typedef unsigned char byte;
roselea 0:df1c8f2961a1 16
roselea 0:df1c8f2961a1 17 class SHT : public Base {
roselea 0:df1c8f2961a1 18 public:
roselea 0:df1c8f2961a1 19 /* Constructor: SHT
roselea 0:df1c8f2961a1 20 * Creates an SHT interface connected to specific pins.
roselea 0:df1c8f2961a1 21 *
roselea 0:df1c8f2961a1 22 */
roselea 0:df1c8f2961a1 23 SHT(PinName p_sclk, PinName p_data, SHT_acc p_accuracy);
roselea 0:df1c8f2961a1 24
roselea 0:df1c8f2961a1 25 /* Functions
roselea 0:df1c8f2961a1 26 */
roselea 0:df1c8f2961a1 27 float get_temperature(); // get the most recent temp reading
roselea 0:df1c8f2961a1 28 float get_humidity(); // get the most recent humidity reading
roselea 0:df1c8f2961a1 29 float get_dewpoint(); // get the most recent dewpoint value
roselea 0:df1c8f2961a1 30 void update(SHT_acc accuracy); // update stored values from sensor
roselea 0:df1c8f2961a1 31
roselea 0:df1c8f2961a1 32 protected:
roselea 0:df1c8f2961a1 33 byte read_byte(bool send_ack);
roselea 0:df1c8f2961a1 34 char write_byte(byte value);
roselea 0:df1c8f2961a1 35 void trans_start(void);
roselea 0:df1c8f2961a1 36 void connection_reset(void);
roselea 0:df1c8f2961a1 37 char soft_reset();
roselea 0:df1c8f2961a1 38 char read_status(byte &value);
roselea 0:df1c8f2961a1 39 char write_status(byte value);
roselea 0:df1c8f2961a1 40 char measure(int &value, byte mode);
roselea 0:df1c8f2961a1 41 void calculate();
roselea 0:df1c8f2961a1 42
roselea 0:df1c8f2961a1 43 DigitalOut sclk;
roselea 0:df1c8f2961a1 44 DigitalInOut data;
roselea 0:df1c8f2961a1 45 SHT_acc accuracy; // will we use high or low accuracy mode on the sensor
roselea 0:df1c8f2961a1 46
roselea 0:df1c8f2961a1 47 float temperature; // calculated from sensor reading
roselea 0:df1c8f2961a1 48 float humidity;
roselea 0:df1c8f2961a1 49 float dewpoint;
roselea 0:df1c8f2961a1 50 int temp,hum; // integer values from sensor before conversion
roselea 0:df1c8f2961a1 51
roselea 0:df1c8f2961a1 52 enum commands {
roselea 0:df1c8f2961a1 53 com_read_status_reg=0x06,
roselea 0:df1c8f2961a1 54 com_write_status_reg=0x07,
roselea 0:df1c8f2961a1 55 com_measure_temp=0x03,
roselea 0:df1c8f2961a1 56 com_measure_humid=0x05,
roselea 0:df1c8f2961a1 57 com_reset=0x1E
roselea 0:df1c8f2961a1 58 };
roselea 0:df1c8f2961a1 59
roselea 0:df1c8f2961a1 60 enum acks {
roselea 0:df1c8f2961a1 61 no_ack=0,
roselea 0:df1c8f2961a1 62 send_ack=1
roselea 0:df1c8f2961a1 63 };
roselea 0:df1c8f2961a1 64 };
roselea 0:df1c8f2961a1 65
roselea 0:df1c8f2961a1 66 #endif