add support for signals
split main into more files
This commit is contained in:
57
train.cpp
57
train.cpp
@ -1,7 +1,9 @@
|
||||
#include "train.h"
|
||||
#include <stdlib.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
Train::Train(const uint8_t address, uint8_t functionmask): Item(address), _functionmask(functionmask)
|
||||
Train::Train(const uint8_t address, uint8_t functionmask, uint8_t quirks):
|
||||
Item(address), _functionmask(functionmask), _quirks(quirks)
|
||||
{
|
||||
}
|
||||
|
||||
@ -71,15 +73,48 @@ uint16_t Train::packetAddFunction(const uint8_t function)
|
||||
return packet;
|
||||
}
|
||||
|
||||
void Train::setSpeed(uint8_t speed)
|
||||
void Train::setSpeed(int8_t speed)
|
||||
{
|
||||
_speed = speed;
|
||||
sendData();
|
||||
bool direction = _direction;
|
||||
|
||||
if(_quirks & (1 << 1))
|
||||
speed = 0-speed;
|
||||
|
||||
if(speed < 0)
|
||||
_direction = true;
|
||||
else if(speed > 0)
|
||||
_direction = false;
|
||||
|
||||
_speed = abs(speed);
|
||||
|
||||
if((_quirks & 1) && direction != _direction)
|
||||
{
|
||||
cli();
|
||||
for(uint8_t i = 0; i < 2; ++i)
|
||||
{
|
||||
sendRaw(0x28c);
|
||||
_delay_ms(4);
|
||||
}
|
||||
if(!_direction)
|
||||
{
|
||||
for(uint8_t i = 0; i < 2; ++i)
|
||||
{
|
||||
sendRaw(0x224);
|
||||
_delay_ms(4);
|
||||
}
|
||||
}
|
||||
sei();
|
||||
}
|
||||
else
|
||||
{
|
||||
sendData();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Train::getSpeed()
|
||||
int8_t Train::getSpeed()
|
||||
{
|
||||
return _speed;
|
||||
int8_t speed = _direction ? 0-_speed : _speed;
|
||||
return _quirks & (1 << 1) ? 0-speed : speed;
|
||||
}
|
||||
|
||||
void Train::stop()
|
||||
@ -144,3 +179,13 @@ void Train::sendFunction(const uint8_t function, bool enable)
|
||||
_function = (_function & ~(1 << function)) | (enable << function);
|
||||
sendData();
|
||||
}
|
||||
|
||||
uint8_t Train::getQuirks()
|
||||
{
|
||||
return _quirks;
|
||||
}
|
||||
|
||||
void Train::setQuirks(uint8_t quirks)
|
||||
{
|
||||
_quirks = quirks;
|
||||
}
|
||||
|
Reference in New Issue
Block a user