Ejemplo n.º 1
0
void PAGE_ShowSafetyDialog()
{
    if (disable_safety) {
        return; // don't show safety dialog when calibrating
    }
    if (dialog) {
        u64 unsafe = PROTOCOL_CheckSafe();
        if (! unsafe) {
            GUI_RemoveObj(dialog);
            dialog = NULL;
            PROTOCOL_Init(0);
        } else {
            safety_string_cb(NULL, NULL);
            u32 crc = Crc(tempstring, strlen(tempstring));
            if (crc != dialogcrc) {
                GUI_Redraw(dialog);
                dialogcrc = crc;
            }
        }
    } else {
        tempstring[0] = 0;
        dialogcrc = 0;
        dialog = GUI_CreateDialog(&gui->dialog, 10 + DLG_XOFFSET, 42 + DLG_YOFFSET, 300, 188, _tr("Safety"), safety_string_cb, safety_ok_cb, dtOk, NULL);
    }
}
Ejemplo n.º 2
0
void Init() {
    PWR_Init();
    CLOCK_Init();
    UART_Initialize();
    printf("Start\n");
    Initialize_ButtonMatrix();
    SPIFlash_Init(); //This must come before LCD_Init() for 7e

    LCD_Init();
    CHAN_Init();

    SPITouch_Init();
    SOUND_Init();
    BACKLIGHT_Init();
    BACKLIGHT_Brightness(1);
    AUTODIMMER_Init();
    SPI_FlashBlockWriteEnable(1); //Enable writing to all banks of SPIFlash

    PPMin_TIM_Init();
#ifdef MODULAR
    //Force protocol to none to initialize RAM
    Model.protocol = PROTOCOL_NONE;
    PROTOCOL_Init(1);
#endif
#if HAS_RTC
    RTC_Init();        // Watchdog must be running in case something goes wrong (e.g no crystal)
#endif
}
Ejemplo n.º 3
0
static void bind_cb(guiObject_t *obj, const void *data)
{
    (void)data;
    (void)obj;
    if (PROTOCOL_AutoBindEnabled())
        PROTOCOL_Init(0);
    else
        PROTOCOL_Bind();
}
Ejemplo n.º 4
0
void PROTOCOL_Bind()
{
    if(! (proto_state & PROTO_INIT)) {
        PROTOCOL_Init(0);
    }
    if (! (proto_state & PROTO_READY)) {
        return;
    }
    if(Model.protocol != PROTOCOL_NONE && PROTOCOL_LOADED)
        PROTO_Cmds(PROTOCMD_BIND);
}
Ejemplo n.º 5
0
static void calibrate_sticks(void)
{
    // bug fix: should turn of safety dialog during calibrating, or it might fail when stick is not calibrated and safety setting is on
    PAGE_DisableSafetyDialog(1);
    PROTOCOL_DeInit();
    PAGE_SetModal(1);
    PAGE_RemoveAllObjects();
    PAGE_SetActionCB(_action_cb_calibrate);
    snprintf(tempstring, sizeof(tempstring), "%s",  _tr("Center all \nsticks and knobs\nthen press ENT"));
    GUI_CreateLabelBox(&guic->msg, 1, 10, LCD_WIDTH -1, LCD_HEIGHT - 10,
            LCD_HEIGHT > 70? &NARROW_FONT:&DEFAULT_FONT, NULL, NULL, tempstring);
    memcpy(cp->calibration, Transmitter.calibration, sizeof(cp->calibration));

    while(1) {
        CLOCK_ResetWatchdog();
        if(PWR_CheckPowerSwitch())
            PWR_Shutdown();
        if(priority_ready & (1 << MEDIUM_PRIORITY)) {
            BUTTON_Handler();
            priority_ready &= ~(1 << MEDIUM_PRIORITY);
        }
        if(priority_ready & (1 << LOW_PRIORITY)) {
            //Only sample every 100msec
            GUI_RefreshScreen();
            priority_ready = 0;
        }
        for (u8 i = 0; i < INP_HAS_CALIBRATION; i++) {
            s32 value = CHAN_ReadRawInput(i + 1);
            if (value > Transmitter.calibration[i].max)
                Transmitter.calibration[i].max = value;
            else if (value < Transmitter.calibration[i].min)
                Transmitter.calibration[i].min = value;
        }
        if (calibrate_state == CALI_SUCCESSEXIT || calibrate_state == CALI_EXIT)
            break;
    }
    if (calibrate_state == CALI_EXIT)
        memcpy(Transmitter.calibration, cp->calibration, sizeof(cp->calibration));

    PAGE_SetActionCB(NULL);
    PROTOCOL_Init(0);
    PAGE_TxConfigureInit(-1);   // should be -1 so that devo10 can get back to previous item selection
    PAGE_DisableSafetyDialog(0);
}
Ejemplo n.º 6
0
static void okcancel_cb(guiObject_t *obj, const void *data)
{
    int msg = (long)data;
    (void)obj;
    if (msg == LOAD_MODEL + 1) {
        /* Load Model */
        if (mp->selected != CONFIG_GetCurrentModel()) { // don't do that if model didn't change
            CONFIG_SaveModelIfNeeded();
            PROTOCOL_DeInit();
            CONFIG_ReadModel(mp->selected);
            CONFIG_SaveTxIfNeeded();  //Save here to ensure in case of crash we restart on the right model
            /* Need to recalculate channels to see if we're in a safe state */
            MIXER_Init();
            MIXER_CalcChannels();
            PROTOCOL_Init(0);
        }
    } else if (msg == SAVE_MODEL + 1) {
        /* Save Model */
        CONFIG_WriteModel(mp->selected);
        CONFIG_ReadModel(mp->selected);  //Reload the model after saving to switch (for future saves)
    } else if (msg == LOAD_TEMPLATE + 1) {
        /* Load Template */
        get_idx_filename(tempstring, "template", ".ini", mp->selected-1, "");
        CONFIG_ReadTemplate(tempstring);
    } else if (msg == LOAD_ICON + 1) {
        if (mp->selected == 1)
            Model.icon[0] = 0;
        else
            strcpy(Model.icon, mp->iconstr);
    } else if (msg == LOAD_LAYOUT + 1) {
        /* Load Layout */
        if (mp->selected > mp->file_state) {
            sprintf(tempstring, "models/model%d.ini", mp->selected - mp->file_state);
        } else {
            get_idx_filename(tempstring, "layout", ".ini", mp->selected-1, "layout/");
        }
        CONFIG_ReadLayout(tempstring);
    }
    PAGE_SetModal(0);
    PAGE_RemoveAllObjects();
    mp->return_page(-1);  // -1 for devo10 means return to the focus of previous page, which is important so that users don't need to scroll down from the 1st item
}
Ejemplo n.º 7
0
void PROTOCOL_CheckDialogs()
{
    if (proto_state & PROTO_MODULEDLG) {
        if(! PAGE_DialogVisible()) {
            //Dialog was dismissed, proceed
            proto_state &= ~PROTO_MODULEDLG;
            PROTOCOL_Init(0);
        }
        return;
    }
    if (PROTOCOL_WaitingForSafe()) {
        PAGE_ShowSafetyDialog();
    } else {
        if (PROTOCOL_Binding()) {
            PAGE_ShowBindingDialog(proto_state & PROTO_BINDDLG);
            proto_state |= PROTO_BINDDLG;
        } else if (proto_state & PROTO_BINDDLG) {
            PAGE_CloseBindingDialog();
            MUSIC_Play(MUSIC_DONE_BINDING);
            proto_state &= ~PROTO_BINDDLG;
        }
    }
}
Ejemplo n.º 8
0
void PROTOCOL_InitModules()
{
#if HAS_MULTIMOD_SUPPORT
    int error = 0;
    const char * missing[TX_MODULE_LAST];
    memset(missing, 0, sizeof(missing));

    if (PROTOCOL_SetSwitch(TX_MODULE_LAST) == 0) {
        //No Switch found
/*
        missing[MULTIMOD] = MODULE_NAME[MULTIMOD];
        for(int i = 0; i < MULTIMOD; i++) {
            if(Transmitter.module_enable[i].port == SWITCH_ADDRESS) {
                error = 1;
                printf("Disabling %s because switch wasn't found\n", MODULE_NAME[i]);
                missing[i] = MODULE_NAME[i];
                Transmitter.module_enable[i].port = 0;
            }
        }
*/
    }
    int orig_proto = Model.protocol;
    for(int i = 0; i < MULTIMOD; i++) {
        if(Transmitter.module_enable[i].port) {
            for(int j = 1; j < PROTOCOL_COUNT; j++) {
                if (get_module(j) == i) {
                    //Try this module
                    Model.protocol = j;
                    PROTOCOL_Load(1);
                    if (! PROTOCOL_LOADED)
                        continue;
                    int res = (long)PROTO_Cmds(PROTOCMD_RESET);
                    if (res == 0)
                        continue;
                    if (res < 0) {
                        error = 1;
                        missing[i] = MODULE_NAME[i];
                        if (! (Transmitter.extra_hardware & FORCE_MODULES))
                            Transmitter.module_enable[i].port = 0;
                    }
                    break;
                }
            } 
        }
    }
    //Put this last because the switch will not respond until after it has been initialized
    if (Transmitter.module_enable[MULTIMOD].port && PROTOCOL_SetSwitch(TX_MODULE_LAST) == 0) {
        //No Switch found
	error = 1;
        missing[MULTIMOD] = MODULE_NAME[MULTIMOD];
    }
    Model.protocol = orig_proto;
    if(error) {
        proto_state |= PROTO_MODULEDLG;
        PAGE_ShowModuleDialog(missing);
    } else
#endif //HAS_MULTIMOD_SUPPORT
    {
        PROTOCOL_Init(0);
    }
}
Ejemplo n.º 9
0
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
}