Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2248 | - | 1 | /***************************************************************************************************************************** |
2 | * File: led.c |
||
3 | * |
||
4 | * Purpose: controlling LEDs |
||
5 | * |
||
6 | * Functions: void LED_Init(void) |
||
7 | * void LED_Update(void) |
||
8 | * |
||
9 | *****************************************************************************************************************************/ |
||
10 | #include "led.h" |
||
11 | |||
12 | #include <inttypes.h> |
||
13 | #include "main.h" |
||
14 | |||
15 | uint16_t LED1_Timing = 0; |
||
16 | uint16_t LED2_Timing = 0; |
||
17 | unsigned char J16Blinkcount = 0, J16Mask = 1; |
||
18 | unsigned char J17Blinkcount = 0, J17Mask = 1; |
||
19 | |||
20 | //------------------------------------------------------------------------------------------------------ |
||
21 | // initialisiert die Schalt-Ausgänge PORTC2 und PORTC3 an SV2 (control of J16 & J17) |
||
22 | //------------------------------------------------------------------------------------------------------ |
||
23 | void LED_Init(void) |
||
24 | { |
||
25 | DDRC |= (1<<DDC2)|(1<<DDC3); |
||
26 | J16_OFF; |
||
27 | J17_OFF; |
||
28 | J16Blinkcount = 0; J16Mask = 128; |
||
29 | J17Blinkcount = 0; J17Mask = 128; |
||
30 | } |
||
31 | //------------------------------------------------------------------------------------------------------ |
||
32 | |||
33 | |||
34 | //-------------------------------------------------------------------------------------------------------------------------------- |
||
35 | // wird aus UpdateMotors() alle 2ms aufgerufen |
||
36 | // damit können am Mikrokopter aussen angebrachte LEDs gesteuert werden |
||
37 | // deren Ankoppelung geschieht über PORTC2 und PORTC3 |
||
38 | //-------------------------------------------------------------------------------------------------------------------------------- |
||
39 | void LED_Update(void) |
||
40 | { |
||
41 | static char delay = 0; |
||
42 | static unsigned char J16Bitmask = 0; |
||
43 | static unsigned char J17Bitmask = 0; |
||
44 | if(!delay--) // 10ms Intervall |
||
45 | { |
||
46 | delay = 4; |
||
47 | |||
48 | if(MikroKopterFlags & FLAG_LOWBAT || SenderOkay < 128) |
||
49 | { |
||
50 | J16Bitmask = EE_Parameter.WARN_J16_Bitmask; |
||
51 | J17Bitmask = EE_Parameter.WARN_J17_Bitmask; |
||
52 | } |
||
53 | else |
||
54 | { |
||
55 | J16Bitmask = EE_Parameter.J16Bitmask; |
||
56 | J17Bitmask = EE_Parameter.J17Bitmask; |
||
57 | } |
||
58 | |||
59 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;} |
||
60 | else |
||
61 | |||
62 | if((EE_Parameter.J16Timing > 250) && (Parameter_J16Timing > 220)) {if(J16Bitmask & 128) J16_ON; else J16_OFF;} |
||
63 | else |
||
64 | |||
65 | if((EE_Parameter.J16Timing > 250) && (Parameter_J16Timing < 10)) {if(J16Bitmask & 128) J16_OFF; else J16_ON;} |
||
66 | else |
||
67 | |||
68 | if(!J16Blinkcount--) |
||
69 | { |
||
70 | J16Blinkcount = Parameter_J16Timing-1; |
||
71 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
||
72 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
||
73 | } |
||
74 | |||
75 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;} |
||
76 | else |
||
77 | if((EE_Parameter.J17Timing > 250) && (Parameter_J17Timing > 230)) {if(J17Bitmask & 128) J17_ON; else J17_OFF;} |
||
78 | else |
||
79 | if((EE_Parameter.J17Timing > 250) && (Parameter_J17Timing < 10)) {if(J17Bitmask & 128) J17_OFF; else J17_ON;} |
||
80 | else |
||
81 | if(!J17Blinkcount--) |
||
82 | { |
||
83 | J17Blinkcount = Parameter_J17Timing-1; |
||
84 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
||
85 | if(J17Mask & J17Bitmask) J17_ON; else J17_OFF; |
||
86 | } |
||
87 | } // Ende : 10ms Intervall |
||
88 | } |
||
89 | //-------------------------------------------------------------------------------------------------------------------------------- |