static const char *_contrast_select_cb(guiObject_t *obj, int dir, void *data) { (void)data; (void)obj; u8 changed; Transmitter.contrast = GUI_TextSelectHelper(Transmitter.contrast, 0, 10, dir, 1, 1, &changed); if (changed) { LCD_Contrast(Transmitter.contrast); } if (Transmitter.contrast == 0) return _tr("Off"); sprintf(tempstring, "%d", Transmitter.contrast); return tempstring; }
int main() { Init(); #ifndef MODULAR //Banner(); #endif if(PWR_CheckPowerSwitch()) PWR_Shutdown(); LCD_Clear(0x0000); #ifdef TEST_ADC ADC_ScanChannels(); while(1); #endif u32 buttons = ScanButtons(); if(CHAN_ButtonIsPressed(buttons, BUT_ENTER) || !FS_Mount(NULL, NULL)) { LCD_DrawUSBLogo(LCD_WIDTH, LCD_HEIGHT); USB_Connect(); LCD_Clear(0x0000); FS_Mount(NULL, NULL); } CONFIG_LoadTx(); SPI_ProtoInit(); CONFIG_ReadDisplay(); CONFIG_ReadModel(CONFIG_GetCurrentModel()); CONFIG_ReadLang(Transmitter.language); BACKLIGHT_Brightness(Transmitter.backlight); LCD_Contrast(Transmitter.contrast); LCD_SetFont(DEFAULT_FONT.font); LCD_SetFontColor(DEFAULT_FONT.font_color); #if !HAS_EXTENDED_AUDIO // If Extended Audio is present, move startup msg to Splash page to allow additional audio hardware initialization time MUSIC_Play(MUSIC_STARTUP); #else if (Transmitter.splash_delay < 5) MUSIC_Play(MUSIC_STARTUP); // if no splash page startup msg is used force playing here #endif GUI_HandleButtons(1); MIXER_Init(); PAGE_Init(); CLOCK_StartWatchdog(); #if HAS_DATALOG DATALOG_Init(); #endif priority_ready = 0; CLOCK_SetMsecCallback(LOW_PRIORITY, LOW_PRIORITY_MSEC); CLOCK_SetMsecCallback(MEDIUM_PRIORITY, MEDIUM_PRIORITY_MSEC); // We need to wait until we've actually measured the ADC before proceeding while(! (priority_ready & (1 << LOW_PRIORITY))) ; //Only do this after we've initialized all channel data so the saftey works PROTOCOL_InitModules(); GUI_DrawScreen(); #ifdef HAS_EVENT_LOOP start_event_loop(); #else while(1) { if(priority_ready) { EventLoop(); } //This does not appear to have any impact on power //and has been disabled in common/devo/power.c //but it helps a huge amount for the emulator PWR_Sleep(); } #endif }
int main() { Init(); #ifndef MODULAR //Banner(); #endif if(PWR_CheckPowerSwitch()) PWR_Shutdown(); LCD_Clear(0x0000); #ifdef TEST_ADC ADC_ScanChannels(); while(1); #endif u32 buttons = ScanButtons(); if(CHAN_ButtonIsPressed(buttons, BUT_ENTER) || !FS_Mount(NULL, NULL)) { LCD_DrawUSBLogo(LCD_WIDTH, LCD_HEIGHT); USB_Connect(); LCD_Clear(0x0000); FS_Mount(NULL, NULL); } CONFIG_LoadTx(); SPI_ProtoInit(); CONFIG_ReadDisplay(); CONFIG_ReadModel(CONFIG_GetCurrentModel()); CONFIG_ReadLang(Transmitter.language); BACKLIGHT_Brightness(Transmitter.brightness); LCD_Contrast(Transmitter.contrast); LCD_SetFont(DEFAULT_FONT.font); LCD_SetFontColor(DEFAULT_FONT.font_color); MUSIC_Play(MUSIC_STARTUP); GUI_HandleButtons(1); MIXER_Init(); PAGE_Init(); CLOCK_StartWatchdog(); #if DATALOG_ENABLED DATALOG_Init(); #endif priority_ready = 0; CLOCK_SetMsecCallback(LOW_PRIORITY, LOW_PRIORITY_MSEC); CLOCK_SetMsecCallback(MEDIUM_PRIORITY, MEDIUM_PRIORITY_MSEC); // We need to wait until we've actually measured the ADC before proceeding while(! (priority_ready & (1 << LOW_PRIORITY))) ; //Only do this after we've initialized all channel data so the saftey works PROTOCOL_Init(0); GUI_DrawScreen(); #ifdef HAS_EVENT_LOOP start_event_loop(); #else while(1) { if(priority_ready) { EventLoop(); } //PWR_Sleep(); //This does not appear to have any impact on power } #endif }
int main(void) { uint16_t U_Bat; /* voltage of power supply */ uint8_t Test; /* test value */ /* * init */ /* switch on power to keep me alive */ CONTROL_DDR = (1 << POWER_CTRL); /* set pin as output */ CONTROL_PORT = (1 << POWER_CTRL); /* set pin to drive power management transistor */ /* setup MCU */ MCUCR = (1 << PUD); /* disable pull-up resistors globally */ ADCSRA = (1 << ADEN) | ADC_CLOCK_DIV; /* enable ADC and set clock divider */ #ifdef HW_RELAY /* init relay (safe mode) */ /* ADC_PORT should be 0 */ ADC_DDR = (1 << TP_REF); /* short circuit probes */ #endif /* catch watchdog */ Test = (MCUSR & (1 << WDRF)); /* save watchdog flag */ MCUSR &= ~(1 << WDRF); /* reset watchdog flag */ wdt_disable(); /* disable watchdog */ /* init LCD module */ LCD_BusSetup(); /* setup bus */ LCD_Init(); /* initialize LCD */ LCD_NextLine_Mode(MODE_NONE); /* reset line mode */ /* * watchdog was triggered (timeout 2s) * - This is after the MCU done a reset driven by the watchdog. * - Does only work if the capacitor at the base of the power management * transistor is large enough to survive a MCU reset. Otherwise the * tester simply loses power. */ if (Test) { LCD_Clear(); /* display was initialized before */ LCD_EEString(Timeout_str); /* display: timeout */ LCD_NextLine_EEString(Error_str); /* display: error */ MilliSleep(2000); /* give user some time to read */ CONTROL_PORT = 0; /* power off myself */ return 0; /* exit program */ } /* * operation mode selection */ Config.SleepMode = SLEEP_MODE_PWR_SAVE; /* default: power save */ UI.TesterMode = MODE_CONTINOUS; /* set default mode: continous */ Test = 0; /* key press */ /* catch long key press */ if (!(CONTROL_PIN & (1 << TEST_BUTTON))) /* if test button is pressed */ { RunsMissed = 0; while (Test == 0) { MilliSleep(20); if (!(CONTROL_PIN & (1 << TEST_BUTTON))) /* if button is still pressed */ { RunsMissed++; if (RunsMissed > 100) Test = 3; /* >2000ms */ } else /* button released */ { Test = 1; /* <300ms */ if (RunsMissed > 15) Test = 2; /* >300ms */ } } } /* key press >300ms sets autohold mode */ if (Test > 1) UI.TesterMode = MODE_AUTOHOLD; /* * load saved offsets and values */ if (Test == 3) /* key press >2s resets to defaults */ { SetAdjustDefaults(); /* set default values */ } else /* normal mode */ { LoadAdjust(); /* load adjustment values */ } /* set extra stuff */ #ifdef SW_CONTRAST LCD_Contrast(NV.Contrast); /* set LCD contrast */ #endif /* * welcome user */ LCD_EEString(Tester_str); /* display: Component Tester */ LCD_NextLine_EEString_Space(Edition_str); /* display firmware edition */ LCD_EEString(Version_str); /* display firmware version */ MilliSleep(1500); /* let the user read the display */ /* * init variables */ /* cycling */ RunsMissed = 0; RunsPassed = 0; /* default offsets and values */ Config.Samples = ADC_SAMPLES; /* number of ADC samples */ Config.AutoScale = 1; /* enable ADC auto scaling */ Config.RefFlag = 1; /* no ADC reference set yet */ Config.Vcc = UREF_VCC; /* voltage of Vcc */ wdt_enable(WDTO_2S); /* enable watchdog (timeout 2s) */ /* * main processing cycle */ start: /* reset variabels */ Check.Found = COMP_NONE; Check.Type = 0; Check.Done = 0; Check.Diodes = 0; Check.Resistors = 0; Semi.U_1 = 0; Semi.I_1 = 0; Semi.F_1 = 0; /* reset hardware */ ADC_DDR = 0; /* set all pins of ADC port as input */ /* also remove short circuit by relay */ LCD_NextLine_Mode(MODE_KEEP); /* line mode: keep first line */ LCD_Clear(); /* clear LCD */ /* * voltage reference */ #ifdef HW_REF25 /* external 2.5V reference */ Config.Samples = 200; /* do a lot of samples for high accuracy */ U_Bat = ReadU(TP_REF); /* read voltage of reference (mV) */ Config.Samples = ADC_SAMPLES; /* set samples back to default */ if ((U_Bat > 2250) && (U_Bat < 2750)) /* check for valid reference */ { uint32_t Temp; /* adjust Vcc (assuming 2.495V typically) */ Temp = ((uint32_t)Config.Vcc * UREF_25) / U_Bat; Config.Vcc = (uint16_t)Temp; } #endif /* internal bandgap reference */ Config.Bandgap = ReadU(0x0e); /* dummy read for bandgap stabilization */ Config.Samples = 200; /* do a lot of samples for high accuracy */ Config.Bandgap = ReadU(0x0e); /* get voltage of bandgap reference (mV) */ Config.Samples = ADC_SAMPLES; /* set samples back to default */ Config.Bandgap += NV.RefOffset; /* add voltage offset */ /* * battery check */ /* * ADC pin is connected to a voltage divider Rh = 10k and Rl = 3k3. * Ul = (Uin / (Rh + Rl)) * Rl -> Uin = (Ul * (Rh + Rl)) / Rl * Uin = (Ul * (10k + 3k3)) / 3k3 = 4 * Ul */ /* get current voltage */ U_Bat = ReadU(TP_BAT); /* read voltage (mV) */ U_Bat *= 4; /* calculate U_bat (mV) */ U_Bat += BAT_OFFSET; /* add offset for voltage drop */ /* display battery voltage */ LCD_EEString_Space(Battery_str); /* display: Bat. */ DisplayValue(U_Bat / 10, -2, 'V'); /* display battery voltage */ LCD_Space(); /* check limits */ if (U_Bat < BAT_POOR) /* low level reached */ { LCD_EEString(Low_str); /* display: low */ MilliSleep(2000); /* let user read info */ goto power_off; /* power off */ } else if (U_Bat < BAT_POOR + 1000) /* warning level reached */ { LCD_EEString(Weak_str); /* display: weak */ } else /* ok */ { LCD_EEString(OK_str); /* display: ok */ } /* * probing */ /* display start of probing */ LCD_NextLine_EEString(Running_str); /* display: probing... */ /* try to discharge any connected component */ DischargeProbes(); if (Check.Found == COMP_ERROR) /* discharge failed */ { goto result; /* skip all other checks */ } /* enter main menu if requested by short-circuiting all probes */ if (AllProbesShorted() == 3) { MainMenu(); /* enter mainmenu */; goto end; /* new cycle after job is is done */ } /* check all 6 combinations of the 3 probes */ CheckProbes(TP1, TP2, TP3); CheckProbes(TP2, TP1, TP3); CheckProbes(TP1, TP3, TP2); CheckProbes(TP3, TP1, TP2); CheckProbes(TP2, TP3, TP1); CheckProbes(TP3, TP2, TP1); /* if component might be a capacitor */ if ((Check.Found == COMP_NONE) || (Check.Found == COMP_RESISTOR)) { /* tell user to be patient with large caps :-) */ LCD_Space(); LCD_Char('C'); /* check all possible combinations */ MeasureCap(TP3, TP1, 0); MeasureCap(TP3, TP2, 1); MeasureCap(TP2, TP1, 2); } /* * output test results */ result: LCD_Clear(); /* clear LCD */ LCD_NextLine_Mode(MODE_KEEP | MODE_KEY); /* call output function based on component type */ switch (Check.Found) { case COMP_ERROR: Show_Error(); goto end; break; case COMP_DIODE: Show_Diode(); break; case COMP_BJT: Show_BJT(); break; case COMP_FET: Show_FET(); break; case COMP_IGBT: Show_IGBT(); break; case COMP_THYRISTOR: Show_Special(); break; case COMP_TRIAC: Show_Special(); break; case COMP_RESISTOR: Show_Resistor(); break; case COMP_CAPACITOR: Show_Capacitor(); break; default: /* no component found */ Show_Fail(); goto end; } /* component was found */ RunsMissed = 0; /* reset counter */ RunsPassed++; /* increase counter */ /* * take care about cycling and power-off */ end: #ifdef HW_RELAY ADC_DDR = (1<<TP_REF); /* short circuit probes */ #endif LCD_NextLine_Mode(MODE_NONE); /* reset next line mode */ /* get key press or timeout */ Test = TestKey((uint16_t)CYCLE_DELAY, 12); if (Test == 0) /* timeout (no key press) */ { /* check if we reached the maximum number of rounds (continious mode only) */ if ((RunsMissed >= CYCLE_MAX) || (RunsPassed >= CYCLE_MAX * 2)) { goto power_off; /* -> power off */ } } else if (Test == 1) /* short key press */ { /* a second key press triggers extra functions */ MilliSleep(50); Test = TestKey(300, 0); if (Test > 0) /* short or long key press */ { #ifdef HW_RELAY ADC_DDR = 0; /* remove short circuit */ #endif MainMenu(); /* enter main menu */ goto end; /* re-run cycle control */ } } else if (Test == 2) /* long key press */ { goto power_off; /* -> power off */ } #ifdef HW_ENCODER else if (Test == 4) /* rotary encoder: left turn */ { MainMenu(); /* enter main menu */ goto end; /* re-run cycle control */ } #endif /* default action (also for rotary encoder) */ goto start; /* -> next round */ power_off: /* display feedback (otherwise the user will wait :-) */ LCD_Clear(); LCD_EEString(Bye_str); wdt_disable(); /* disable watchdog */ CONTROL_PORT &= ~(1 << POWER_CTRL); /* power off myself */ return 0; }
int main() { Init(); #ifndef ENABLE_MODULAR //Banner(); #endif if(PWR_CheckPowerSwitch()) PWR_Shutdown(); LCD_Clear(0x0000); #ifdef TEST_ADC ADC_ScanChannels(); while(1); #endif u32 buttons = ScanButtons(); if (CHAN_ButtonIsPressed(buttons, BUT_ENTER) || !FS_Init()) { LCD_DrawUSBLogo(LCD_WIDTH, LCD_HEIGHT); USB_Connect(); LCD_Clear(0x0000); FS_Init(); } CONFIG_LoadTx(); SPI_ProtoInit(); CONFIG_ReadDisplay(); CONFIG_ReadModel(CONFIG_GetCurrentModel()); CONFIG_ReadLang(Transmitter.language); BACKLIGHT_Brightness(Transmitter.backlight); LCD_Contrast(Transmitter.contrast); LCD_SetFont(DEFAULT_FONT.font); LCD_SetFontColor(DEFAULT_FONT.font_color); GUI_HandleButtons(1); MIXER_Init(); PAGE_Init(); CLOCK_StartWatchdog(); #if HAS_DATALOG DATALOG_Init(); #endif priority_ready = 0; CLOCK_SetMsecCallback(LOW_PRIORITY, LOW_PRIORITY_MSEC); CLOCK_SetMsecCallback(MEDIUM_PRIORITY, MEDIUM_PRIORITY_MSEC); // We need to wait until we've actually measured the ADC before proceeding while(! (priority_ready & (1 << LOW_PRIORITY))) PWR_Sleep(); //Only do this after we've initialized all channel data so the saftey works PROTOCOL_InitModules(); GUI_DrawScreen(); // Add startup delay to make sure audio player is initialized // AUDIO_Init() has already been called by CONFIG_ReadModel() #if HAS_EXTENDED_AUDIO audio_queue_time = CLOCK_getms() + 1500; num_audio=1; next_audio=1; #if (LCD_WIDTH == 480) || (LCD_WIDTH == 320) if(Display.background.drawn_background) while(CLOCK_getms() < audio_queue_time - 1200); #endif AUDIO_SetVolume(); // Initial setting of voice volume #endif MUSIC_Play(MUSIC_STARTUP); #ifdef HAS_EVENT_LOOP start_event_loop(); #else while(1) { if(priority_ready) { EventLoop(); } //This does not appear to have any impact on power //and has been disabled in common/devo/power.c //but it helps a huge amount for the emulator PWR_Sleep(); } #endif }