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