Switch and Throttle Warnings when loading a model. To be tested and re-tested ...

This commit is contained in:
bsongis
2012-05-25 13:52:39 +00:00
parent d3b14ea3e2
commit 9ef47a1e63
11 changed files with 112 additions and 67 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ void putEvent(uint8_t evt)
uint8_t getEvent()
{
uint8_t evt = s_evt;
s_evt=0;
s_evt = 0;
return evt;
}
+12 -1
View File
@@ -471,6 +471,10 @@ void eeLoadModel(uint8_t id)
if (id<MAX_MODELS) {
if (pulsesStarted()) {
pausePulses();
}
size = File_system[id+1].size ;
memset(&g_model, 0, sizeof(g_model));
@@ -493,10 +497,17 @@ void eeLoadModel(uint8_t id)
read32_eeprom_data( ( File_system[id+1].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&g_model, size) ;
}
if (pulsesStarted()) {
checkTHR();
checkSwitches();
resumePulses();
clearKeyEvents();
}
resetProto();
resetAll();
#if defined(SDCARD) && defined(PCBV4)
#if 0
initLogs();
#endif
}
+12 -1
View File
@@ -852,6 +852,11 @@ bool eeModelExists(uint8_t id)
void eeLoadModel(uint8_t id)
{
if (id<MAX_MODELS) {
if (pulsesStarted()) {
pausePulses();
}
theFile.openRlc(FILE_MODEL(id));
uint16_t sz = theFile.readRlc((uint8_t*)&g_model, sizeof(g_model));
@@ -862,11 +867,17 @@ void eeLoadModel(uint8_t id)
#endif
if (sz < 256) {
// alert("Error Loading Model");
modelDefault(id);
eeCheck(true);
}
if (pulsesStarted()) {
checkTHR();
checkSwitches();
resumePulses();
clearKeyEvents();
}
resetProto();
resetAll();
+4 -4
View File
@@ -407,11 +407,11 @@ void processFrskyPacket(uint8_t *packet)
uint8_t numBytes = 3 + (packet[1] & 0x07); // sanitize in case of data corruption leading to buffer overflow
for (uint8_t i=3; i<numBytes; i++) {
#if defined(FRSKY_HUB)
if (g_model.frsky.usrProto == 1) // FrSky Hub
if (g_model.frsky.usrProto == USR_PROTO_FRSKY_HUB)
parseTelemHubByte(packet[i]);
#endif
#if defined(WS_HOW_HIGH)
if (g_model.frsky.usrProto == 2) // WS How High
if (g_model.frsky.usrProto == USR_PROTO_WS_HOW_HIGH)
parseTelemWSHowHighByte(packet[i]);
#endif
}
@@ -977,7 +977,7 @@ void putsTelemetryChannel(uint8_t x, uint8_t y, uint8_t channel, int16_t val, ui
case TELEM_ALT-1:
case TELEM_MIN_ALT-1:
case TELEM_MAX_ALT-1:
if (g_model.frsky.usrProto == PROTO_WS_HOW_HIGH) {
if (g_model.frsky.usrProto == USR_PROTO_WS_HOW_HIGH) {
putsTelemetryValue(x, y, val, UNIT_FEET, att);
break;
}
@@ -1254,7 +1254,7 @@ void menuProcFrsky(uint8_t event)
#ifdef FRSKY_HUB
else if (s_frsky_view == e_frsky_after_flight) {
uint8_t line=1*FH+1;
if (g_model.frsky.usrProto == 1) { // FrSky Hub
if (g_model.frsky.usrProto == USR_PROTO_FRSKY_HUB) {
// Latitude
lcd_putsLeft(line, STR_LATITUDE);
displayGpsCoord(line, frskyHubData.gpsLatitudeNS, frskyHubData.gpsLatitude_bp, frskyHubData.gpsLatitude_ap);
+1 -1
View File
@@ -484,7 +484,7 @@ void menuProcModelSelect(uint8_t event)
// The user choosed a file on SD to restore
s_sdcard_error = eeRestoreModel(sub, (char *)result);
if (!s_sdcard_error && g_eeGeneral.currModel == sub)
eeLoadModel(sub); // force writing of current model data before this is changed
eeLoadModel(sub);
refresh = true;
}
}
+5 -4
View File
@@ -394,9 +394,9 @@ PACK(typedef struct t_FrSkyBarData {
}) FrSkyBarData;
enum FrskyUsrProtocols {
PROTO_NONE,
PROTO_FRSKY_HUB,
PROTO_WS_HOW_HIGH
USR_PROTO_NONE,
USR_PROTO_FRSKY_HUB,
USR_PROTO_WS_HOW_HIGH
};
PACK(typedef struct t_FrSkyData {
@@ -531,7 +531,8 @@ enum Protocols {
PROTO_PICZ,
// PROTO_SWIFT, // we will need 4 bytes for proto :(
#endif
PROTO_MAX
PROTO_MAX,
PROTO_NONE
};
enum Dsm2Variants {
+5 -1
View File
@@ -771,6 +771,7 @@ void clearKeyEvents()
#else
while (keyDown()); // loop until all keys are up
#endif
memset(keys, 0, sizeof(keys));
putEvent(0);
}
@@ -881,6 +882,8 @@ void checkTHR()
}
checkBacklight();
wdt_reset();
}
}
@@ -923,6 +926,8 @@ void checkSwitches()
checkBacklight();
wdt_reset();
#ifdef SIMU
if (!main_thread_running) return;
sleep(1/*ms*/);
@@ -2645,7 +2650,6 @@ int main(void)
getADC_single();
checkTHR();
checkSwitches();
checkAlarm();
}
+33 -33
View File
@@ -33,7 +33,8 @@
#include "open9x.h"
uint8_t Current_protocol ;
uint8_t s_pulses_paused = 0;
uint8_t s_current_protocol ;
uint8_t pxxFlag = 0 ;
uint16_t Pulses[18] = { 2000, 2200, 2400, 2600, 2800, 3000, 3200, 3400, 9000, 0, 0, 0,0,0,0,0,0, 0 } ;
@@ -71,8 +72,8 @@ static void init_main_ppm( uint32_t period, uint32_t out_enable )
{
pioptr = PIOA ;
pioptr->PIO_ABCDSR[0] &= ~PIO_PA17 ; // Peripheral C
pioptr->PIO_ABCDSR[1] |= PIO_PA17 ; // Peripheral C
pioptr->PIO_PDR = PIO_PA17 ; // Disable bit A17 Assign to peripheral
pioptr->PIO_ABCDSR[1] |= PIO_PA17 ; // Peripheral C
pioptr->PIO_PDR = PIO_PA17 ; // Disable bit A17 Assign to peripheral
}
pwmptr = PWM ;
@@ -409,18 +410,8 @@ extern "C" void PWM_IRQHandler(void)
pwmptr = PWM;
if (pwmptr->PWM_ISR1 & PWM_ISR1_CHID3) {
switch (Current_protocol) // Use the current, don't switch until set_up_pulses
switch (s_current_protocol) // Use the current, don't switch until set_up_pulses
{
case PROTO_PPM:
case PROTO_PPM16:
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = Pulses[Pulses_index++]; // Period in half uS
if (Pulses[Pulses_index] == 0) {
Pulses_index = 0;
setupPulses();
}
break;
case PROTO_PXX:
// Alternate periods of 15.5mS and 2.5 mS
period = pwmptr->PWM_CH_NUM[3].PWM_CPDR;
@@ -459,7 +450,7 @@ extern "C" void PWM_IRQHandler(void)
}
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
if (period != 5000) // 2.5 mS
{
{
setupPulses();
}
else {
@@ -472,6 +463,15 @@ extern "C" void PWM_IRQHandler(void)
sscptr->SSC_PTCR = SSC_PTCR_TXTEN; // Start transfers
}
break;
default:
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = Pulses[Pulses_index++]; // Period in half uS
if (Pulses[Pulses_index] == 0) {
Pulses_index = 0;
setupPulses();
}
break;
}
}
}
@@ -480,27 +480,27 @@ void setupPulses()
{
heartbeat |= HEART_TIMER_PULSES;
if (Current_protocol != g_model.protocol) {
switch (Current_protocol) { // stop existing protocol hardware
case PROTO_PPM:
disable_main_ppm();
break;
uint8_t required_protocol = g_model.protocol;
if (s_pulses_paused)
required_protocol = PROTO_NONE;
if (s_current_protocol != required_protocol) {
switch (s_current_protocol) { // stop existing protocol hardware
case PROTO_PXX:
disable_ssc();
break;
case PROTO_DSM2:
disable_ssc();
break;
case PROTO_PPM16:
default:
disable_main_ppm();
break;
}
Current_protocol = g_model.protocol;
switch (Current_protocol) { // Start new protocol hardware here
case PROTO_PPM:
init_main_ppm(3000, 1); // Initial period 1.5 mS, output on
break;
s_current_protocol = required_protocol;
switch (required_protocol) { // Start new protocol hardware here
case PROTO_PXX:
init_main_ppm(5000, 0); // Initial period 2.5 mS, output off
init_ssc();
@@ -509,24 +509,24 @@ void setupPulses()
init_main_ppm(5000, 0); // Initial period 2.5 mS, output off
init_ssc();
break;
case PROTO_PPM16:
case PROTO_NONE:
init_main_ppm(3000, 0); // Initial period 1.5 mS, output on
break;
default:
init_main_ppm(3000, 1); // Initial period 1.5 mS, output on
break;
}
}
// Set up output data here
switch (Current_protocol) {
case PROTO_PPM:
setupPulsesPPM(); // Don't enable interrupts through here
break;
// Set up output data here
switch (required_protocol) {
case PROTO_PXX:
setupPulsesPXX();
break;
case PROTO_DSM2:
setupPulsesDsm2(6);
break;
case PROTO_PPM16:
default:
setupPulsesPPM(); // Don't enable interrupts through here
break ;
}
+6
View File
@@ -34,7 +34,13 @@
#ifndef pulses_arm_h
#define pulses_arm_h
extern uint8_t s_current_protocol;
extern uint8_t s_pulses_paused;
void startPulses();
inline bool pulsesStarted() { return s_current_protocol != 255; }
inline void pausePulses() { s_pulses_paused = true; }
inline void resumePulses() { s_pulses_paused = false; }
void disable_main_ppm();
void disable_ssc();
+23 -17
View File
@@ -44,6 +44,7 @@
#endif
uint8_t s_current_protocol = 255;
uint8_t s_pulses_paused = 0;
#ifdef DSM2_SERIAL
inline void DSM2_EnableTXD(void)
@@ -118,15 +119,17 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation
else
#endif
{
// Orginal bitbang for PPM
// Original bitbang for PPM
#if !defined(PCBV4)
if (pulsePol) {
PORTB |= (1<<OUT_B_PPM); // GCC optimisation should result in a single SBI instruction
pulsePol = 0;
}
else {
PORTB &= ~(1<<OUT_B_PPM);
pulsePol = 1;
if (s_current_protocol != PROTO_NONE) {
if (pulsePol) {
PORTB |= (1<<OUT_B_PPM); // GCC optimisation should result in a single SBI instruction
pulsePol = 0;
}
else {
PORTB &= ~(1<<OUT_B_PPM);
pulsePol = 1;
}
}
#endif
@@ -134,17 +137,19 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation
#if defined(PCBV4)
OCR1B = *((uint16_t*)pulses2MHzRPtr); /* G: Using timer in CTC mode, restricted to using OCR1A for interrupt triggering.
So we actually have to handle the OCR1B register separately in this way. */
So we actually have to handle the OCR1B register separately in this way. */
// We cannot read the status of the PPM_OUT pin when OC1B is connected to it on the ATmega2560.
// So the only way to set polarity is to manually control set/reset mode in COM1B0/1
if (pulsePol) {
TCCR1A = (3<<COM1B0); // SET the state of PB6(OC1B) on next TCNT1==OCR1B
pulsePol = 0;
}
else {
TCCR1A = (2<<COM1B0); // CLEAR the state of PB6(OC1B) on next TCNT1==OCR1B
pulsePol = 1;
if (s_current_protocol != PROTO_NONE) {
if (pulsePol) {
TCCR1A = (3<<COM1B0); // SET the state of PB6(OC1B) on next TCNT1==OCR1B
pulsePol = 0;
}
else {
TCCR1A = (2<<COM1B0); // CLEAR the state of PB6(OC1B) on next TCNT1==OCR1B
pulsePol = 1;
}
}
#endif
@@ -163,7 +168,6 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation
setupPulses();
// TODO test that it's optimized
if (!IS_PXX_PROTOCOL(g_model.protocol) && !IS_DSM2_PROTOCOL(g_model.protocol)) {
// cli is not needed because for these 2 protocols interrupts are not enabled when entering here
@@ -694,6 +698,8 @@ static void setupPulsesPiccoZ(uint8_t chn)
void setupPulses()
{
uint8_t required_protocol = g_model.protocol;
if (s_pulses_paused)
required_protocol = PROTO_NONE;
if (s_current_protocol != required_protocol) {
+10 -4
View File
@@ -34,13 +34,19 @@
#ifndef pulses_avr_h
#define pulses_avr_h
void startPulses();
void setupPulses();
void DSM2_Init();
void DSM2_Done();
extern uint8_t s_current_protocol;
extern uint8_t s_pulses_paused;
extern uint8_t *pulses2MHzRPtr;
extern uint8_t *pulses2MHzWPtr;
void startPulses();
inline bool pulsesStarted() { return s_current_protocol != 255; }
inline void pausePulses() { s_pulses_paused = true; }
inline void resumePulses() { s_pulses_paused = false; }
void setupPulses();
void DSM2_Init();
void DSM2_Done();
#endif
/*eof*/