fix train encodeing make, negative idle pulse optional
This commit is contained in:
33
train.cpp
33
train.cpp
@ -26,7 +26,7 @@ void Train::stop()
|
||||
{
|
||||
_speed = 0;
|
||||
_function = 0;
|
||||
resendData();
|
||||
sendData();
|
||||
}
|
||||
|
||||
void Train::off()
|
||||
@ -95,7 +95,7 @@ void Train::sendRawAddr(const uint16_t address, const uint16_t data)
|
||||
{
|
||||
sendBit(data & (1 << i));
|
||||
}
|
||||
_delay_ms(2);
|
||||
_delay_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ uint16_t Train::packetAddFunction(const uint8_t function)
|
||||
void Train::setSpeed(uint8_t speed)
|
||||
{
|
||||
_speed = speed;
|
||||
resendData();
|
||||
sendData();
|
||||
}
|
||||
|
||||
uint8_t Train::getSpeed()
|
||||
@ -187,14 +187,23 @@ uint16_t Train::assemblePacket()
|
||||
return packet;
|
||||
}
|
||||
|
||||
void Train::resendData()
|
||||
void Train::sendData()
|
||||
{
|
||||
sendRaw(assemblePacket());
|
||||
for(uint8_t i = 1; i < 4; ++i)
|
||||
{
|
||||
if(_functionmask & (1 << i))
|
||||
sendRaw(packetAddSpeed() | packetAddFunction(i) | packetAddFunction(0));
|
||||
}
|
||||
if(_functionmask)
|
||||
{
|
||||
uint8_t functionToResend = (_function & 0xF0) >> 4;
|
||||
++functionToResend;
|
||||
if (functionToResend == 4)
|
||||
functionToResend = 1;
|
||||
if(_functionmask & (1 << functionToResend))
|
||||
{
|
||||
_delay_ms(2);
|
||||
sendRaw(packetAddSpeed() | packetAddFunction(functionToResend) | packetAddFunction(0));
|
||||
}
|
||||
_function &= ~0xF0;
|
||||
_function |= functionToResend << 4;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Train::getLastPacket()
|
||||
@ -205,13 +214,13 @@ uint16_t Train::getLastPacket()
|
||||
void Train::reverse()
|
||||
{
|
||||
_direction = !_direction;
|
||||
resendData();
|
||||
sendData();
|
||||
}
|
||||
|
||||
|
||||
uint8_t Train::getFunctions()
|
||||
{
|
||||
return _function;
|
||||
return _function & 0x0F;
|
||||
}
|
||||
|
||||
uint8_t Train::getFunctionMask()
|
||||
@ -224,5 +233,5 @@ void Train::sendFunction(const uint8_t function, bool enable)
|
||||
if(function > 3)
|
||||
return;
|
||||
_function = (_function & ~(1 << function)) | (enable << function);
|
||||
resendData();
|
||||
sendData();
|
||||
}
|
||||
|
Reference in New Issue
Block a user