]> www.fi.muni.cz Git - openparking.git/blobdiff - firmware/firmware.c
Remove unused function do_measurements()
[openparking.git] / firmware / firmware.c
old mode 100755 (executable)
new mode 100644 (file)
index ce4a914..eb064cd
@@ -2,9 +2,11 @@
 #include <avr/interrupt.h>
 #include <util/delay.h>
 #include <stdio.h>
+#include "clock.h"
 #include "modbus.h"
 
-#define TIMEOUT 0x2FF
+#define ECHO_TIMEOUT           (CLOCK_HZ/10)   // 10 ms
+#define MEASUREMENT_WAIT       (CLOCK_HZ/3)    // three triggers per second
 
 #define N_TRIGGERS 3
 #define N_SENSORS 12
@@ -48,13 +50,13 @@ static void do_measurement(unsigned char trig)
 
        pull_trigger(trig);
 
-       starttime = TCNT1;
+       starttime = get_clock();
 
        while (to_start || to_measure) {
                uint8_t bits = 0;
-               uint16_t now = TCNT1;
+               uint16_t now = get_clock();
 
-               if (now-starttime >= TIMEOUT)
+               if (now-starttime >= ECHO_TIMEOUT)
                        break;
 
                bits = get_pin(trig);
@@ -83,26 +85,14 @@ static void do_measurement(unsigned char trig)
                        distances[trig*N_TRIG_SENSORS + i] = 0;
 }
 
-static void do_measurements()
-{
-       uint8_t trig;
-
-       for (trig = 0; trig < N_TRIGGERS; trig++) {
-               do_measurement(trig);
-               _delay_ms(200);
-       }
-}
-
 static void led_set(uint8_t led, uint8_t state)
 {
        if (led == 0) {
                if (state) {
-                       PORTD |= _BV(PD4);
-                       // PORTC |= _BV(PC5);
+                       PORTC |= _BV(PC5);
                        led_bitmap |= 1;
                } else {
-                       PORTD &= ~_BV(PD4);
-                       // PORTC &= ~_BV(PC5);
+                       PORTC &= ~_BV(PC5);
                        led_bitmap &= ~1;
                }
        } else {
@@ -169,8 +159,6 @@ int main()
        DDRD |= _BV(PD7); // Trig D
        DDRB |= _BV(PB4) | _BV(PB5); // Trig B, LED 2
        DDRC |= _BV(PC4) | _BV(PC5); // Trig C, LED 1
-       // temporary LED
-       DDRD |= _BV(PD4);
 
        // set up the timer
        TCCR1A = 0;
@@ -184,8 +172,8 @@ int main()
                for (trig = 0; trig < N_TRIGGERS; trig++) {
                        uint16_t now;
                        do_measurement(trig);
-                       now = TCNT1;
-                       while (TCNT1-now < 200)
+                       now = get_clock();
+                       while (get_clock()-now < MEASUREMENT_WAIT)
                                modbus_poll();
                }