Subversion Repositories FlightCtrl

Rev

Rev 2099 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1910 - 1
#include <inttypes.h>
2
#include "output.h"
3
#include "eeprom.h"
4
#include "timer0.h"
5
 
6
// To access the DebugOut struct.
7
#include "uart0.h"
8
uint8_t flashCnt[2], flashMask[2];
9
// initializes the LED control outputs J16, J17
10
void output_init(void) {
11
  // set PC2 & PC3 as output (control of J16 & J17)
12
  DDRC |= (1 << DDC2) | (1 << DDC3);
13
  OUTPUT_SET(0,0);
14
  OUTPUT_SET(1,0);
15
  flashCnt[0] = flashCnt[1] = 0;
16
  flashMask[0] = flashMask[1] = 128;
17
}
18
 
19
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask,
20
    uint8_t manual) {
21
  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.
23
    OUTPUT_SET(port, bitmask & 128);
24
  } 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.
26
    OUTPUT_SET(port, !(bitmask & 128));
27
  } else if (!flashCnt[port]--) {
28
    // rotating mask over bitmask...
29
    flashCnt[port] = timing - 1;
30
    if (flashMask[port] == 1)
31
      flashMask[port] = 128;
32
    else
33
      flashMask[port] >>= 1;
34
    OUTPUT_SET(port, flashMask[port] & bitmask);
35
  }
36
}
37
 
38
void flashingLights(void) {
39
  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,
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();
62
  }
63
  else if (DIGITAL_DEBUG_MASK == DEBUG_LEDTEST_ON) {
64
    OUTPUT_SET(0, 1);
65
    OUTPUT_SET(1, 1);
66
  } else if (DIGITAL_DEBUG_MASK == DEBUG_LEDTEST_OFF) {
67
    OUTPUT_SET(0, 0);
68
    OUTPUT_SET(1, 0);
69
  } else {
70
    OUTPUT_SET(0, DebugOut.Digital[0] & DIGITAL_DEBUG_MASK);
71
    OUTPUT_SET(1, DebugOut.Digital[1] & DIGITAL_DEBUG_MASK);
72
  }
73
}
74
 
75
void beep(uint16_t millis) {
76
  beepTime = millis;
77
}
78
 
79
/*
80
 * Make [numbeeps] beeps.
81
 */
82
void beepNumber(uint8_t numbeeps) {
83
  while(numbeeps--) {
84
    if(MKFlags & MKFLAG_MOTOR_RUN) return; //auf keinen Fall bei laufenden Motoren!
85
    beep(100); // 0.1 second
86
    delay_ms(250); // blocks 250 ms as pause to next beep,
87
    // this will block the flight control loop,
88
    // therefore do not use this function if motors are running
89
  }
90
}
91
 
92
/*
93
 * Beep the R/C alarm signal
94
 */
95
void beepRCAlarm(void) {
96
  if(beepModulation == 0xFFFF) { // If not already beeping an alarm signal (?)
97
    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;
109
  }
110
}
111
 
112
/*
113
 * Beep the battery low alarm signal
114
 */
115
void beepBatteryAlarm(void) {
116
  beepModulation = 0x0300;
117
  if(!beepTime) {
118
    beepTime = 6000; // 0.6 seconds
119
  }
120
}
121
 
122
/*
123
 * Beep the EEPROM checksum alarm
124
 */
125
void beepEEPROMAlarm(void) {
126
  beepModulation = 0x0007;
127
  if(!beepTime) {
128
    beepTime = 6000; // 0.6 seconds
129
  }
130
}