implement single item resend
This commit is contained in:
8
item.cpp
8
item.cpp
@ -74,7 +74,7 @@ void Item::sendAddress(uint8_t address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item::sendRawAddr(const uint8_t address, const uint16_t data)
|
void Item::sendRawAddr(const uint8_t address, const uint16_t data, bool single)
|
||||||
{
|
{
|
||||||
for(uint8_t j = 0; j < SEND_COUNT; j++)
|
for(uint8_t j = 0; j < SEND_COUNT; j++)
|
||||||
{
|
{
|
||||||
@ -83,11 +83,13 @@ void Item::sendRawAddr(const uint8_t address, const uint16_t data)
|
|||||||
{
|
{
|
||||||
sendBit(data & (1 << i));
|
sendBit(data & (1 << i));
|
||||||
}
|
}
|
||||||
|
if(single || SEND_COUNT == 1)
|
||||||
|
return;
|
||||||
_delay_ms(1);
|
_delay_ms(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::sendRaw(const uint16_t data)
|
void Item::sendRaw(const uint16_t data, bool single)
|
||||||
{
|
{
|
||||||
sendRawAddr(_address, data);
|
sendRawAddr(_address, data, single);
|
||||||
}
|
}
|
||||||
|
6
item.h
6
item.h
@ -18,7 +18,7 @@ private:
|
|||||||
static constexpr unsigned char _pinLowA = PD4;
|
static constexpr unsigned char _pinLowA = PD4;
|
||||||
static constexpr unsigned char _pinHighB = PD2;
|
static constexpr unsigned char _pinHighB = PD2;
|
||||||
static constexpr unsigned char _pinLowB = PD3;
|
static constexpr unsigned char _pinLowB = PD3;
|
||||||
static constexpr uint8_t SEND_COUNT = 2;
|
static constexpr uint8_t SEND_COUNT = 1;
|
||||||
|
|
||||||
uint8_t _address;
|
uint8_t _address;
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ public:
|
|||||||
|
|
||||||
Item(const uint8_t address);
|
Item(const uint8_t address);
|
||||||
|
|
||||||
void sendRaw(const uint16_t data);
|
void sendRaw(const uint16_t data, bool single = false);
|
||||||
static void sendRawAddr(const uint8_t address, const uint16_t data);
|
static void sendRawAddr(const uint8_t address, const uint16_t data, bool single = false);
|
||||||
|
|
||||||
void setAddress(const uint8_t address);
|
void setAddress(const uint8_t address);
|
||||||
uint8_t getAddress();
|
uint8_t getAddress();
|
||||||
|
25
main.cpp
25
main.cpp
@ -252,7 +252,7 @@ void serialDispatch(Serial* serial)
|
|||||||
{
|
{
|
||||||
token = strtok(NULL, " ");
|
token = strtok(NULL, " ");
|
||||||
if(token != NULL)
|
if(token != NULL)
|
||||||
ret = nfcBoard.dispatch(token, serial);
|
ret = nfcBoard.dispatch(token);
|
||||||
}
|
}
|
||||||
else if(strncmp(token, "erase", 4) == 0)
|
else if(strncmp(token, "erase", 4) == 0)
|
||||||
{
|
{
|
||||||
@ -350,22 +350,31 @@ int main()
|
|||||||
|
|
||||||
serial->write_p(PSTR("TrainController v0.5 starting\n"));
|
serial->write_p(PSTR("TrainController v0.5 starting\n"));
|
||||||
|
|
||||||
|
uint8_t repeatCount = 0;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
if(resendEvent && (trains.count() || turnouts.count() || signals.count()))
|
if(resendEvent && (trains.count() || turnouts.count() || signals.count()))
|
||||||
{
|
{
|
||||||
timer0InterruptEnable(false);
|
|
||||||
if(itemToResend < trains.count())
|
if(itemToResend < trains.count())
|
||||||
trains[itemToResend].sendData();
|
trains[itemToResend].sendData(true);
|
||||||
else if(itemToResend < trains.count() + turnouts.count())
|
else if(itemToResend < trains.count() + turnouts.count())
|
||||||
turnouts[itemToResend-trains.count()].sendData();
|
turnouts[itemToResend-trains.count()].sendData(true);
|
||||||
else if(itemToResend < trains.count() + turnouts.count()+signals.count())
|
else if(itemToResend < trains.count() + turnouts.count()+signals.count())
|
||||||
signals[itemToResend-trains.count()-turnouts.count()].sendData();
|
signals[itemToResend-trains.count()-turnouts.count()].sendData(true);
|
||||||
|
resendEvent = false;
|
||||||
|
if(repeatCount == 0)
|
||||||
|
{
|
||||||
|
TCNT0 = 190;
|
||||||
|
repeatCount = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
itemToResend++;
|
itemToResend++;
|
||||||
if(trains.count()+turnouts.count()+signals.count() <= itemToResend)
|
if(trains.count()+turnouts.count()+signals.count() <= itemToResend)
|
||||||
itemToResend = 0;
|
itemToResend = 0;
|
||||||
resendEvent = false;
|
repeatCount = 0;
|
||||||
timer0InterruptEnable(true);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(autoff)
|
if(autoff)
|
||||||
@ -380,7 +389,9 @@ int main()
|
|||||||
Train::setOutput(Train::OFF);
|
Train::setOutput(Train::OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serialDispatch(serial);
|
serialDispatch(serial);
|
||||||
|
nfcBoard.poll(serial);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ uint16_t Signal::getPacket()
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::sendData()
|
void Signal::sendData(bool single)
|
||||||
{
|
{
|
||||||
sendRaw(getPacket());
|
sendRaw(getPacket(), single);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Signal::getType()
|
uint8_t Signal::getType()
|
||||||
|
@ -132,9 +132,9 @@ uint16_t Train::assembleSpeedPacket()
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Train::sendData()
|
void Train::sendData(bool single)
|
||||||
{
|
{
|
||||||
sendRaw(assembleSpeedPacket());
|
sendRaw(assembleSpeedPacket(), single);
|
||||||
if(_functionmask)
|
if(_functionmask)
|
||||||
{
|
{
|
||||||
uint8_t functionToResend = (_function & 0xF0) >> 4;
|
uint8_t functionToResend = (_function & 0xF0) >> 4;
|
||||||
@ -144,7 +144,7 @@ void Train::sendData()
|
|||||||
if(_functionmask & (1 << functionToResend))
|
if(_functionmask & (1 << functionToResend))
|
||||||
{
|
{
|
||||||
_delay_ms(2);
|
_delay_ms(2);
|
||||||
sendRaw(packetAddSpeed() | packetAddFunction(functionToResend) | packetAddFunction(0));
|
sendRaw(packetAddSpeed() | packetAddFunction(functionToResend) | packetAddFunction(0), single);
|
||||||
}
|
}
|
||||||
_function &= ~0xF0;
|
_function &= ~0xF0;
|
||||||
_function |= functionToResend << 4;
|
_function |= functionToResend << 4;
|
||||||
|
2
train.h
2
train.h
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
Train(const uint8_t address, uint8_t functionmask = 0, uint8_t quirks = 0);
|
Train(const uint8_t address, uint8_t functionmask = 0, uint8_t quirks = 0);
|
||||||
|
|
||||||
void sendData();
|
void sendData(bool single = false);
|
||||||
|
|
||||||
void reverse();
|
void reverse();
|
||||||
void stop();
|
void stop();
|
||||||
|
@ -33,7 +33,7 @@ uint16_t Turnout::getPacket()
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Turnout::sendData()
|
void Turnout::sendData(bool single)
|
||||||
{
|
{
|
||||||
sendRaw(getPacket());
|
sendRaw(getPacket(), single);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user