Rev 1910 | Rev 2102 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1910 | Rev 2099 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include <inttypes.h> |
1 | #include <inttypes.h> |
2 | #include "output.h" |
2 | #include "output.h" |
3 | #include "eeprom.h" |
3 | #include "eeprom.h" |
4 | #include "timer0.h" |
4 | #include "timer0.h" |
5 | - | ||
6 | // To access the DebugOut struct. |
- | |
7 | #include "uart0.h" |
- | |
8 | uint8_t flashCnt[2], flashMask[2]; |
5 | uint8_t flashCnt[2], flashMask[2]; |
- | 6 | ||
9 | // initializes the LED control outputs J16, J17 |
7 | DebugOut_t debugOut; |
- | 8 | ||
10 | void output_init(void) { |
9 | void output_init(void) { |
11 | // set PC2 & PC3 as output (control of J16 & J17) |
10 | // set PC2 & PC3 as output (control of J16 & J17) |
12 | DDRC |= (1 << DDC2) | (1 << DDC3); |
11 | DDRC |= (1 << DDC2) | (1 << DDC3); |
13 | OUTPUT_SET(0,0); |
12 | outputSet(0,0); |
14 | OUTPUT_SET(1,0); |
13 | outputSet(1,0); |
15 | flashCnt[0] = flashCnt[1] = 0; |
14 | flashCnt[0] = flashCnt[1] = 0; |
16 | flashMask[0] = flashMask[1] = 128; |
15 | flashMask[0] = flashMask[1] = 128; |
17 | } |
16 | } |
Line 18... | Line 17... | ||
18 | 17 | ||
- | 18 | void outputSet(uint8_t num, uint8_t state) { |
|
- | 19 | if (staticParams.outputFlags & (OUTPUTFLAGS_INVERT_0 << num)) { |
|
- | 20 | if (state) OUTPUT_LOW(num) else OUTPUT_HIGH(num); |
|
- | 21 | } else { |
|
- | 22 | if (state) OUTPUT_HIGH(num) else OUTPUT_LOW(num); |
|
- | 23 | } |
|
19 | void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, |
24 | if (staticParams.outputFlags & OUTPUTFLAGS_USE_ONBOARD_LEDS) { |
- | 25 | if (num) { |
|
- | 26 | if (state) GRN_ON else GRN_OFF; |
|
- | 27 | } else { |
|
- | 28 | if (state) RED_ON else RED_OFF; |
|
- | 29 | } |
|
- | 30 | } |
|
- | 31 | } |
|
- | 32 | ||
20 | uint8_t manual) { |
33 | void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, uint8_t manual) { |
21 | if (timing > 250 && manual > 230) { |
34 | if (timing > 250 && manual > 230) { |
22 | // "timing" is set to "manual" and the value is very high --> Set to the value in bitmask bit 7. |
35 | // "timing" is set to "manual (a variable)" and the value is very high --> Set to the value in bitmask bit 7. |
23 | OUTPUT_SET(port, bitmask & 128); |
36 | outputSet(port, 1); |
24 | } else if (timing > 250 && manual < 10) { |
37 | } else if (timing > 250 && manual < 10) { |
25 | // "timing" is set to "manual" and the value is very low --> Set to the negated value in bitmask bit 7. |
38 | // "timing" is set to "manual" (a variable) and the value is very low --> Set to the negated value in bitmask bit 7. |
26 | OUTPUT_SET(port, !(bitmask & 128)); |
39 | outputSet(port, 0); |
27 | } else if (!flashCnt[port]--) { |
40 | } else if (!flashCnt[port]--) { |
28 | // rotating mask over bitmask... |
41 | // rotating mask over bitmask... |
29 | flashCnt[port] = timing - 1; |
42 | flashCnt[port] = timing - 1; |
30 | if (flashMask[port] == 1) |
43 | if (flashMask[port] == 1) |
31 | flashMask[port] = 128; |
44 | flashMask[port] = 128; |
32 | else |
45 | else |
33 | flashMask[port] >>= 1; |
46 | flashMask[port] >>= 1; |
34 | OUTPUT_SET(port, flashMask[port] & bitmask); |
47 | outputSet(port, flashMask[port] & bitmask); |
35 | } |
48 | } |
Line 36... | Line 49... | ||
36 | } |
49 | } |
37 | 50 | ||
38 | void flashingLights(void) { |
51 | void output_update(void) { |
39 | static int8_t delay = 0; |
52 | static int8_t delay = 0; |
40 | if (!delay--) { // 10 ms intervals |
- | |
41 | delay = 4; |
- | |
42 | flashingLight(0, staticParams.J16Timing, staticParams.J16Bitmask, |
- | |
43 | dynamicParams.J16Timing); |
- | |
44 | flashingLight(1, staticParams.J17Timing, staticParams.J17Bitmask, |
53 | if (!delay--) { // 10 ms intervals |
45 | dynamicParams.J17Timing); |
- | |
46 | } |
- | |
47 | } |
- | |
48 | - | ||
49 | void output_update(void) { |
- | |
50 | if (!DIGITAL_DEBUG_MASK) { |
- | |
51 | // If there is a warning beep, also flash it. |
- | |
52 | if (beepTime) { |
- | |
53 | if (beepTime & beepModulation) { |
- | |
54 | OUTPUT_SET(0, 1); |
- | |
55 | OUTPUT_SET(1, 1); |
- | |
56 | } else { |
- | |
57 | OUTPUT_SET(0, 0); |
- | |
58 | OUTPUT_SET(1, 0); |
- | |
59 | } |
- | |
60 | }else |
- | |
61 | flashingLights(); |
54 | delay = 4; |
62 | } |
55 | } |
63 | else if (DIGITAL_DEBUG_MASK == DEBUG_LEDTEST_ON) { |
56 | if (staticParams.outputFlags & OUTPUTFLAGS_TEST_ON) { |
64 | OUTPUT_SET(0, 1); |
57 | outputSet(0, 1); |
65 | OUTPUT_SET(1, 1); |
58 | outputSet(1, 1); |
66 | } else if (DIGITAL_DEBUG_MASK == DEBUG_LEDTEST_OFF) { |
59 | } else if (staticParams.outputFlags & OUTPUTFLAGS_TEST_OFF) { |
67 | OUTPUT_SET(0, 0); |
60 | outputSet(0, 0); |
- | 61 | outputSet(1, 0); |
|
- | 62 | } else { |
|
- | 63 | if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_0_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) { |
|
68 | OUTPUT_SET(1, 0); |
64 | flashingLight(0, 25, 0x55, 25); |
- | 65 | } else if (staticParams.outputDebugMask) { |
|
- | 66 | outputSet(0, debugOut.digital[0] & staticParams.outputDebugMask); |
|
- | 67 | } else if (!delay) { |
|
- | 68 | flashingLight(0, staticParams.outputFlash[0].timing, staticParams.outputFlash[0].bitmask, dynamicParams.output0Timing); |
|
- | 69 | } |
|
- | 70 | if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_1_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) { |
|
69 | } else { |
71 | flashingLight(1, 25, 0x55, 25); |
- | 72 | } else if (staticParams.outputDebugMask) { |
|
- | 73 | outputSet(1, debugOut.digital[1] & staticParams.outputDebugMask); |
|
- | 74 | } else if (!delay) { |
|
70 | OUTPUT_SET(0, DebugOut.Digital[0] & DIGITAL_DEBUG_MASK); |
75 | flashingLight(1, staticParams.outputFlash[1].timing, staticParams.outputFlash[1].bitmask, dynamicParams.output1Timing); |
71 | OUTPUT_SET(1, DebugOut.Digital[1] & DIGITAL_DEBUG_MASK); |
76 | } |
Line 72... | Line 77... | ||
72 | } |
77 | } |
73 | } |
78 | } |
Line 91... | Line 96... | ||
91 | 96 | ||
92 | /* |
97 | /* |
93 | * Beep the R/C alarm signal |
98 | * Beep the R/C alarm signal |
94 | */ |
99 | */ |
95 | void beepRCAlarm(void) { |
100 | void beepRCAlarm(void) { |
96 | if(beepModulation == 0xFFFF) { // If not already beeping an alarm signal (?) |
101 | if(beepModulation == BEEP_MODULATION_NONE) { // If not already beeping an alarm signal (?) |
97 | beepTime = 15000; // 1.5 seconds |
102 | beepTime = 15000; // 1.5 seconds |
98 | beepModulation = 0x0C00; |
- | |
99 | } |
- | |
100 | } |
- | |
101 | - | ||
102 | /* |
- | |
103 | * Beep the I2C bus error signal |
- | |
104 | */ |
- | |
105 | void beepI2CAlarm(void) { |
- | |
106 | if((beepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN)) { |
- | |
107 | beepTime = 10000; // 1 second |
- | |
108 | beepModulation = 0x0080; |
103 | beepModulation = BEEP_MODULATION_RCALARM; |
109 | } |
104 | } |
Line 110... | Line 105... | ||
110 | } |
105 | } |
111 | 106 | ||
112 | /* |
107 | /* |
113 | * Beep the battery low alarm signal |
108 | * Beep the battery low alarm signal |
114 | */ |
109 | */ |
115 | void beepBatteryAlarm(void) { |
110 | void beepBatteryAlarm(void) { |
116 | beepModulation = 0x0300; |
111 | beepModulation = BEEP_MODULATION_BATTERYALARM; |
117 | if(!beepTime) { |
112 | if(!beepTime) { |
118 | beepTime = 6000; // 0.6 seconds |
113 | beepTime = 6000; // 0.6 seconds |
Line 119... | Line 114... | ||
119 | } |
114 | } |
120 | } |
115 | } |
121 | 116 | ||
122 | /* |
117 | /* |
123 | * Beep the EEPROM checksum alarm |
118 | * Beep the EEPROM checksum alarm |
124 | */ |
119 | */ |
125 | void beepEEPROMAlarm(void) { |
120 | void beepEEPROMAlarm(void) { |
126 | beepModulation = 0x0007; |
121 | beepModulation = BEEP_MODULATION_EEPROMALARM; |
127 | if(!beepTime) { |
122 | if(!beepTime) { |