Some Arduino refactoring and it builds now
This commit is contained in:
parent
606e767f34
commit
d377bbc0a9
14 changed files with 92 additions and 62 deletions
|
|
@ -27,10 +27,12 @@ void ProtocolOregon::setConsumption(unsigned int cons)
|
|||
this->humidity = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ProtocolOregon::send()
|
||||
{
|
||||
byte buffer[9];
|
||||
setType(buffer, { 0x1A,0x2D }); //temperature/humidity sensor (THGR2228N)
|
||||
setType(buffer, 0x1A,0x2D); //temperature/humidity sensor (THGR2228N)
|
||||
setChannel(buffer, 0x20);
|
||||
setId(buffer, address); //set id of the sensor, BB=187
|
||||
setBatteryLevel(buffer, true); // false : low, true : high
|
||||
|
|
@ -53,10 +55,10 @@ void ProtocolOregon::send()
|
|||
* \param data Oregon message
|
||||
* \param type Sensor type
|
||||
*/
|
||||
inline void setType(byte *data, byte* type)
|
||||
inline void ProtocolOregon::setType(byte *data, byte b1, byte b2)
|
||||
{
|
||||
data[0] = type[0];
|
||||
data[1] = type[1];
|
||||
data[0] = b1;
|
||||
data[1] = b2;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,13 +66,13 @@ inline void setType(byte *data, byte* type)
|
|||
* \param data Oregon message
|
||||
* \param channel Sensor channel (0x10, 0x20, 0x30)
|
||||
*/
|
||||
inline void setChannel(byte *data, byte channel)
|
||||
inline void ProtocolOregon::setChannel(byte *data, byte channel)
|
||||
{
|
||||
data[2] = channel;
|
||||
}
|
||||
|
||||
|
||||
inline void setId(byte *data, byte id)
|
||||
inline void ProtocolOregon::setId(byte *data, byte id)
|
||||
{
|
||||
data[3] = id;
|
||||
}
|
||||
|
|
@ -78,13 +80,13 @@ inline void setId(byte *data, byte id)
|
|||
/**
|
||||
* \param level false: low, true: high
|
||||
*/
|
||||
inline void setBatteryLevel(byte *data, bool level)
|
||||
inline void ProtocolOregon::setBatteryLevel(byte *data, bool level)
|
||||
{
|
||||
if(!level) data[4] = 0x0C;
|
||||
else data[4] = 0x00;
|
||||
}
|
||||
|
||||
inline void setTemperature(byte *data, float temp)
|
||||
inline void ProtocolOregon::setTemperature(byte *data, float temp)
|
||||
{
|
||||
// Set temperature sign
|
||||
if(temp < 0)
|
||||
|
|
@ -112,13 +114,13 @@ inline void setTemperature(byte *data, float temp)
|
|||
data[4] |= (tempFloat << 4);
|
||||
}
|
||||
|
||||
inline void setHumidity(byte* data, byte hum)
|
||||
inline void ProtocolOregon::setHumidity(byte* data, byte hum)
|
||||
{
|
||||
data[7] = (hum/10);
|
||||
data[6] |= (hum - data[7]*10) << 4;
|
||||
}
|
||||
|
||||
inline void calculateAndSetChecksum(byte* data)
|
||||
inline void ProtocolOregon::calculateAndSetChecksum(byte* data)
|
||||
{
|
||||
int sum = 0;
|
||||
for(byte i = 0; i<8;i++)
|
||||
|
|
@ -141,7 +143,7 @@ inline void calculateAndSetChecksum(byte* data)
|
|||
* \ of the RF signal at the middle of a clock period.
|
||||
* \ Remember, the Oregon v2.1 protocol adds an inverted bit first
|
||||
*/
|
||||
inline void sendZero(void)
|
||||
inline void ProtocolOregon::sendZero(void)
|
||||
{
|
||||
RF_SEND_HIGH();
|
||||
delayMicroseconds(RF_DELAY);
|
||||
|
|
@ -157,7 +159,7 @@ inline void sendZero(void)
|
|||
* \ of the RF signal at the middle of a clock period.
|
||||
* \ Remember, the Oregon v2.1 protocol add an inverted bit first
|
||||
*/
|
||||
inline void sendOne(void)
|
||||
inline void ProtocolOregon::sendOne(void)
|
||||
{
|
||||
RF_SEND_LOW();
|
||||
delayMicroseconds(RF_DELAY);
|
||||
|
|
@ -177,7 +179,7 @@ inline void sendOne(void)
|
|||
* \param data Data to send
|
||||
* \param length size of data array
|
||||
*/
|
||||
void sendData(byte *data, byte length)
|
||||
void ProtocolOregon::sendData(byte *data, byte length)
|
||||
{
|
||||
for(byte i = 0; i < length; ++i)
|
||||
{
|
||||
|
|
@ -196,15 +198,17 @@ void sendData(byte *data, byte length)
|
|||
* \brief Send an Oregon message
|
||||
* \param data The Oregon message
|
||||
*/
|
||||
void rfSend(byte *data, byte size)
|
||||
void ProtocolOregon::rfSend(byte *data, byte size)
|
||||
{
|
||||
// Send preamble
|
||||
sendData({ 0xFF,0xFF }, 2);
|
||||
byte preamble[] = { 0xFF,0xFF };
|
||||
sendData(preamble, 2);
|
||||
// Send sync nibble
|
||||
//sendQuarterLSB(0xA); // It is not use in this version since the sync nibble is include in the Oregon message to send.
|
||||
// Send data
|
||||
sendData(data, size);
|
||||
// Send postamble
|
||||
sendData({ 0x00 }, 1);
|
||||
byte postamble[] = { 0x00 };
|
||||
sendData(postamble, 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue