]> git.tdb.fi Git - r2c2.git/commitdiff
Change the input filtering for better suitability for unreliable track circuits
authorMikko Rasa <tdb@tdb.fi>
Fri, 12 Nov 2010 21:03:19 +0000 (21:03 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 12 Nov 2010 21:03:19 +0000 (21:03 +0000)
Reduce the amount of spam sent by s88w-t
Optimize the LCD output code in s88w-r

firmware/s88w-r.c
firmware/s88w-t.c

index dbd1ef175d9a7ea95279dc5bccfe85fe12c557f5..730ac10f3a5337ba2ec31e51ef79a3e8fbac27b6 100644 (file)
@@ -44,7 +44,8 @@ volatile uint8_t rx_buf[7];
 volatile uint8_t rx_fill = 0xFF;
 volatile uint8_t input[128] = { 0 };
 volatile uint8_t latch[128] = { 0 };
-uint8_t log_pos = 0;
+uint8_t log_row = 0;
+uint8_t log_col = 0;
 
 int main()
 {
@@ -147,7 +148,6 @@ void receive(uint8_t c)
                                lcd_gotoxy(19-offset-nibbles, 0);
                                for(i=0; i<=nibbles; ++i)
                                        lcd_write(rx_buf[3+i]);
-                               log_pos |= 0x80;
                        }
                }
                rx_fill = 0xFF;
@@ -160,13 +160,17 @@ void receive(uint8_t c)
                        rx_fill = 0xFF;
        }
 
-       lcd_gotoxy(log_pos%20, 1+log_pos/20);
+       lcd_gotoxy(log_col, 1+log_row);
        lcd_write(c);
-       ++log_pos;
-       if(log_pos>=60)
-               log_pos = 0;
-       if(log_pos%20==0)
-               lcd_gotoxy(log_pos%20, 1+log_pos/20);
+       ++log_col;
+       if(log_col>=20)
+       {
+               log_col = 0;
+               ++log_row;
+               if(log_row>=3)
+                       log_row = 0;
+               lcd_gotoxy(log_col, 1+log_row);
+       }
        lcd_write(255);
 }
 
index 70c646c19984fb5583899d6a2b1a45c6ecab83b7..b39fd796fb762199ef311cbada24b5016689a481 100644 (file)
@@ -52,6 +52,7 @@ uint8_t rx_fill = 0xFF;
 volatile uint8_t nibbles = 2;
 volatile uint8_t offset = 0;
 volatile uint16_t state = 0;
+volatile uint8_t time_since_send = 0;
 
 int main()
 {
@@ -68,23 +69,25 @@ int main()
        PORTB = 0x3F;  // 00111111
 
        serial_init(9600);
-       timer_start_hz(1, 1, 2);
+       timer_start_hz(1, 100, 1);
 
        sei();
 
        while(1)
        {
-               uint8_t i;
+               uint8_t i, j;
                uint16_t input = 0;
                uint16_t valid = 0xFFF;
 
                for(i=0; i<100; ++i)
                {
-                       uint16_t pins;
+                       uint16_t pins = 0;
+                       for(j=0; j<100; ++j)
+                               pins |= ~((PIND>>2) | ((PINB&0x3F)<<6));
 
-                       pins = ~((PIND>>2) | ((PINB&0x3F)<<6));
                        if(i==0)
                                input = pins;
+
                        valid &= ~(pins^input);
                }
 
@@ -92,7 +95,7 @@ int main()
                input |= state&~valid;
                input &= (1<<(nibbles*4))-1;
 
-               if(input!=state)
+               if(input!=state && time_since_send>5)
                {
                        state = input;
                        send_state();
@@ -138,6 +141,7 @@ SERIAL_SET_CALLBACK(receive)
 void send_state(void)
 {
        uint8_t i;
+
        serial_write(':');
        serial_write(hexdigit(offset>>8));
        serial_write(hexdigit(offset>>4));
@@ -145,9 +149,18 @@ void send_state(void)
        for(i=nibbles; i--;)
                serial_write(hexdigit(state>>(i*4)));
        serial_write('.');
+
+       time_since_send = 0;
+}
+
+void timer(void)
+{
+       ++time_since_send;
+       if(time_since_send>200)
+               send_state();
 }
 
-TIMER_SET_CALLBACK(1, send_state)
+TIMER_SET_CALLBACK(1, timer)
 
 uint8_t hexdigit(uint8_t n)
 {