Subversion Repositories FlightCtrl

Rev

Rev 2099 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2099 Rev 2102
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
uint8_t flashCnt[2], flashMask[2];
5
uint8_t flashCnt[2], flashMask[2];
6
 
6
 
7
DebugOut_t debugOut;
7
DebugOut_t debugOut;
8
 
8
 
9
void output_init(void) {
9
void output_init(void) {
10
  // set PC2 & PC3 as output (control of J16 & J17)
10
  // set PC2 & PC3 as output (control of J16 & J17)
11
  DDRC |= (1 << DDC2) | (1 << DDC3);
11
  DDRC |= (1 << DDC2) | (1 << DDC3);
12
  outputSet(0,0);
12
  outputSet(0,0);
13
  outputSet(1,0);
13
  outputSet(1,0);
14
  flashCnt[0] = flashCnt[1] = 0;
14
  flashCnt[0] = flashCnt[1] = 0;
15
  flashMask[0] = flashMask[1] = 128;
15
  flashMask[0] = flashMask[1] = 128;
16
}
16
}
17
 
17
 
18
void outputSet(uint8_t num, uint8_t state) {
18
void outputSet(uint8_t num, uint8_t state) {
19
  if (staticParams.outputFlags & (OUTPUTFLAGS_INVERT_0 << num)) {
19
  if (staticParams.outputFlags & (OUTPUTFLAGS_INVERT_0 << num)) {
20
    if (state) OUTPUT_LOW(num) else OUTPUT_HIGH(num);
20
    if (state) OUTPUT_LOW(num) else OUTPUT_HIGH(num);
21
  } else {
21
  } else {
22
    if (state) OUTPUT_HIGH(num) else OUTPUT_LOW(num);
22
    if (state) OUTPUT_HIGH(num) else OUTPUT_LOW(num);
23
  }
23
  }
24
  if (staticParams.outputFlags & OUTPUTFLAGS_USE_ONBOARD_LEDS) {
24
  if (staticParams.outputFlags & OUTPUTFLAGS_USE_ONBOARD_LEDS) {
25
    if (num) {
25
    if (num) {
26
      if (state) GRN_ON else GRN_OFF;
26
      if (state) GRN_ON else GRN_OFF;
27
    } else {
27
    } else {
28
      if (state) RED_ON else RED_OFF;
28
      if (state) RED_ON else RED_OFF;
29
    }
29
    }
30
  }
30
  }
31
}
31
}
32
 
32
 
33
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, uint8_t manual) {
33
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, uint8_t manual) {
34
  if (timing > 250 && manual > 230) {
34
  if (timing > 250 && manual > 230) {
35
    // "timing" is set to "manual (a variable)" 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.
36
    outputSet(port, 1);
36
    outputSet(port, 1);
37
  } else if (timing > 250 && manual < 10) {
37
  } else if (timing > 250 && manual < 10) {
38
    // "timing" is set to "manual" (a variable) 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.
39
    outputSet(port, 0);
39
    outputSet(port, 0);
40
  } else if (!flashCnt[port]--) {
40
  } else if (!flashCnt[port]--) {
41
    // rotating mask over bitmask...
41
    // rotating mask over bitmask...
42
    flashCnt[port] = timing - 1;
42
    flashCnt[port] = timing - 1;
43
    if (flashMask[port] == 1)
43
    if (flashMask[port] == 1)
44
      flashMask[port] = 128;
44
      flashMask[port] = 128;
45
    else
45
    else
46
      flashMask[port] >>= 1;
46
      flashMask[port] >>= 1;
47
    outputSet(port, flashMask[port] & bitmask);
47
    outputSet(port, flashMask[port] & bitmask);
48
  }
48
  }
49
}
49
}
50
 
50
 
