blackbox/main.c

changeset 3
1a0ef40ef458
parent 2
6c59b4293fa9
child 4
58529e14c45c
--- a/blackbox/main.c	Mon Nov 14 21:15:11 2011 +0100
+++ b/blackbox/main.c	Mon Nov 14 21:38:00 2011 +0100
@@ -13,64 +13,6 @@
 #include "main.h"
 #include "lowlevel.h"
 
-void init_hardware(void) {
-    RS232_init(); // initialize RS485 interface
-    RS232_puts_p(PSTR("CARRERA beta loading\n"));
-
-    initADC();
-
-    // set LED output
-    DDR(LED1_PORT) |= _BV(LED1);
-    DDR(LED2_PORT) |= _BV(LED2);
-    DDR(LED3_PORT) |= _BV(LED3);
-    DDR(LED4_PORT) |= _BV(LED4);
-    DDR(LED5_PORT) |= _BV(LED5);
-
-    // set Controller Input Pull-UPs
-    CONTROLLER_PORT |= (_BV(CONTROLLER1_SW) | _BV(CONTROLLER2_SW) | _BV(CONTROLLER3_SW) | _BV(CONTROLLER4_SW));
-
-    // switch pull-ups
-    SW_FUEL_PORT |= _BV(SW_FUEL);
-
-    //RAIL_DETECT_PORT |= _BV(RAIL_DETECT); // enable internal pull-up
-    DDR(RAIL_POWER_PORT) |= _BV(RAIL_POWER);
-
-
-    LED(1, 1); _delay_ms(50);
-    LED(2, 1); _delay_ms(50);
-    LED(3, 1); _delay_ms(50);
-    LED(4, 1); _delay_ms(50);
-    LED(5, 1); _delay_ms(50);
-    LED(1, 0); _delay_ms(50);
-    LED(2, 0); _delay_ms(50);
-    LED(3, 0); _delay_ms(50);
-    LED(4, 0); _delay_ms(50);
-    LED(5, 0); _delay_ms(50);
-
-    //TCCR0 = (1<<CS01); //divide by 8
-
-
-    // setup data bit timer
-    TCCR2 = (1<<CS21); //divide by 8
-    TCCR2 |= (1<<WGM21); // set compare match
-    OCR2 = TIMER2_50US;
-    TIMSK |= 1<<OCIE2; //enable timer2 interrupt
-
-    // setup data packet timer
-    //TCCR1A = (1<<COM1A1);
-    TCCR1B = (1<<CS11); //divide by 8
-    TCCR1B |= (1<<WGM12); // set compare match
-    //TCCR1B = (1<<CS11) | (1<<CS10); //divide by 64
-    //TCNT1 = TIMER_7500NS;
-    OCR1A = TIMER1_7500NS;
-    TIMSK |= 1<<OCIE1A; //enable timer1 interrupt
-
-    RS232_puts_p(PSTR("INIT OK\n"));
-
-}
-
-
-
 volatile uint8_t datalen = 0;
 char data[10]; // 8 bytes data buffer + string termination
 
@@ -159,19 +101,27 @@
     // read controller X speed & encode controller data packet
     uint16_t tmp;
     switch (controller) {
-        case 0: tmp = getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR; break;
-        case 1: tmp = getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR; break;
-        case 2: tmp = getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR; break;
-        case 3: tmp = getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR; break;
-        case 4: tmp = 0; break; // todo regler 5
-        case 5: tmp = 0; break; // todo regler 6
+        case 0:
+            tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1;
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) tmp |= (1<<5);
+            break;
+        case 1:
+            tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1;
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) tmp |= (1<<5);
+            break;
+        case 2:
+            tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1;
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) tmp |= (1<<5);
+            break;
+        case 3:
+            tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0xF) << 1;
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) tmp |= (1<<5);
+            break;
+        case 4: tmp = (1<<5); break; // todo regler 5
+        case 5: tmp = (1<<5); break; // todo regler 6
     }
-    tmp =  0b1000000000 | (controller << 6) | ((tmp & 0xF) << 1);
+    tmp |=  0b1000000000 | (controller << 6);
     if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter
-    if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) {
-        tmp |= (1<<5);
-        LED(controller+1, 0);
-    } else LED(controller+1, 1);
 
     return insert_queue(tmp, 9);
 }

mercurial