Add Payload Helper Functions to AttSensor Class
This commit is contained in:
parent
b498364a57
commit
054f27ebee
7 changed files with 27 additions and 44 deletions
|
@ -39,6 +39,18 @@ class AttSensor {
|
|||
|
||||
// Return the number of Bytes added to the Payload
|
||||
virtual uint8_t numBytes(void) = 0;
|
||||
|
||||
// Helper Functions to Put Values Into the Payload Array
|
||||
static void int32ToPayload(int32_t value, char *payload, uint8_t startbyte) {
|
||||
payload[startbyte] = (value) & 0XFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0XFF;
|
||||
payload[startbyte+2] = (value >> 16) & 0XFF;
|
||||
payload[startbyte+3] = (value >> 24) & 0XFF;
|
||||
}
|
||||
static void int16ToPayload(int16_t value, char *payload, uint8_t startbyte) {
|
||||
payload[startbyte] = (value) & 0XFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0XFF;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -80,7 +80,7 @@ int32_t BME280::compensate_h(int32_t adc_H)
|
|||
uint8_t BME280::getSensorData(char *payload, uint8_t startbyte) {
|
||||
|
||||
int32_t UP, UT, UH;
|
||||
int32_t rawP, rawT, value;
|
||||
int32_t rawP, rawT;
|
||||
|
||||
// Trigger Measurement
|
||||
// Set Sensor Config
|
||||
|
@ -104,27 +104,13 @@ uint8_t BME280::getSensorData(char *payload, uint8_t startbyte) {
|
|||
// Read Humidity
|
||||
UH = read16(0xFD);
|
||||
|
||||
|
||||
// Temperature
|
||||
value = compensate_t(UT);
|
||||
payload[startbyte] = (value) & 0XFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0XFF;
|
||||
payload[startbyte+2] = (value >> 16) & 0XFF;
|
||||
payload[startbyte+3] = (value >> 24) & 0XFF;
|
||||
|
||||
int32ToPayload(compensate_t(UT), payload, startbyte);
|
||||
// Humidity
|
||||
value = compensate_h(UH);
|
||||
payload[startbyte+4] = (value) & 0XFF;
|
||||
payload[startbyte+5] = (value >> 8) & 0XFF;
|
||||
payload[startbyte+6] = (value >> 16) & 0XFF;
|
||||
payload[startbyte+7] = (value >> 24) & 0XFF;
|
||||
|
||||
int32ToPayload(compensate_h(UH), payload, startbyte+4);
|
||||
// Pressure
|
||||
value = compensate_p(UP);
|
||||
payload[startbyte+8] = (value) & 0XFF;
|
||||
payload[startbyte+9] = (value >> 8) & 0XFF;
|
||||
payload[startbyte+10] = (value >> 16) & 0XFF;
|
||||
payload[startbyte+11] = (value >> 24) & 0XFF;
|
||||
int32ToPayload(compensate_p(UP), payload, startbyte+8);
|
||||
|
||||
return startbyte+12;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,8 +125,8 @@ uint8_t DS18B20::getSensorData(char *payload, uint8_t startbyte){
|
|||
value = -85;
|
||||
}
|
||||
// Add to Payload
|
||||
payload[startbyte] = (value) & 0XFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0XFF;
|
||||
int16ToPayload(value, payload, startbyte);
|
||||
|
||||
// Set next Startbyte
|
||||
startbyte += 2;
|
||||
delay(50);
|
||||
|
|
|
@ -51,10 +51,8 @@ uint8_t MHZ19C::getSensorData(char * payload, uint8_t startbyte) {
|
|||
if (readBytes > 0) {
|
||||
switch(buffer[1]) {
|
||||
case 0x86:
|
||||
uint16_t value = (buffer[2]*256) + buffer[3];
|
||||
payload[startbyte] = (value) & 0xFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0xFF;
|
||||
break;
|
||||
int16ToPayload((buffer[2]*256) + buffer[3], payload, startbyte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return startbyte+2;
|
||||
|
|
|
@ -44,9 +44,7 @@ uint8_t SENSAIRS8::getSensorData(char *payload, uint8_t startbyte) {
|
|||
payload[startbyte] = 0x00;
|
||||
payload[startbyte+1] = 0x00;
|
||||
if (readBytes > 0) {
|
||||
uint16_t value = (buffer[3]*256) + buffer[4];
|
||||
payload[startbyte] = (value) & 0xFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0xFF;
|
||||
int16ToPayload((buffer[3]*256) + buffer[4], payload, startbyte);
|
||||
}
|
||||
return startbyte+2;
|
||||
}
|
||||
|
|
|
@ -44,10 +44,8 @@ uint8_t SG112A::getSensorData(char *payload, uint8_t startbyte) {
|
|||
if (readBytes > 0) {
|
||||
switch(buffer[2]) {
|
||||
case 0x15:
|
||||
uint16_t value = (buffer[5]*256) + buffer[4];
|
||||
payload[startbyte] = (value) & 0xFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0xFF;
|
||||
break;
|
||||
int16ToPayload((buffer[3]*256) + buffer[4], payload, startbyte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return startbyte+2;
|
||||
|
|
|
@ -54,18 +54,9 @@ uint16_t SHT21::sensorRead(uint8_t command) {
|
|||
|
||||
uint8_t SHT21::getSensorData(char *payload, uint8_t startbyte) {
|
||||
// Temperature
|
||||
int32_t value = (int32_t)((-46.85 + 175.72 / 65536.0 * (float)(sensorRead(SHT21_TEMPHOLD)))*100);
|
||||
payload[startbyte] = (value) & 0XFF;
|
||||
payload[startbyte+1] = (value >> 8) & 0XFF;
|
||||
payload[startbyte+2] = (value >> 16) & 0XFF;
|
||||
payload[startbyte+3] = (value >> 24) & 0XFF;
|
||||
|
||||
int32ToPayload((int32_t)((-46.85 + 175.72 / 65536.0 * (float)(sensorRead(SHT21_TEMPHOLD)))*100), payload, startbyte);
|
||||
// Humidity
|
||||
value = (int32_t)((-6.0 + 125.0 / 65536.0 * (float)(sensorRead(SHT21_HUMIHOLD)))*100);
|
||||
payload[startbyte+4] = (value) & 0XFF;
|
||||
payload[startbyte+5] = (value >> 8) & 0XFF;
|
||||
payload[startbyte+6] = (value >> 16) & 0XFF;
|
||||
payload[startbyte+7] = (value >> 24) & 0XFF;
|
||||
int32ToPayload((int32_t)((-6.0 + 125.0 / 65536.0 * (float)(sensorRead(SHT21_HUMIHOLD)))*100), payload, startbyte+4);
|
||||
|
||||
return startbyte+8;
|
||||
}
|
Loading…
Reference in a new issue