51
void output_update(void) {
51
void output_update(void) {
52
  static int8_t delay = 0;
52
  static int8_t delay = 0;
53
  if (!delay--) { // 10 ms intervals
53
  if (!delay--) { // 10 ms intervals
54
    delay = 4;
54
    delay = 4;
55
  }
55
  }
56
  if (staticParams.outputFlags & OUTPUTFLAGS_TEST_ON) {
56
  if (staticParams.outputFlags & OUTPUTFLAGS_TEST_ON) {
57
    outputSet(0, 1);
57
    outputSet(0, 1);
58
    outputSet(1, 1);
58
    outputSet(1, 1);
59
  } else if (staticParams.outputFlags & OUTPUTFLAGS_TEST_OFF) {
59
  } else if (staticParams.outputFlags & OUTPUTFLAGS_TEST_OFF) {
60
    outputSet(0, 0);
60
    outputSet(0, 0);
61
    outputSet(1, 0);
61
    outputSet(1, 0);
62
  } else {
62
  } else {
63
    if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_0_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
63
    if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_0_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
64
      flashingLight(0, 25, 0x55, 25);
64
      flashingLight(0, 25, 0x55, 25);
65
    } else if (staticParams.outputDebugMask) {
65
    } else if (staticParams.outputDebugMask) {
66
      outputSet(0, debugOut.digital[0] & staticParams.outputDebugMask);
66
      outputSet(0, debugOut.digital[0] & staticParams.outputDebugMask);
67
    } else if (!delay) {
67
    } else if (!delay) {
68
      flashingLight(0, staticParams.outputFlash[0].timing, staticParams.outputFlash[0].bitmask, dynamicParams.output0Timing);
68
      flashingLight(0, staticParams.outputFlash[0].timing, staticParams.outputFlash[0].bitmask, dynamicParams.output0Timing);
69
    }
69
    }
70
    if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_1_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
70
    if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_1_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) {
71
      flashingLight(1, 25, 0x55, 25);
71
      flashingLight(1, 25, 0x55, 25);
72
    } else if (staticParams.outputDebugMask) {
72
    } else if (staticParams.outputDebugMask) {
73
      outputSet(1, debugOut.digital[1] & staticParams.outputDebugMask);
73
      outputSet(1, debugOut.digital[1] & staticParams.outputDebugMask);
74
    } else if (!delay) {
74
    } else if (!delay) {
75
      flashingLight(1, staticParams.outputFlash[1].timing, staticParams.outputFlash[1].bitmask, dynamicParams.output1Timing);
75
      flashingLight(1, staticParams.outputFlash[1].timing, staticParams.outputFlash[1].bitmask, dynamicParams.output1Timing);
76
    }
76
    }
77
  }
77
  }
78
}
78
}
79
 
79
 
80
void beep(uint16_t millis) {
80
void beep(uint16_t millis) {
81
  beepTime = millis;
81
  beepTime = millis;
82
}
82
}
83
 
83
 
84
/*
84
/*
85
 * Make [numbeeps] beeps.
85
 * Make [numbeeps] beeps.
86
 */
86
 */
87
void beepNumber(uint8_t numbeeps) {
87
void beepNumber(uint8_t numbeeps) {
88
  while(numbeeps--) {
88
  while(numbeeps--) {
89
    if(MKFlags & MKFLAG_MOTOR_RUN) return; //auf keinen Fall bei laufenden Motoren!
89
    if(isMotorRunning) return; //auf keinen Fall bei laufenden Motoren!
90
    beep(100); // 0.1 second
90
    beep(100); // 0.1 second
91
    delay_ms(250); // blocks 250 ms as pause to next beep,
91
    delay_ms(250); // blocks 250 ms as pause to next beep,
92
    // this will block the flight control loop,
92
    // this will block the flight control loop,
93
    // therefore do not use this function if motors are running
93
    // therefore do not use this function if motors are running
94
  }
94
  }
95
}
95
}
96
 
96
 
97
/*
97
/*
98
 * Beep the R/C alarm signal
98
 * Beep the R/C alarm signal
99
 */
99
 */
100
void beepRCAlarm(void) {
100
void beepRCAlarm(void) {
101
  if(beepModulation == BEEP_MODULATION_NONE) { // If not already beeping an alarm signal (?)
101
  if(beepModulation == BEEP_MODULATION_NONE) { // If not already beeping an alarm signal (?)
102
    beepTime = 15000; // 1.5 seconds
102
    beepTime = 15000; // 1.5 seconds
103
    beepModulation = BEEP_MODULATION_RCALARM;
103
    beepModulation = BEEP_MODULATION_RCALARM;
104
  }
104
  }
105
}
105
}
106
 
106
 
107
/*
107
/*
108
 * Beep the battery low alarm signal
108
 * Beep the battery low alarm signal
109
 */
109
 */
110
void beepBatteryAlarm(void) {
110
void beepBatteryAlarm(void) {
111
  beepModulation = BEEP_MODULATION_BATTERYALARM;
111
  beepModulation = BEEP_MODULATION_BATTERYALARM;
112
  if(!beepTime) {
112
  if(!beepTime) {
113
    beepTime = 6000; // 0.6 seconds
113
    beepTime = 6000; // 0.6 seconds
114
  }
114
  }
115
}
115
}
116
 
116
 
117
/*
117
/*
118
 * Beep the EEPROM checksum alarm
118
 * Beep the EEPROM checksum alarm
119
 */
119
 */
120
void beepEEPROMAlarm(void) {
120
void beepEEPROMAlarm(void) {
121
  beepModulation = BEEP_MODULATION_EEPROMALARM;
121
  beepModulation = BEEP_MODULATION_EEPROMALARM;
122
  if(!beepTime) {
122
  if(!beepTime) {
123
    beepTime = 6000; // 0.6 seconds
123
    beepTime = 6000; // 0.6 seconds
124
  }
124
  }
125
}
125
}
126
 
126