forked from tinkertanker/microDriver_SHT2x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver_sht2x.ts
49 lines (47 loc) · 1.71 KB
/
driver_sht2x.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* The SHT2x Driver provides access to the functionality of the SHT20, SHT21
* and SHT2x sensors
*/
//% color=#4c6ef5 weight=25 icon="\uf043" block="SHT2x Sensor"
namespace SHT2xDriver {
/**
* Read Relative Humidity from the SHT2x Sensor.
* Returns a number describing the relative humidity in percentage % relative
* humidity
*/
//% shim=SHT2xDriver::read_humidity
//% blockId="SHT2xDriver_read_humidity"
//% block="read humidty"
export function read_humidity(): number{
// Dummy implementation for the simulator.
console.log("Simulate: Read Humidity from SHT2x sensor: 50");
return 50.0;
}
/**
* Read Temperature in degrees celcius from the SHT2x sensor.
* Returns a number describing the ambient temperature in degrees celcius
*/
//% shim=SHT2xDriver::read_temperature
//% blockId="SHT2xDriver_read_temperature"
//% block="read temperature"
export function read_temperature(): number{
// Dummy implementation for the simulator.
console.log("Simulate: Read Temperature from SHT2x sensor: 50");
return 30.0;
}
/**
* Change the I2c address used to interact with the SHT2x to the given
* address. The I2c address should be within 0-127.
*/
//% shim=SHT2xDriver::set_i2c_address
//% blockId="SHT2xDriver_set_i2c_address"
//% block="Change i2c address to %address"
//% advanced=true
export function set_i2c_address(address:number)
{
// Dummy implementation for the simulator.
if(address < 0 || address > 128)
{ console.log("Simulate: Invaild i2c Address: " + address); }
else { console.log("Simulate: Set i2c address to " + address); }
}
}