fix train encodeing make, negative idle pulse optional
This commit is contained in:
35
main.cpp
35
main.cpp
@ -28,20 +28,27 @@ volatile uint8_t tick = 0;
|
||||
|
||||
volatile bool resendEvent = false;
|
||||
|
||||
constexpr bool USE_PULSES = false;
|
||||
|
||||
ISR(TIMER0_OVF_vect)
|
||||
{
|
||||
++tick;
|
||||
if(tick == 0)
|
||||
resendEvent = true;
|
||||
if((tick & 0b00000111) < 1)
|
||||
Train::setOutput(Train::HIGH);
|
||||
else Train::setOutput(Train::LOW);
|
||||
if constexpr(USE_PULSES)
|
||||
{
|
||||
if((tick & 0b00000111) < 1)
|
||||
Train::setOutput(Train::HIGH);
|
||||
else Train::setOutput(Train::LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void timer0InterruptEnable(const bool enable)
|
||||
{
|
||||
if(enable) TIMSK0 = 0b00000001;
|
||||
else TIMSK0 = 0b00000000;
|
||||
if(enable)
|
||||
TIMSK0 = 0b00000001;
|
||||
else
|
||||
TIMSK0 = 0b00000000;
|
||||
}
|
||||
|
||||
void save_state()
|
||||
@ -109,11 +116,11 @@ int trainDispatch(char* inBuffer, Serial* serial)
|
||||
if(token != NULL)
|
||||
trains[storedTrains].setFunctionMask(strtol(token, nullptr, 2 ));
|
||||
|
||||
uint8_t size = snprintf(buffer, SNPRINTF_BUFFER_SIZE, "TRAIN saved! NUMBER: %u ADDRESS: %u FUNCTIONS: %u FUNCTIONMASK: %u\n",
|
||||
uint8_t size = snprintf(buffer, SNPRINTF_BUFFER_SIZE, "TRAIN saved! NUMBER: %u ADDRESS: %u FUNCTIONS: %s FUNCTIONMASK: %s\n",
|
||||
storedTrains,
|
||||
address,
|
||||
trains[storedTrains].getFunctions(),
|
||||
trains[storedTrains].getFunctionMask());
|
||||
bit_rep[trains[storedTrains].getFunctions() & 0x0F],
|
||||
bit_rep[trains[storedTrains].getFunctionMask() & 0x0F]);
|
||||
serial->write(buffer, size);
|
||||
|
||||
storedTrains++;
|
||||
@ -138,10 +145,10 @@ int trainDispatch(char* inBuffer, Serial* serial)
|
||||
serial->write_p(PSTR("Trains:\n"));
|
||||
for(uint8_t i = 0; i < storedTrains; i++)
|
||||
{
|
||||
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "NUMBER: %u ID: %u CURRENT PACKET: %x SPEED: %i FUNCTIONS: %u FUNCTIONMASK: %u\n",
|
||||
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "NUMBER: %u ID: %u CURRENT PACKET: %x SPEED: %i FUNCTIONS: %s FUNCTIONMASK: %s\n",
|
||||
i, trains[i].getAddress(),
|
||||
trains[i].getLastPacket(), trains[i].getSpeed(),
|
||||
trains[i].getFunctions(), trains[i].getFunctionMask());
|
||||
bit_rep[trains[i].getFunctions() & 0x0F], bit_rep[trains[i].getFunctionMask() & 0x0F]);
|
||||
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
|
||||
}
|
||||
serial->putChar('\n');
|
||||
@ -226,7 +233,7 @@ int trainDispatch(char* inBuffer, Serial* serial)
|
||||
uint16_t i = strtol(token, nullptr, 16 );
|
||||
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "SENDING: %x to %x\n", i, trains[id].getAddress());
|
||||
serial->write(buffer, strlen(buffer));
|
||||
for(uint8_t j = 0; j < 100; j++)
|
||||
//for(uint8_t j = 0; j < 100; j++)
|
||||
{
|
||||
trains[id].sendRaw(i);
|
||||
_delay_ms(20);
|
||||
@ -392,7 +399,7 @@ void serialDispatch(Serial* serial)
|
||||
int main()
|
||||
{
|
||||
TCNT0 = 0;
|
||||
TCCR0B = (1<<CS01) /*| (1<<CS00)*/; // run timer0 with /64 scaler
|
||||
TCCR0B = (1<<CS00); // run timer0 with /1 scaler
|
||||
|
||||
DDRD = (1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5);
|
||||
|
||||
@ -421,9 +428,9 @@ int main()
|
||||
{
|
||||
if(resendEvent && storedTrains > 0)
|
||||
{
|
||||
//_delay_ms(100);
|
||||
timer0InterruptEnable(false);
|
||||
_delay_us(255);
|
||||
trains[trainToResend].resendData();
|
||||
trains[trainToResend].sendData();
|
||||
trainToResend++;
|
||||
if(storedTrains <= trainToResend)
|
||||
trainToResend = 0;
|
||||
|
Reference in New Issue
Block a user