SCH MME sensor test
Dependencies: mbed Adafruit_GFX
mlx90615.cpp@1:bbf8b08b8a20, 2019-11-06 (annotated)
- Committer:
- shinshingo
- Date:
- Wed Nov 06 09:06:56 2019 +0000
- Revision:
- 1:bbf8b08b8a20
- Parent:
- 0:28c89a4b6b69
comment;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shinshingo | 0:28c89a4b6b69 | 1 | |
shinshingo | 0:28c89a4b6b69 | 2 | #include "mlx90615.h" |
shinshingo | 0:28c89a4b6b69 | 3 | |
shinshingo | 0:28c89a4b6b69 | 4 | |
shinshingo | 0:28c89a4b6b69 | 5 | |
shinshingo | 0:28c89a4b6b69 | 6 | |
shinshingo | 0:28c89a4b6b69 | 7 | MLX90615::MLX90615(I2C* i2c,int addr){ |
shinshingo | 0:28c89a4b6b69 | 8 | |
shinshingo | 0:28c89a4b6b69 | 9 | this->i2caddress = addr; |
shinshingo | 0:28c89a4b6b69 | 10 | this->i2c = i2c; |
shinshingo | 0:28c89a4b6b69 | 11 | |
shinshingo | 0:28c89a4b6b69 | 12 | } |
shinshingo | 0:28c89a4b6b69 | 13 | |
shinshingo | 0:28c89a4b6b69 | 14 | |
shinshingo | 0:28c89a4b6b69 | 15 | bool MLX90615::getTemp(float* temp_val){ |
shinshingo | 0:28c89a4b6b69 | 16 | |
shinshingo | 0:28c89a4b6b69 | 17 | char ch1, ch2; |
shinshingo | 0:28c89a4b6b69 | 18 | char cmd[3]; |
shinshingo | 0:28c89a4b6b69 | 19 | |
shinshingo | 0:28c89a4b6b69 | 20 | cmd[0] = 0x27; |
shinshingo | 0:28c89a4b6b69 | 21 | cmd[1] = 0; |
shinshingo | 0:28c89a4b6b69 | 22 | cmd[2] = 0; |
shinshingo | 0:28c89a4b6b69 | 23 | |
shinshingo | 0:28c89a4b6b69 | 24 | i2c->stop(); |
shinshingo | 0:28c89a4b6b69 | 25 | wait_us(5); |
shinshingo | 0:28c89a4b6b69 | 26 | ch1 = i2c->write(0xb6, cmd, 1, true); |
shinshingo | 0:28c89a4b6b69 | 27 | if (ch1 != 0) {return false;} |
shinshingo | 0:28c89a4b6b69 | 28 | ch2 = i2c->read(0xb7, cmd, 3); |
shinshingo | 0:28c89a4b6b69 | 29 | if (ch2 != 0) {return false;} |
shinshingo | 0:28c89a4b6b69 | 30 | wait_us(5); |
shinshingo | 0:28c89a4b6b69 | 31 | |
shinshingo | 0:28c89a4b6b69 | 32 | *temp_val = ((((cmd[1]&0x007f)<<8)+cmd[0])*0.02)-273.15; |
shinshingo | 0:28c89a4b6b69 | 33 | return true; |
shinshingo | 0:28c89a4b6b69 | 34 | |
shinshingo | 0:28c89a4b6b69 | 35 | } |
shinshingo | 0:28c89a4b6b69 | 36 | |
shinshingo | 0:28c89a4b6b69 | 37 | bool MLX90615::getTempAmbient(float* temp_val){ |
shinshingo | 0:28c89a4b6b69 | 38 | |
shinshingo | 0:28c89a4b6b69 | 39 | char ch1, ch2; |
shinshingo | 0:28c89a4b6b69 | 40 | char cmd[3]; |
shinshingo | 0:28c89a4b6b69 | 41 | |
shinshingo | 0:28c89a4b6b69 | 42 | cmd[0] = 0x26; |
shinshingo | 0:28c89a4b6b69 | 43 | cmd[1] = 0; |
shinshingo | 0:28c89a4b6b69 | 44 | cmd[2] = 0; |
shinshingo | 0:28c89a4b6b69 | 45 | |
shinshingo | 0:28c89a4b6b69 | 46 | i2c->stop(); |
shinshingo | 0:28c89a4b6b69 | 47 | wait_us(5); |
shinshingo | 0:28c89a4b6b69 | 48 | ch1 = i2c->write(0xb6, cmd, 1, true); |
shinshingo | 0:28c89a4b6b69 | 49 | if (ch1 != 0) {return false;} |
shinshingo | 0:28c89a4b6b69 | 50 | ch2 = i2c->read(0xb7, cmd, 3); |
shinshingo | 0:28c89a4b6b69 | 51 | if (ch2 != 0) {return false;} |
shinshingo | 0:28c89a4b6b69 | 52 | wait_us(5); |
shinshingo | 0:28c89a4b6b69 | 53 | |
shinshingo | 0:28c89a4b6b69 | 54 | *temp_val = ((((cmd[1]&0x007f)<<8)+cmd[0])*0.02)-273.15; |
shinshingo | 0:28c89a4b6b69 | 55 | return true; |
shinshingo | 0:28c89a4b6b69 | 56 | |
shinshingo | 0:28c89a4b6b69 | 57 | } |
shinshingo | 0:28c89a4b6b69 | 58 | |
shinshingo | 0:28c89a4b6b69 | 59 | bool MLX90615::getRawIR(int16_t* ir_val){ |
shinshingo | 0:28c89a4b6b69 | 60 | |
shinshingo | 0:28c89a4b6b69 | 61 | char ch1, ch2; |
shinshingo | 0:28c89a4b6b69 | 62 | char cmd[3]; |
shinshingo | 0:28c89a4b6b69 | 63 | uint16_t temp; |
shinshingo | 0:28c89a4b6b69 | 64 | |
shinshingo | 0:28c89a4b6b69 | 65 | cmd[0] = 0x25; |
shinshingo | 0:28c89a4b6b69 | 66 | cmd[1] = 0; |
shinshingo | 0:28c89a4b6b69 | 67 | cmd[2] = 0; |
shinshingo | 0:28c89a4b6b69 | 68 | |
shinshingo | 0:28c89a4b6b69 | 69 | i2c->stop(); |
shinshingo | 0:28c89a4b6b69 | 70 | wait_us(5); |
shinshingo | 0:28c89a4b6b69 | 71 | ch1 = i2c->write(0xb6, cmd, 1, true); |
shinshingo | 0:28c89a4b6b69 | 72 | if (ch1 != 0) {return false;} |
shinshingo | 0:28c89a4b6b69 | 73 | ch2 = i2c->read(0xb7, cmd, 3); |
shinshingo | 0:28c89a4b6b69 | 74 | if (ch2 != 0) {return false;} |
shinshingo | 0:28c89a4b6b69 | 75 | wait_us(5); |
shinshingo | 0:28c89a4b6b69 | 76 | temp = (uint16_t)((cmd[1]<<8)|cmd[0]); |
shinshingo | 0:28c89a4b6b69 | 77 | if(temp & 0x8000) *ir_val = ~((int16_t)(temp & 0x7fff))+1; |
shinshingo | 0:28c89a4b6b69 | 78 | else *ir_val = (int16_t)temp; |
shinshingo | 0:28c89a4b6b69 | 79 | return true; |
shinshingo | 0:28c89a4b6b69 | 80 | |
shinshingo | 0:28c89a4b6b69 | 81 | } |