Initial commit
This commit is contained in:
commit
f83dd4f105
36 changed files with 3704 additions and 0 deletions
101
lib/NexusTX/NexusTX.cpp
Normal file
101
lib/NexusTX/NexusTX.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include "NexusTX.h"
|
||||
|
||||
NexusTX::NexusTX(byte tr_pin)
|
||||
{
|
||||
SendBuffer = new bool[buffer_size];
|
||||
TX_PIN = tr_pin;
|
||||
pinMode(TX_PIN, OUTPUT);
|
||||
digitalWrite(TX_PIN, LOW);
|
||||
SendBuffer[9] = 0;
|
||||
SendBuffer[24] = 1;
|
||||
SendBuffer[25] = 1;
|
||||
SendBuffer[26] = 1;
|
||||
SendBuffer[27] = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void NexusTX::tx_bit(bool b)
|
||||
{
|
||||
digitalWrite(TX_PIN, HIGH);
|
||||
delayMicroseconds(PULSE_HIGH);
|
||||
digitalWrite(TX_PIN, LOW);
|
||||
if (b == true)
|
||||
delayMicroseconds(PULSE_ONE);
|
||||
else
|
||||
delayMicroseconds(PULSE_ZERO);
|
||||
}
|
||||
|
||||
void NexusTX::setBatteryFlag(bool level)
|
||||
{
|
||||
SendBuffer[8] = level;
|
||||
}
|
||||
|
||||
void NexusTX::setHumidity(int h)
|
||||
{
|
||||
uint8_t h8 = (uint8_t)h;
|
||||
for (idx = 0; idx <= 7; idx++)
|
||||
{
|
||||
SendBuffer[35 - idx] = (h8 >> idx) & 0x1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NexusTX::setChannel(byte dev_ch)
|
||||
{
|
||||
SendBuffer[10] = dev_ch & 0x2;
|
||||
SendBuffer[11] = dev_ch & 0x1;
|
||||
}
|
||||
|
||||
void NexusTX::setId(byte dev_id)
|
||||
{
|
||||
int array_idx = 0;
|
||||
for (idx = 7; idx >= 0; idx--)
|
||||
{
|
||||
SendBuffer[array_idx++] = dev_id & (0x1 << idx);
|
||||
}
|
||||
}
|
||||
|
||||
void NexusTX::setTemperature(float t)
|
||||
{
|
||||
int16_t t12 = t * 10.0f;
|
||||
for (idx = 0; idx <= 11; idx++)
|
||||
{
|
||||
SendBuffer[23 - idx] = (t12 >> idx) & 0x1;
|
||||
}
|
||||
}
|
||||
|
||||
void NexusTX::SendNexus()
|
||||
{
|
||||
for (int i=0; i <buffer_size; i++)
|
||||
{
|
||||
tx_bit(SendBuffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void NexusTX::SendPacket()
|
||||
{
|
||||
for (idx = 1; idx < repeat; idx++)
|
||||
{
|
||||
SendNexus();
|
||||
if (idx + 1 == repeat) {break;} // do not send sync after last TX
|
||||
// sync bit
|
||||
digitalWrite(TX_PIN, HIGH);
|
||||
delayMicroseconds(PULSE_HIGH);
|
||||
digitalWrite(TX_PIN, LOW);
|
||||
delayMicroseconds(PULSE_SYNC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool NexusTX::transmit()
|
||||
{
|
||||
if (millis() >= time_marker_send && send_time)
|
||||
{
|
||||
time_marker_send = millis() + send_time;
|
||||
SendPacket();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
46
lib/NexusTX/NexusTX.h
Normal file
46
lib/NexusTX/NexusTX.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <Arduino.h>
|
||||
#ifndef NexusTX_h
|
||||
#define NexusTX_h
|
||||
|
||||
#define PULSE_HIGH 500 /* 500 us */
|
||||
#define PULSE_ZERO 1000 /* 1000 us */
|
||||
#define PULSE_ONE 2000 /* 2000 us */
|
||||
#define PULSE_SYNC 4000 /* 4000 us */
|
||||
|
||||
// Time between two TX = 56.75 seconds
|
||||
#define TX_INTERVAL 56750
|
||||
|
||||
// Bitstream repetition (this device sends the information 10 times)
|
||||
#define repeat 12
|
||||
|
||||
|
||||
|
||||
class NexusTX
|
||||
{
|
||||
public:
|
||||
|
||||
bool* SendBuffer;
|
||||
int buffer_size=36;
|
||||
int tx_interval = TX_INTERVAL;
|
||||
NexusTX(byte);
|
||||
void setChannel(byte);
|
||||
void setId(byte);
|
||||
void setBatteryFlag(bool);
|
||||
void setTemperature(float);
|
||||
void setHumidity(int);
|
||||
bool transmit();
|
||||
void SendPacket();
|
||||
|
||||
|
||||
private:
|
||||
void tx_bit(bool);
|
||||
byte TX_PIN;
|
||||
int idx = 0;
|
||||
void SendNexus();
|
||||
unsigned long time_marker_send = 0;
|
||||
unsigned long send_time = TX_INTERVAL;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue