MansOS Humidity

From DiLab
Revision as of 18:50, 14 November 2011 by Girts (talk | contribs) (Function reference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
mos/hil/humidity.h

Usage and configuration

To use humidity sensor, make the following changes to you application:

  • enable humidity sensor by adding the following line to config file:
USE_HUMIDITY = y
  • If using generic MSP430 platforms, which use the same humidity sensor as TelosB, additional definition in config file required:
USE_TELOSB_HUMIDITY = y
  • in your code, call humidityOn() to turn the sensor on
  • in your code, call readHumidity() to get 16-bit raw humidity value

Dependencies

There are no dependencies for humidity sensor usage imposed by the MansOS operating system. However, some platforms may have specific requirements, for example, I2C or SPI usage. Such cases should be handled automatically by the platforms and error or warning should be issued if some platform-specific humidity sensor requirements are not met.

Function reference

All platform-independent humidity sensor functions are described in mos/hil/humidity.h . Implementation can be found under mos/hal/platforms/<platform-name>/

void humidityInit();      // init humidity sensor, do not turn it on - called by kernel automatically, not needed in user level
void humidityOn();        // turn on humidity sensor
void humidityOff();       // turn off humidity sensor
uint16_t readHumidity();  // read humidity value

// Optional - some humidity sensors (SHT11) also provide temperature reading
uint16_t readHTemperature();  // read temperature value from humidity sensor

Example

Read humidity sensor, print raw value to UART

#include "stdmansos.h"
#include "dprint.h"
#include "humidity.h"


//-------------------------------------------
//      Entry point for the application
//-------------------------------------------
void appMain(void)
{
    PRINT_INIT(129);
    PRINTF("Humidity test app\n");

    humidityOn();

    while (1) {
        sleep(1);
        uint16_t hum_raw = readHumidity();
        uint16_t temp_raw = readHTemperature();
        PRINTF("hum = %i\t temp = %i\n", hum_raw, temp_raw);
    }
}