avoid sending user command directly if manny user commands are issued in a short period of time
This commit is contained in:
32
main.cpp
32
main.cpp
@ -29,12 +29,10 @@ SVector<Signal, 32> signals;
|
||||
bool autoff = true;
|
||||
bool powerIsOn = true;
|
||||
|
||||
#define TICK_MAX 255
|
||||
volatile uint8_t tick = 0;
|
||||
|
||||
volatile bool resendEvent = false;
|
||||
|
||||
constexpr bool USE_PULSES = false;
|
||||
uint8_t itemToResend = 0;
|
||||
|
||||
void setPower(bool on);
|
||||
void save_state();
|
||||
@ -45,15 +43,9 @@ void save_state();
|
||||
|
||||
ISR(TIMER0_OVF_vect)
|
||||
{
|
||||
++tick;
|
||||
if(tick == 0)
|
||||
if(tick == 0)
|
||||
resendEvent = true;
|
||||
if constexpr(USE_PULSES)
|
||||
{
|
||||
if((tick & 0b00000111) < 1)
|
||||
Train::setOutput(Train::HIGH);
|
||||
else Train::setOutput(Train::LOW);
|
||||
}
|
||||
tick = !tick;
|
||||
}
|
||||
|
||||
void timer0InterruptEnable(const bool enable)
|
||||
@ -229,6 +221,7 @@ int powerDispatch(char* token, Serial* serial)
|
||||
|
||||
void serialDispatch(Serial* serial)
|
||||
{
|
||||
static uint8_t lastItemToResend = 0;
|
||||
if(serial->dataIsWaiting())
|
||||
{
|
||||
char buffer[COMMAND_BUFFER_SIZE];
|
||||
@ -237,6 +230,10 @@ void serialDispatch(Serial* serial)
|
||||
{
|
||||
int ret = -1;
|
||||
char* token = strtok(buffer, " ");
|
||||
|
||||
if(lastItemToResend == itemToResend)
|
||||
Item::directSendBlock = true;
|
||||
|
||||
if(strcmp(token, "train") == 0 || strcmp(token, "t") == 0 )
|
||||
{
|
||||
token = strtok(NULL, " ");
|
||||
@ -309,15 +306,18 @@ void serialDispatch(Serial* serial)
|
||||
}
|
||||
else
|
||||
{
|
||||
for(uint8_t i = 0; i < length; ++i)
|
||||
lastItemToResend = itemToResend;
|
||||
/*for(uint8_t i = 0; i < length; ++i)
|
||||
{
|
||||
if(buffer[i] == '\0' || buffer[i] == '\n')
|
||||
buffer[i] = ' ';
|
||||
}
|
||||
serial->write_p(PSTR("Sucess \""));
|
||||
serial->write(buffer, length);
|
||||
serial->write("\"\n");
|
||||
serial->write("\"\n");*/
|
||||
}
|
||||
|
||||
Item::directSendBlock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -325,7 +325,7 @@ void serialDispatch(Serial* serial)
|
||||
int main()
|
||||
{
|
||||
TCNT0 = 0;
|
||||
TCCR0B = (1<<CS00); // run timer0 with /1 scaler
|
||||
TCCR0B = (1<<CS02); // run timer0 with /256 scaler
|
||||
|
||||
DDRD = (1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5);
|
||||
|
||||
@ -348,11 +348,9 @@ int main()
|
||||
|
||||
serial.write_p(PSTR("TrainController v0.5 starting\n"));
|
||||
|
||||
uint8_t itemToResend = 0;
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(resendEvent && (trains.count() > 0 || turnouts.count()))
|
||||
if(resendEvent && (trains.count() || turnouts.count() || signals.count()))
|
||||
{
|
||||
timer0InterruptEnable(false);
|
||||
if(itemToResend < trains.count())
|
||||
|
Reference in New Issue
Block a user