temp sensor: [#61] Added placeholder for the sensor interface.
This commit is contained in:
parent
34618d640d
commit
7cc658bc2e
57
source/shoh/src/threads/temperature/SensorTempSHT20.cpp
Normal file
57
source/shoh/src/threads/temperature/SensorTempSHT20.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* SensorTempSHT20.cpp
|
||||
*
|
||||
* Created on: 16 May 2023
|
||||
*/
|
||||
|
||||
#include "SensorTempSHT20.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "Log.h"
|
||||
|
||||
//D6U9H:
|
||||
//D - Digital (i2c)
|
||||
//6 - 2016 year of production
|
||||
//U9H - Sensirion undecodable crap
|
||||
//Address: 0x40
|
||||
|
||||
//Trigger T measurement | hold master | 1110 0011 - 0xe3
|
||||
//Trigger T measurement | no hold master | 1111 0011 - 0xf3
|
||||
//Write user register | | 1110 0110 - 0xe6
|
||||
//Read user register | | 1110 0111 - 0xe7
|
||||
//Soft reset | | 1111 1110 - 0xfe
|
||||
|
||||
//Use hold master - read(com = 0xe3)
|
||||
//Reading is done via 3 bytes.
|
||||
//WRITE: I2C address + write | read command
|
||||
//READ: Data (MSB) | Data (LSB) + Stat. | Checksum
|
||||
|
||||
|
||||
SensorTempSHT20::SensorTempSHT20(I2C* pi2c)
|
||||
: _pi2c(pi2c), _dev_addr(0x40)
|
||||
{}
|
||||
|
||||
SensorTempSHT20::~SensorTempSHT20()
|
||||
{}
|
||||
/*
|
||||
const int16_t POLYNOMIAL = 0x131;
|
||||
|
||||
int8_t SHT2x_CheckCrc(int8_t data[], int8_t nbrOfBytes, int8_t checksum)
|
||||
{
|
||||
int8_t crc = 0;
|
||||
int8_t bit;
|
||||
int8_t byteCtr;
|
||||
//calculates 8-Bit checksum with given polynomial
|
||||
for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr)
|
||||
{
|
||||
crc ^= (data[byteCtr]);
|
||||
for ( bit = 8; bit > 0; --bit)
|
||||
{
|
||||
if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
|
||||
else crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
if (crc != checksum) return 1;
|
||||
else return 0;
|
||||
}
|
||||
*/
|
||||
28
source/shoh/src/threads/temperature/SensorTempSHT20.h
Normal file
28
source/shoh/src/threads/temperature/SensorTempSHT20.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SensorTempSHT20.h
|
||||
*
|
||||
* Created on: 16 May 2023
|
||||
*/
|
||||
|
||||
#ifndef THREADS_TEMPERATURE_SENSORTEMPTC74_H_
|
||||
#define THREADS_TEMPERATURE_SENSORTEMPTC74_H_
|
||||
|
||||
#include "I2C.h"
|
||||
#include "chip.h"
|
||||
|
||||
class SensorTempSHT20 {
|
||||
public:
|
||||
SensorTempSHT20(I2C* pi2c);
|
||||
virtual ~SensorTempSHT20();
|
||||
private:
|
||||
uint16_t read();
|
||||
|
||||
bool write_com(uint8_t com, uint8_t *trdata, const uint16_t size);
|
||||
bool read_com(uint8_t com, uint8_t *rdata, uint16_t size);
|
||||
|
||||
I2C* _pi2c;
|
||||
const uint8_t _dev_addr;
|
||||
bool _up_flag;
|
||||
};
|
||||
|
||||
#endif /* THREADS_TEMPERATURE_SENSORTEMPSHT20_H_ */
|
||||
Loading…
x
Reference in New Issue
Block a user