reformat source in uvosstyle
This commit is contained in:
313
CL56.cpp
313
CL56.cpp
@ -1,187 +1,188 @@
|
|||||||
#include "CL56.h"
|
#include "CL56.h"
|
||||||
|
|
||||||
DualCl56::DualCl56(ShiftReg<16>* shiftReg):
|
DualCl56::DualCl56(ShiftReg<16>* shiftReg):
|
||||||
_shiftReg(shiftReg)
|
_shiftReg(shiftReg)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DualCl56::tick()
|
void DualCl56::tick()
|
||||||
{
|
{
|
||||||
++_currentLit;
|
++_currentLit;
|
||||||
if(_currentLit > 7)
|
if(_currentLit > 7)
|
||||||
_currentLit = 0;
|
_currentLit = 0;
|
||||||
|
|
||||||
unsigned char bits[2] = {static_cast<unsigned char>(0b10000000 >> _currentLit),
|
unsigned char bits[2] = {static_cast<unsigned char>(0b10000000 >> _currentLit),
|
||||||
static_cast<unsigned char>(~(_segments[_currentLit]))};
|
static_cast<unsigned char>(~(_segments[_currentLit]))
|
||||||
|
};
|
||||||
|
|
||||||
if(!_blank)
|
if(!_blank)
|
||||||
_shiftReg->write(reinterpret_cast<unsigned char*>(&bits));
|
_shiftReg->write(reinterpret_cast<unsigned char*>(&bits));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DualCl56::setString(const char string[], const uint8_t dp)
|
void DualCl56::setString(const char string[], const uint8_t dp)
|
||||||
{
|
{
|
||||||
uint_fast8_t i = 0;
|
uint_fast8_t i = 0;
|
||||||
for(; i < 8 && string[i] != '\0'; i++)
|
for(; i < 8 && string[i] != '\0'; i++)
|
||||||
{
|
{
|
||||||
switch (string[i])
|
switch (string[i])
|
||||||
{
|
{
|
||||||
case '\0':
|
case '\0':
|
||||||
case '\n':
|
case '\n':
|
||||||
case ' ':
|
case ' ':
|
||||||
_segments[i] = 0;
|
_segments[i] = 0;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
_segments[i] = ZERO;
|
_segments[i] = ZERO;
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
_segments[i] = ONE;
|
_segments[i] = ONE;
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
_segments[i] = TOW;
|
_segments[i] = TOW;
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
_segments[i] = THREE;
|
_segments[i] = THREE;
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
_segments[i] = FOUR;
|
_segments[i] = FOUR;
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
_segments[i] = FIVE;
|
_segments[i] = FIVE;
|
||||||
break;
|
break;
|
||||||
case '6':
|
case '6':
|
||||||
_segments[i] = SIX;
|
_segments[i] = SIX;
|
||||||
break;
|
break;
|
||||||
case '7':
|
case '7':
|
||||||
_segments[i] = SEVEN;
|
_segments[i] = SEVEN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '8':
|
case '8':
|
||||||
_segments[i] = EIGT;
|
_segments[i] = EIGT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '9':
|
case '9':
|
||||||
_segments[i] = NINE;
|
_segments[i] = NINE;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
_segments[i] = SIGA;
|
_segments[i] = SIGA;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'B':
|
case 'B':
|
||||||
_segments[i] = SIGB;
|
_segments[i] = SIGB;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
_segments[i] = SIGc;
|
_segments[i] = SIGc;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
_segments[i] = SIGC;
|
_segments[i] = SIGC;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'D':
|
case 'D':
|
||||||
_segments[i] = SIGD;
|
_segments[i] = SIGD;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
_segments[i] = SIGE;
|
_segments[i] = SIGE;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'F':
|
case 'F':
|
||||||
_segments[i] = SIGF;
|
_segments[i] = SIGF;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
_segments[i] = SIGG;
|
_segments[i] = SIGG;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
_segments[i] = SIGh;
|
_segments[i] = SIGh;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
_segments[i] = SIGH;
|
_segments[i] = SIGH;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'I':
|
case 'I':
|
||||||
_segments[i] = SIGI;
|
_segments[i] = SIGI;
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
case 'J':
|
case 'J':
|
||||||
_segments[i] = SIGJ;
|
_segments[i] = SIGJ;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
_segments[i] = SIGl;
|
_segments[i] = SIGl;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
_segments[i] = SIGL;
|
_segments[i] = SIGL;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
case 'N':
|
case 'N':
|
||||||
_segments[i] = SIGN;
|
_segments[i] = SIGN;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
_segments[i] = SIGo;
|
_segments[i] = SIGo;
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
_segments[i] = SIGO;
|
_segments[i] = SIGO;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'P':
|
case 'P':
|
||||||
_segments[i] = SIGP;
|
_segments[i] = SIGP;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'R':
|
case 'R':
|
||||||
_segments[i] = SIGR;
|
_segments[i] = SIGR;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
case 'S':
|
case 'S':
|
||||||
_segments[i] = SIGS;
|
_segments[i] = SIGS;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
case 'T':
|
case 'T':
|
||||||
_segments[i] = SIGT;
|
_segments[i] = SIGT;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
case 'U':
|
case 'U':
|
||||||
_segments[i] = SIGU;
|
_segments[i] = SIGU;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
case 'V':
|
case 'V':
|
||||||
_segments[i] = SIGV;
|
_segments[i] = SIGV;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X':
|
case 'X':
|
||||||
_segments[i] = SIGX;
|
_segments[i] = SIGX;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
case 'Y':
|
case 'Y':
|
||||||
_segments[i] = SIGY;
|
_segments[i] = SIGY;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
_segments[i] = MINUS;
|
_segments[i] = MINUS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_segments[i] = INVLD;
|
_segments[i] = INVLD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( (1 << i) & dp ) _segments[i] |= 1;
|
if( (1 << i) & dp ) _segments[i] |= 1;
|
||||||
else _segments[i] &= ~1;
|
else _segments[i] &= ~1;
|
||||||
}
|
}
|
||||||
if(string[i] == '\0') for(; i < 8; i++) _segments[i]&=SEG_DP;
|
if(string[i] == '\0') for(; i < 8; i++) _segments[i]&=SEG_DP;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DualCl56::setSegments(const uint8_t segments, const uint8_t place)
|
void DualCl56::setSegments(const uint8_t segments, const uint8_t place)
|
||||||
{
|
{
|
||||||
_segments[place] = segments;
|
_segments[place] = segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DualCl56::setBlank(bool blankIn)
|
void DualCl56::setBlank(bool blankIn)
|
||||||
{
|
{
|
||||||
_blank = blankIn;
|
_blank = blankIn;
|
||||||
if(_blank)
|
if(_blank)
|
||||||
_shiftReg->clear();
|
_shiftReg->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DualCl56::getBlank()
|
bool DualCl56::getBlank()
|
||||||
{
|
{
|
||||||
return _blank;
|
return _blank;
|
||||||
}
|
}
|
||||||
|
137
CL56.h
137
CL56.h
@ -5,84 +5,83 @@
|
|||||||
|
|
||||||
class DualCl56
|
class DualCl56
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static constexpr uint8_t SEG_A = 0b10000000;
|
static constexpr uint8_t SEG_A = 0b10000000;
|
||||||
static constexpr uint8_t SEG_B = 0b01000000;
|
static constexpr uint8_t SEG_B = 0b01000000;
|
||||||
static constexpr uint8_t SEG_C = 0b00100000;
|
static constexpr uint8_t SEG_C = 0b00100000;
|
||||||
static constexpr uint8_t SEG_D = 0b00010000;
|
static constexpr uint8_t SEG_D = 0b00010000;
|
||||||
static constexpr uint8_t SEG_E = 0b00001000;
|
static constexpr uint8_t SEG_E = 0b00001000;
|
||||||
static constexpr uint8_t SEG_F = 0b00000100;
|
static constexpr uint8_t SEG_F = 0b00000100;
|
||||||
static constexpr uint8_t SEG_G = 0b00000010;
|
static constexpr uint8_t SEG_G = 0b00000010;
|
||||||
static constexpr uint8_t SEG_DP= 0b00000001;
|
static constexpr uint8_t SEG_DP= 0b00000001;
|
||||||
|
|
||||||
static constexpr uint8_t COLEN_A = 0b00000010;
|
static constexpr uint8_t COLEN_A = 0b00000010;
|
||||||
static constexpr uint8_t COLEN_B = 0b00100000;
|
static constexpr uint8_t COLEN_B = 0b00100000;
|
||||||
static constexpr uint8_t DP_A = 0b00000000;
|
static constexpr uint8_t DP_A = 0b00000000;
|
||||||
static constexpr uint8_t DP_B = 0b00000001;
|
static constexpr uint8_t DP_B = 0b00000001;
|
||||||
static constexpr uint8_t DP_C = 0b00000100;
|
static constexpr uint8_t DP_C = 0b00000100;
|
||||||
static constexpr uint8_t DP_D = 0b00001000;
|
static constexpr uint8_t DP_D = 0b00001000;
|
||||||
static constexpr uint8_t DP_E = 0b00000000;
|
static constexpr uint8_t DP_E = 0b00000000;
|
||||||
static constexpr uint8_t DP_F = 0b00010000;
|
static constexpr uint8_t DP_F = 0b00010000;
|
||||||
static constexpr uint8_t DP_G = 0b01000000;
|
static constexpr uint8_t DP_G = 0b01000000;
|
||||||
static constexpr uint8_t DP_H = 0b10000000;
|
static constexpr uint8_t DP_H = 0b10000000;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static constexpr uint8_t ZERO = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F;
|
static constexpr uint8_t ZERO = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F;
|
||||||
static constexpr uint8_t ONE = SEG_B | SEG_C;
|
static constexpr uint8_t ONE = SEG_B | SEG_C;
|
||||||
static constexpr uint8_t TOW = SEG_A | SEG_B | SEG_G | SEG_E | SEG_D;
|
static constexpr uint8_t TOW = SEG_A | SEG_B | SEG_G | SEG_E | SEG_D;
|
||||||
static constexpr uint8_t THREE = SEG_A | SEG_B | SEG_C | SEG_D | SEG_G;
|
static constexpr uint8_t THREE = SEG_A | SEG_B | SEG_C | SEG_D | SEG_G;
|
||||||
static constexpr uint8_t FOUR = SEG_B | SEG_C | SEG_F | SEG_G;
|
static constexpr uint8_t FOUR = SEG_B | SEG_C | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t FIVE =SEG_A | SEG_C | SEG_D | SEG_F | SEG_G;
|
static constexpr uint8_t FIVE =SEG_A | SEG_C | SEG_D | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIX = SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t SIX = SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SEVEN= SEG_A | SEG_B | SEG_C;
|
static constexpr uint8_t SEVEN= SEG_A | SEG_B | SEG_C;
|
||||||
static constexpr uint8_t EIGT = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t EIGT = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t NINE = SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G;
|
static constexpr uint8_t NINE = SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t MINUS = SEG_G;
|
static constexpr uint8_t MINUS = SEG_G;
|
||||||
static constexpr uint8_t SIGA = SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t SIGA = SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIGB = SEG_F | SEG_E | SEG_D | SEG_C | SEG_G;
|
static constexpr uint8_t SIGB = SEG_F | SEG_E | SEG_D | SEG_C | SEG_G;
|
||||||
static constexpr uint8_t SIGC = SEG_A | SEG_D | SEG_E | SEG_F;
|
static constexpr uint8_t SIGC = SEG_A | SEG_D | SEG_E | SEG_F;
|
||||||
static constexpr uint8_t SIGc = SEG_G | SEG_D | SEG_E;
|
static constexpr uint8_t SIGc = SEG_G | SEG_D | SEG_E;
|
||||||
static constexpr uint8_t SIGD = SEG_B | SEG_C | SEG_D | SEG_G | SEG_E;
|
static constexpr uint8_t SIGD = SEG_B | SEG_C | SEG_D | SEG_G | SEG_E;
|
||||||
static constexpr uint8_t SIGE = SEG_A | SEG_D | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t SIGE = SEG_A | SEG_D | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIGF = SEG_A | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t SIGF = SEG_A | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIGG = NINE;
|
static constexpr uint8_t SIGG = NINE;
|
||||||
static constexpr uint8_t SIGH = SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t SIGH = SEG_B | SEG_C | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIGh = SEG_D | SEG_C | SEG_E | SEG_F | SEG_G;
|
static constexpr uint8_t SIGh = SEG_D | SEG_C | SEG_E | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIGI = SEG_E;
|
static constexpr uint8_t SIGI = SEG_E;
|
||||||
static constexpr uint8_t SIGJ = SEG_B | SEG_C | SEG_D;
|
static constexpr uint8_t SIGJ = SEG_B | SEG_C | SEG_D;
|
||||||
static constexpr uint8_t SIGL = SEG_F | SEG_E | SEG_D;
|
static constexpr uint8_t SIGL = SEG_F | SEG_E | SEG_D;
|
||||||
static constexpr uint8_t SIGl = SEG_F | SEG_E;
|
static constexpr uint8_t SIGl = SEG_F | SEG_E;
|
||||||
static constexpr uint8_t SIGN = SEG_C | SEG_E | SEG_G;
|
static constexpr uint8_t SIGN = SEG_C | SEG_E | SEG_G;
|
||||||
static constexpr uint8_t SIGO = ZERO;
|
static constexpr uint8_t SIGO = ZERO;
|
||||||
static constexpr uint8_t SIGo = SEG_E | SEG_G | SEG_C | SEG_D;
|
static constexpr uint8_t SIGo = SEG_E | SEG_G | SEG_C | SEG_D;
|
||||||
static constexpr uint8_t SIGP = SEG_A | SEG_B | SEG_G | SEG_F | SEG_E;
|
static constexpr uint8_t SIGP = SEG_A | SEG_B | SEG_G | SEG_F | SEG_E;
|
||||||
static constexpr uint8_t SIGR = SEG_G | SEG_E;
|
static constexpr uint8_t SIGR = SEG_G | SEG_E;
|
||||||
static constexpr uint8_t SIGS = SEG_A | SEG_C | SEG_D | SEG_F | SEG_G;
|
static constexpr uint8_t SIGS = SEG_A | SEG_C | SEG_D | SEG_F | SEG_G;
|
||||||
static constexpr uint8_t SIGT = SEG_F | SEG_E | SEG_C | SEG_D;
|
static constexpr uint8_t SIGT = SEG_F | SEG_E | SEG_C | SEG_D;
|
||||||
static constexpr uint8_t SIGU = SEG_B | SEG_C | SEG_D | SEG_E | SEG_F;
|
static constexpr uint8_t SIGU = SEG_B | SEG_C | SEG_D | SEG_E | SEG_F;
|
||||||
static constexpr uint8_t SIGV = SIGU;
|
static constexpr uint8_t SIGV = SIGU;
|
||||||
static constexpr uint8_t SIGX = SIGH;
|
static constexpr uint8_t SIGX = SIGH;
|
||||||
static constexpr uint8_t SIGY = SEG_F | SEG_B | SEG_G | SEG_E;
|
static constexpr uint8_t SIGY = SEG_F | SEG_B | SEG_G | SEG_E;
|
||||||
static constexpr uint8_t INVLD = SEG_A | SEG_D;
|
static constexpr uint8_t INVLD = SEG_A | SEG_D;
|
||||||
|
|
||||||
uint8_t _currentLit = 0;
|
uint8_t _currentLit = 0;
|
||||||
uint8_t _segments[8] = {SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_G, SEG_DP, FIVE};
|
uint8_t _segments[8] = {SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_G, SEG_DP, FIVE};
|
||||||
|
|
||||||
ShiftReg<16>* _shiftReg;
|
ShiftReg<16>* _shiftReg;
|
||||||
|
|
||||||
bool _blank = false;
|
bool _blank = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DualCl56(ShiftReg<16>* shiftReg);
|
DualCl56(ShiftReg<16>* shiftReg);
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
void setBlank(bool blank);
|
void setBlank(bool blank);
|
||||||
bool getBlank();
|
bool getBlank();
|
||||||
|
|
||||||
void setString(const char* string, const uint8_t dp = 0);
|
void setString(const char* string, const uint8_t dp = 0);
|
||||||
void setSegments(const uint8_t segments, const uint8_t place);
|
void setSegments(const uint8_t segments, const uint8_t place);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,63 +7,63 @@ unsigned char _pin = PD2;
|
|||||||
|
|
||||||
void WirelessRelay::sendId()
|
void WirelessRelay::sendId()
|
||||||
{
|
{
|
||||||
writePin(_port,_pin,true);
|
writePin(_port,_pin,true);
|
||||||
_delay_us(SMALL_TIME);
|
_delay_us(SMALL_TIME);
|
||||||
writePin(_port,_pin,false);
|
writePin(_port,_pin,false);
|
||||||
_delay_us(LARGE_TIME);
|
_delay_us(LARGE_TIME);
|
||||||
|
|
||||||
for(short i = 0; i<10; i++)
|
for(short i = 0; i<10; i++)
|
||||||
{
|
{
|
||||||
sendBit( id & 1 << (15 - i) );
|
sendBit( id & 1 << (15 - i) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirelessRelay::sendBit(const bool in)
|
void WirelessRelay::sendBit(const bool in)
|
||||||
{
|
{
|
||||||
switch(in)
|
switch(in)
|
||||||
{
|
{
|
||||||
case true:
|
case true:
|
||||||
//Der Code fuer '0'
|
//Der Code fuer '0'
|
||||||
writePin(_port,_pin,true);
|
writePin(_port,_pin,true);
|
||||||
_delay_us(SMALL_TIME);
|
_delay_us(SMALL_TIME);
|
||||||
writePin(_port,_pin,false);
|
writePin(_port,_pin,false);
|
||||||
_delay_us(LARGE_TIME);
|
_delay_us(LARGE_TIME);
|
||||||
writePin(_port,_pin,true);
|
writePin(_port,_pin,true);
|
||||||
_delay_us(SMALL_TIME);
|
_delay_us(SMALL_TIME);
|
||||||
writePin(_port,_pin,false);
|
writePin(_port,_pin,false);
|
||||||
_delay_us(LARGE_TIME);
|
_delay_us(LARGE_TIME);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case false:
|
case false:
|
||||||
//Der Code fuer '1'
|
//Der Code fuer '1'
|
||||||
writePin(_port,_pin,true);
|
writePin(_port,_pin,true);
|
||||||
_delay_us(LARGE_TIME);
|
_delay_us(LARGE_TIME);
|
||||||
writePin(_port,_pin,false);
|
writePin(_port,_pin,false);
|
||||||
_delay_us(SMALL_TIME);
|
_delay_us(SMALL_TIME);
|
||||||
writePin(_port,_pin,true);
|
writePin(_port,_pin,true);
|
||||||
_delay_us(SMALL_TIME);
|
_delay_us(SMALL_TIME);
|
||||||
writePin(_port,_pin,false);
|
writePin(_port,_pin,false);
|
||||||
_delay_us(LARGE_TIME);
|
_delay_us(LARGE_TIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirelessRelay::sync()
|
void WirelessRelay::sync()
|
||||||
{
|
{
|
||||||
writePin(_port,_pin,false);
|
writePin(_port,_pin,false);
|
||||||
_delay_us(SMALL_TIME*31);
|
_delay_us(SMALL_TIME*31);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirelessRelay::setValue(const uint8_t value)
|
void WirelessRelay::setValue(const uint8_t value)
|
||||||
{
|
{
|
||||||
lastValue = value;
|
lastValue = value;
|
||||||
for(short z = 0; z<10; z++)
|
for(short z = 0; z<10; z++)
|
||||||
{
|
{
|
||||||
sendId();
|
sendId();
|
||||||
sendBit(value);
|
sendBit(value);
|
||||||
sendBit(!value);
|
sendBit(!value);
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirelessRelay::resend()
|
void WirelessRelay::resend()
|
||||||
@ -73,13 +73,13 @@ void WirelessRelay::resend()
|
|||||||
|
|
||||||
WirelessRelay::WirelessRelay(const uint16_t idIn, char nameIn[])
|
WirelessRelay::WirelessRelay(const uint16_t idIn, char nameIn[])
|
||||||
{
|
{
|
||||||
id = idIn;
|
id = idIn;
|
||||||
setName(nameIn);
|
setName(nameIn);
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WirelessRelay::WirelessRelay(const Item& item)
|
WirelessRelay::WirelessRelay(const Item& item)
|
||||||
{
|
{
|
||||||
Item::operator=(item);
|
Item::operator=(item);
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
}
|
||||||
|
@ -8,20 +8,20 @@
|
|||||||
class WirelessRelay: public Item
|
class WirelessRelay: public Item
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static constexpr uint16_t LARGE_TIME = 750;
|
static constexpr uint16_t LARGE_TIME = 750;
|
||||||
static constexpr uint8_t SMALL_TIME = 250;
|
static constexpr uint8_t SMALL_TIME = 250;
|
||||||
|
|
||||||
static constexpr uint16_t MAX_NAME_LENGTH = 16;
|
static constexpr uint16_t MAX_NAME_LENGTH = 16;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendBit(const bool i);
|
void sendBit(const bool i);
|
||||||
void sync();
|
void sync();
|
||||||
void sendId();
|
void sendId();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WirelessRelay(const uint16_t idIn, char nameIn[]);
|
WirelessRelay(const uint16_t idIn, char nameIn[]);
|
||||||
WirelessRelay(const Item& item);
|
WirelessRelay(const Item& item);
|
||||||
void setValue(const uint8_t value);
|
void setValue(const uint8_t value);
|
||||||
void resend();
|
void resend();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
30
dht11.cpp
30
dht11.cpp
@ -1,6 +1,8 @@
|
|||||||
#include "dht11.h"
|
#include "dht11.h"
|
||||||
|
|
||||||
Dht11::Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort, volatile unsigned char * const port_ctl, const unsigned char pin): _port(port), _port_ctl(port_ctl), _inPort(inPort), _pin(pin)
|
Dht11::Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort,
|
||||||
|
volatile unsigned char * const port_ctl, const unsigned char pin): _port(port), _port_ctl(port_ctl), _inPort(inPort),
|
||||||
|
_pin(pin)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
uint8_t Dht11::read()
|
uint8_t Dht11::read()
|
||||||
@ -17,7 +19,7 @@ uint8_t Dht11::read()
|
|||||||
setDirection(_port_ctl, _pin, true);
|
setDirection(_port_ctl, _pin, true);
|
||||||
writePin(_port, _pin, false);
|
writePin(_port, _pin, false);
|
||||||
_delay_ms(18);
|
_delay_ms(18);
|
||||||
writePin(_port, _pin, true);
|
writePin(_port, _pin, true);
|
||||||
setDirection(_port_ctl, _pin, false);
|
setDirection(_port_ctl, _pin, false);
|
||||||
_delay_us(42);
|
_delay_us(42);
|
||||||
|
|
||||||
@ -28,10 +30,10 @@ uint8_t Dht11::read()
|
|||||||
loopCnt = LOOP_TIMEOUT_COUNT;
|
loopCnt = LOOP_TIMEOUT_COUNT;
|
||||||
while(readPin(_inPort, _pin) ) if (loopCnt-- == 0) return 2;
|
while(readPin(_inPort, _pin) ) if (loopCnt-- == 0) return 2;
|
||||||
|
|
||||||
PORTD |= 1 << PD1;
|
PORTD |= 1 << PD1;
|
||||||
PORTD &= ~(1 << PD1);
|
PORTD &= ~(1 << PD1);
|
||||||
PORTD |= 1 << PD1;
|
PORTD |= 1 << PD1;
|
||||||
PORTD &= ~(1 << PD1);
|
PORTD &= ~(1 << PD1);
|
||||||
|
|
||||||
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
|
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
|
||||||
for (uint8_t i=0; i<40; i++)
|
for (uint8_t i=0; i<40; i++)
|
||||||
@ -39,10 +41,10 @@ uint8_t Dht11::read()
|
|||||||
loopCnt = LOOP_TIMEOUT_COUNT;
|
loopCnt = LOOP_TIMEOUT_COUNT;
|
||||||
while(!readPin(_inPort, _pin))
|
while(!readPin(_inPort, _pin))
|
||||||
if (loopCnt-- == 0)
|
if (loopCnt-- == 0)
|
||||||
{
|
{
|
||||||
PORTD |= 1 << PD1;
|
PORTD |= 1 << PD1;
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
loopCnt = 0;
|
loopCnt = 0;
|
||||||
while(readPin(_inPort, _pin))
|
while(readPin(_inPort, _pin))
|
||||||
@ -52,11 +54,11 @@ uint8_t Dht11::read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( loopCnt > BIT_COUNT )
|
if( loopCnt > BIT_COUNT )
|
||||||
{
|
{
|
||||||
PORTD |= 1 << PD1;
|
PORTD |= 1 << PD1;
|
||||||
PORTD &= ~(1 << PD1);
|
PORTD &= ~(1 << PD1);
|
||||||
bits[idx] |= (1 << cnt);
|
bits[idx] |= (1 << cnt);
|
||||||
}
|
}
|
||||||
if (cnt == 0) // next byte?
|
if (cnt == 0) // next byte?
|
||||||
{
|
{
|
||||||
cnt = 7; // restart at MSB
|
cnt = 7; // restart at MSB
|
||||||
|
17
dht11.h
17
dht11.h
@ -10,14 +10,15 @@ class Dht11
|
|||||||
static constexpr uint8_t BIT_COUNT = 5;//(6.0 / 16000000.0)*F_CPU;
|
static constexpr uint8_t BIT_COUNT = 5;//(6.0 / 16000000.0)*F_CPU;
|
||||||
static constexpr bool DHT22 = true;
|
static constexpr bool DHT22 = true;
|
||||||
|
|
||||||
volatile unsigned char * const _port;
|
volatile unsigned char * const _port;
|
||||||
volatile unsigned char * const _port_ctl;
|
volatile unsigned char * const _port_ctl;
|
||||||
volatile unsigned char * const _inPort;
|
volatile unsigned char * const _inPort;
|
||||||
const unsigned char _pin;
|
const unsigned char _pin;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort, volatile unsigned char * const port_ctl, const unsigned char pin);
|
Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort,
|
||||||
uint8_t read();
|
volatile unsigned char * const port_ctl, const unsigned char pin);
|
||||||
int16_t humidity = 0;
|
uint8_t read();
|
||||||
int16_t temperature = 0;
|
int16_t humidity = 0;
|
||||||
|
int16_t temperature = 0;
|
||||||
};
|
};
|
||||||
|
20
main.cpp
20
main.cpp
@ -185,18 +185,17 @@ void reciverError(uint8_t code, void* userData)
|
|||||||
inline static void printHelp(Serial* serial)
|
inline static void printHelp(Serial* serial)
|
||||||
{
|
{
|
||||||
serial->write_p(PSTR("Available Commands: \n"
|
serial->write_p(PSTR("Available Commands: \n"
|
||||||
"help : Show this prompt.\n"
|
"help : Show this prompt.\n"
|
||||||
"date : Show current date and time.\n"
|
"date : Show current date and time.\n"
|
||||||
"set [yyyy] [mm] [dd] [hh] [mm] [ss] : Show current date and time.\n"
|
"set [yyyy] [mm] [dd] [hh] [mm] [ss] : Show current date and time.\n"
|
||||||
"pause : pause sensor output.\n"
|
"pause : pause sensor output.\n"
|
||||||
"resume : resume sensor output.\n"
|
"resume : resume sensor output.\n"
|
||||||
"dump : Dump epprom.\n"
|
"dump : Dump epprom.\n"
|
||||||
"free : Show free ram.\n"
|
"free : Show free ram.\n"
|
||||||
"beep : Test buzzer.\n"
|
"beep : Test buzzer.\n"
|
||||||
"list : List sensors.\n"));
|
"list : List sensors.\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int freeRAM()
|
int freeRAM()
|
||||||
{
|
{
|
||||||
extern int __heap_start, *__brkval;
|
extern int __heap_start, *__brkval;
|
||||||
@ -502,4 +501,3 @@ int main()
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user