void user_init(void) { uart_init(BIT_RATE_9600, BIT_RATE_9600); os_install_putc1((void *)uart_putc1); avr_uart_override_rx_intr (); os_delay_us(1000000); CFG_Load(); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); INFO("\r\nSystem started ...\r\n"); avr_init_task (); avr_reg_msg_callback(avr_msg_cb); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { wifi_station_set_auto_connect(FALSE); stdoutInit(); CFG_Load(); ioInit(); MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n"); stack_init(); /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */ captdnsInit(); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif os_timer_disarm(&websockTimer); os_timer_setfn(&websockTimer, websockTimerCb, NULL); os_timer_arm(&websockTimer, 1000, 1); os_printf("\nReady\n"); }
void CFG_Load(void) { filehandle_t* cfgFile ; cfgFile = FS_OpenFile(CONFIG_FILENAME, "wrt"); FS_UploadToRAM(cfgFile); if (!cfgFile) { Log_Printf("[CFG_Load] Unable to find player settings file, creating it.\n"); CFG_Save(); CFG_Load(); return; } //Check the magic number if(strncmp(cfgFile->filedata, cfgMagicNumber, strlen(cfgMagicNumber))) { Log_Printf("[CFG_Load] Magic number check failed.\n"); return; } //Reading visited act FS_CloseFile(cfgFile); }
LOCAL void ICACHE_FLASH_ATTR initDone_cb() { CFG_Load(); os_printf("\n%s starting ...\n", sysCfg.deviceName); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); char temp[100]; os_sprintf(temp, "/Raw/%s/offline", sysCfg.device_id); MQTT_InitLWT(&mqttClient, temp, "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnData(&mqttClient, mqttDataCb); os_printf("SDK version is: %s\n", system_get_sdk_version()); os_printf("Smart-Config version is: %s\n", smartconfig_get_version()); system_print_meminfo(); os_printf("Flash size map %d; id %lx\n", system_get_flash_size_map(), spi_flash_get_id()); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, sysCfg.deviceName, wifiConnectCb); lcdInit(); lightOn(); showString(1, 1, "MQTT Monitor"); }
void user_init(void) { system_set_os_print(0); uart_init(BIT_RATE_115200, BIT_RATE_115200); os_delay_us(1000000); CFG_Load(); // Initialize the GPIO subsystem. gpio_init(); //Set GPIO2 to output mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); //Set GPIO2 high gpio_output_set(ROOMBA_WAKEUP_PIN, 0, ROOMBA_WAKEUP_PIN, 0); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); INFO("\r\nSystem started ...\r\n"); }
void ICACHE_FLASH_ATTR user_init(void) { pcd8544_settings.lcdVop = PCD8544_CONTRAST; pcd8544_settings.tempCoeff = 0x04; pcd8544_settings.biasMode = 0x14; pcd8544_settings.inverse = false; // you can change these values to any pin you like and have access to pcd8544_settings.resetPin = PCD8544_RESET_PIN; //-1; This pin is now optional. // Set it to negative value to disable. // If you do disable it, you must tie LCD reset pin to esp reset via resistor. pcd8544_settings.scePin = PCD8544_SCE_PIN; //-1; This pin is now optional. // Set it to negative value to disable. // If you do disable it, you must tie LCD CE pin to GND via resistor. // dcPin, sdinPin and sclkPin can be used for other SPI devices if scePin is *NOT* disabled. pcd8544_settings.dcPin = PCD8544_DC_PIN; pcd8544_settings.sdinPin = PCD8544_SDIN_PIN; pcd8544_settings.sclkPin = PCD8544_SCLK_PIN; // Make uart0 work with just the TX pin. Baud:115200,n,8,1 // The RX pin is now free for GPIO use. stdout_init(); os_delay_us(1000000); // wait a second PCD8544_init(&pcd8544_settings); PCD8544_initLCD(&pcd8544_settings); CFG_Load(); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnData(&mqttClient, mqttDataCb); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); os_timer_setfn(&lcd_timer, (os_timer_func_t*) lcdInitTask, NULL); os_timer_arm(&lcd_timer, user_procTaskPeriod, 0); INFO("\nSystem started ...\n"); }
//Main routine. Initialize stdout, the I/O and the webserver and we're done. void user_init(void) { // HTTPD stdoutInit(); ioInit(); httpdInit(builtInUrls, 80); //MQTT uart_init(115200, 115200); CFG_Load(); sleepms(1000); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); // MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); INFO("device_ID:%s\r\n",sysCfg.device_id); INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host); //DS18B20 timers os_timer_disarm(&ds18b20_timer); os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0); os_timer_arm(&ds18b20_timer, DELAY, 1); //NTP timers ntp_get_time(); os_timer_disarm(&NTP_timer); os_timer_setfn(&NTP_timer, (os_timer_func_t *)ntp_get_time, (void *)0); os_timer_arm(&NTP_timer, NTPDELAY, 1); // initialize GPIO2 PIN_FUNC_SELECT(PIN_GPIO2_MUX, PIN_GPIO2_FUNC); GPIO_OUTPUT_SET(PIN_GPIO2, 0); INFO("GPIO2 set to OFF\r\n"); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); os_printf("\nReady\n"); }
void user_init(void) { //uart_init(BIT_RATE_115200, BIT_RATE_115200); uart_init(BIT_RATE_9600, BIT_RATE_115200); os_delay_us(1000000); CFG_Load(); //MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); MQTT_InitConnection(&mqttClient, "user.jdaiot.com", 1883, 0); //MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); MQTT_InitClient(&mqttClient, "g500001", "LASS", "LaSS2015", 120, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); //// modified for LASS system_os_task(recvTask, recvTaskPrio, recvTaskQueue, recvTaskQueueLen); tick=0; refreshTime=10; // turn off timer os_timer_disarm(&tmr0); // // set the timer call back function // os_timer_setfn(&tmr0, tsr0, &mqttClient); // // turn timer on to trigger each .5 second // os_timer_arm(&tmr0, 5000, 1); //every 5 second INFO("\r\nSystem started ...\r\n"); }
void ICACHE_FLASH_ATTR u_mqtt_init() { CFG_Load(); /* * Original, old call with SSID and Passwd included. * WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); * * NOTE:- Our WiFi-Connect callback calls the MQTT_Connect function, * which in turn will call the mqttConnectCb() function when * communications with the MQTT servcer are established. */ WIFI_Connect(wifiConnectCb); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); }
void user_init(void) { uart_init(BIT_RATE_115200, BIT_RATE_115200); os_delay_us(1000000); CFG_Load(); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); INFO("\r\nSystem started ...\r\n"); }
void user_init(void) { int access_point = 1; uart_init(BIT_RATE_115200, BIT_RATE_115200); os_delay_us(1000000); if(access_point) { wifi_set_opmode(STATIONAP_MODE); } else { gpio_init(); PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); gpio_output_set(0, 0, (1 << pin), 0); CFG_Load(); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); INFO("\r\nSystem started ...\r\n"); } }
//Main routine void ICACHE_FLASH_ATTR user_init(void) { stdoutInit(); os_delay_us(100000); CFG_Load(); ioInit(); WIFI_Connect(wifiConnectCb); httpdInit(builtInUrls, sysCfg.httpd_port); if(sysCfg.ntp_enable==1) { sntp_init(sysCfg.ntp_tz); //timezone } if(sysCfg.mqtt_enable==1) { MQTT_InitConnection(&mqttClient, (uint8_t *)sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_use_ssl ); MQTT_InitClient(&mqttClient, (uint8_t *)sysCfg.mqtt_devid, (uint8_t *)sysCfg.mqtt_user, (uint8_t *)sysCfg.mqtt_pass, sysCfg.mqtt_keepalive,1); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); } if(sysCfg.sensor_dht22_enable) DHTInit(SENSOR_DHT22, 30000); if(sysCfg.sensor_ds18b20_enable) ds_init(30000); broadcastd_init(); thermostat_init(30000); /* //Netbios to set the name struct softap_config wiconfig; os_memset(netbios_name, ' ', sizeof(netbios_name)-1); if(wifi_softap_get_config(&wiconfig)) { int i; for(i = 0; i < sizeof(netbios_name)-1; i++) { if(wiconfig.ssid[i] < ' ') break; netbios_name[i] = wiconfig.ssid[i]; }; } else os_sprintf(netbios_name, "ESP8266"); netbios_name[sizeof(netbios_name)-1]='\0'; netbios_init(); */ os_printf("\nRelay Board Ready\n"); os_printf("Free heap size:%d\n",system_get_free_heap_size()); #ifdef CGIPWM_H //Mind the PWM pin!! defined in pwm.h duty=0; pwm_init( 50, &duty); pwm_set_duty(duty, 0); pwm_start(); #endif //OLEDInit(); }
void ICACHE_FLASH_ATTR CFG_init(uint32 delay) { os_timer_disarm(&delay_timer); os_timer_setfn(&delay_timer, (os_timer_func_t *) checkLazyWrite, (void *) 0); os_timer_arm(&delay_timer, delay, true); CFG_Load(); }
//Main routine. Initialize stdout, the I/O and the webserver and we're done. void user_init(void) { // my stuff dBR_BOILER_SET=65; // default setting 65C boiler temperature on reboot dBR_TEMP_ROOM_SET=18; // default setting 18C room temperature on reboot dBR_HUMIDITY_SET=60; // default setting 65% humidity target on reboot dBR_MODE=2; // default BR MODE is AUTO dDEVICE_MODE=1; // This mode defines if device uses remote (MQTT) management or uses local logics - 0 for remote, 1 for local mode. DEFAULT is 0 - remote // HTTPD stdoutInit(); ioInit(); httpdInit(builtInUrls, 80); //MQTT uart_init(115200, 115200); CFG_Load(); sleepms(1000); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL); //MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); //MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1); // MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); INFO("device_ID:%s\r\n",sysCfg.device_id); INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host); //DS18B20 timers os_timer_disarm(&ds18b20_timer); os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0); os_timer_arm(&ds18b20_timer, DELAY, 1); // DHT22 initialize DHTInit(DHT22, DELAY); os_timer_disarm(&dht22_timer); os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0); os_timer_arm(&dht22_timer, DELAY, 1); // INPUT PIN initialize ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts ETS_GPIO_INTR_ATTACH(read_input_pin, 13); // GPIO13 interrupt handler PIN_FUNC_SELECT(PIN_GPIO13_MUX, PIN_GPIO13_FUNC); gpio_output_set(0, 0, 0, BIT13); // Set GPIO13 as input PIN_PULLUP_EN(PIN_GPIO13_MUX); // Enable pullup GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13)); // Clear GPIO12 status gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_NEGEDGE); // Interrupt on NEGATIVE GPIO13 edge ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts // INFO("Input pin INITIALIZED ! ! !"); // initialize GPIO12 PIN_FUNC_SELECT(PIN_GPIO12_MUX, PIN_GPIO12_FUNC); GPIO_OUTPUT_SET(PIN_GPIO12, 0); // INFO("GPIO12 set to OFF\r\n"); // initialize GPIO5 GPIO_OUTPUT_SET(PIN_GPIO5, 0); // INFO("GPIO5 set to OFF\r\n"); // initialize GPIO14 PIN_FUNC_SELECT(PIN_GPIO14_MUX, PIN_GPIO14_FUNC); GPIO_OUTPUT_SET(PIN_GPIO14, 0); // INFO("GPIO14 set to OFF\r\n"); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb); os_printf("\nReady\n"); }
/**************************************************************************** * MenuLanguageSelect ***************************************************************************/ int MenuLanguageSelect() { int cnt = 0; int ret = 0, choice = 0; int scrollon; int returnhere = 0; GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume); // because destroy GuiSound must wait while sound playing is finished, we use a global sound if(!btnClick2) btnClick2=new GuiSound(button_click2_pcm, button_click2_pcm_size, Settings.sfxvolume); // GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, Settings.sfxvolume); char imgPath[100]; snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path); GuiImageData btnOutline(imgPath, button_dialogue_box_png); snprintf(imgPath, sizeof(imgPath), "%ssettings_background.png", CFG.theme_path); GuiImageData settingsbg(imgPath, settings_background_png); GuiTrigger trigA; trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); GuiTrigger trigB; trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); char fullpath[100]; int countfiles = GetAllDirFiles(Settings.languagefiles_path); if (!strcmp("", Settings.languagefiles_path)) { sprintf(fullpath, "%s", tr("Standard")); } else { sprintf(fullpath, "%s", Settings.languagefiles_path); } GuiText titleTxt(fullpath, 24, (GXColor) {0, 0, 0, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); titleTxt.SetPosition(0,0); GuiButton pathBtn(300, 50); pathBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); pathBtn.SetPosition(0,28); pathBtn.SetLabel(&titleTxt); pathBtn.SetSoundOver(&btnSoundOver); pathBtn.SetSoundClick(btnClick2); pathBtn.SetTrigger(&trigA); pathBtn.SetEffectGrow(); GuiImage oggmenubackground(&settingsbg); oggmenubackground.SetAlignment(ALIGN_LEFT, ALIGN_TOP); oggmenubackground.SetPosition(0, 0); GuiText backBtnTxt(tr("Back") , 22, THEME.prompttext); backBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage backBtnImg(&btnOutline); if (Settings.wsprompt == yes) { backBtnTxt.SetWidescreen(CFG.widescreen); backBtnImg.SetWidescreen(CFG.widescreen); } GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); backBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); backBtn.SetPosition(-190, 400); backBtn.SetLabel(&backBtnTxt); backBtn.SetImage(&backBtnImg); backBtn.SetSoundOver(&btnSoundOver); backBtn.SetSoundClick(btnClick2); backBtn.SetTrigger(&trigA); backBtn.SetTrigger(&trigB); backBtn.SetEffectGrow(); GuiText defaultBtnTxt(tr("Default") , 22, THEME.prompttext); defaultBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage defaultBtnImg(&btnOutline); if (Settings.wsprompt == yes) { defaultBtnTxt.SetWidescreen(CFG.widescreen); defaultBtnImg.SetWidescreen(CFG.widescreen); } GuiButton defaultBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); defaultBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); defaultBtn.SetPosition(190, 400); defaultBtn.SetLabel(&defaultBtnTxt); defaultBtn.SetImage(&defaultBtnImg); defaultBtn.SetSoundOver(&btnSoundOver); defaultBtn.SetSoundClick(btnClick2); defaultBtn.SetTrigger(&trigA); defaultBtn.SetEffectGrow(); GuiText updateBtnTxt(tr("Update Files") , 22, THEME.prompttext); updateBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage updateBtnImg(&btnOutline); if (Settings.wsprompt == yes) { updateBtnTxt.SetWidescreen(CFG.widescreen); updateBtnImg.SetWidescreen(CFG.widescreen); } GuiButton updateBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); updateBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); updateBtn.SetPosition(0, 400); updateBtn.SetLabel(&updateBtnTxt); updateBtn.SetImage(&updateBtnImg); updateBtn.SetSoundOver(&btnSoundOver); updateBtn.SetSoundClick(btnClick2); updateBtn.SetTrigger(&trigA); updateBtn.SetEffectGrow(); customOptionList options2(countfiles); for (cnt = 0; cnt < countfiles; cnt++) { char filename[64]; strlcpy(filename, GetFileName(cnt), sizeof(filename)); char *dot = strchr(filename, '.'); if (dot) *dot='\0'; options2.SetName(cnt, "%s", filename); options2.SetValue(cnt, NULL); } if (cnt < 9) { scrollon = 0; } else { scrollon = 1; } GuiCustomOptionBrowser optionBrowser4(396, 280, &options2, CFG.theme_path, "bg_options_settings.png", bg_options_settings_png, scrollon, 10); optionBrowser4.SetPosition(0, 90); optionBrowser4.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); HaltGui(); GuiWindow w(screenwidth, screenheight); w.Append(&oggmenubackground); w.Append(&pathBtn); w.Append(&backBtn); w.Append(&defaultBtn); w.Append(&updateBtn); w.Append(&optionBrowser4); mainWindow->Append(&w); w.SetEffect(EFFECT_FADE, 20); ResumeGui(); while (w.GetEffect()>0) usleep(50); while (!returnhere) { if (shutdown == 1) Sys_Shutdown(); else if (reset == 1) Sys_Reboot(); else if (backBtn.GetState() == STATE_CLICKED) { backBtn.ResetState(); break; } else if (defaultBtn.GetState() == STATE_CLICKED) { choice = WindowPrompt(tr("Loading standard language."),0,tr("OK"), tr("Cancel")); if (choice == 1) { sprintf(Settings.language_path, "notset"); cfg_save_global(); gettextCleanUp(); HaltGui(); CFG_Load(); ResumeGui(); returnhere = 2; } defaultBtn.ResetState(); //optionBrowser4.SetFocus(1); // commented out to prevent crash } else if (updateBtn.GetState() == STATE_CLICKED) { choice = WindowPrompt(tr("Update all Language Files"),tr("Do you wish to update/download all language files?"),tr("OK"), tr("Cancel")); if (choice == 1) { bool network = true; if (!IsNetworkInit()) { network = NetworkInitPrompt(); } if (network) { const char URL[60] = "http://usbloader-gui.googlecode.com/svn/trunk/Languages/"; char fullURL[300]; FILE *pfile; URL_List LinkList(URL); int listsize = LinkList.GetURLCount(); subfoldercreate(Settings.languagefiles_path); for (int i = 0; i < listsize; i++) { ShowProgress(tr("Updating Language Files:"), 0, LinkList.GetURL(i), i, listsize-1); if (strcasecmp(".lang", strrchr(LinkList.GetURL(i), '.')) == 0) { snprintf(fullURL, sizeof(fullURL), "%s%s", URL, LinkList.GetURL(i)); struct block file = downloadfile(fullURL); if (file.data && file.size) { char filepath[300]; snprintf(filepath, sizeof(filepath), "%s%s", Settings.languagefiles_path, LinkList.GetURL(i)); pfile = fopen(filepath, "wb"); fwrite(file.data, 1, file.size, pfile); fclose(pfile); } free(file.data); } } ProgressStop(); returnhere = 1; break; } } updateBtn.ResetState(); //optionBrowser4.SetFocus(1); // commented out to prevent crash } else if (pathBtn.GetState() == STATE_CLICKED) { w.Remove(&optionBrowser4); w.Remove(&backBtn); w.Remove(&pathBtn); w.Remove(&defaultBtn); char entered[43] = ""; strlcpy(entered, Settings.languagefiles_path, sizeof(entered)); int result = OnScreenKeyboard(entered,43,0); w.Append(&optionBrowser4); w.Append(&pathBtn); w.Append(&backBtn); w.Append(&defaultBtn); if ( result == 1 ) { int len = (strlen(entered)-1); if (entered[len] !='/') strncat (entered, "/", 1); strlcpy(Settings.languagefiles_path, entered, sizeof(Settings.languagefiles_path)); WindowPrompt(tr("Languagepath changed."),0,tr("OK")); if (isInserted(bootDevice)) { cfg_save_global(); returnhere = 1; break; } else { WindowPrompt(tr("No SD-Card inserted!"), tr("Insert an SD-Card to save."), tr("OK")); } } if (countfiles > 0) { optionBrowser4.SetFocus(1); } pathBtn.ResetState(); } ret = optionBrowser4.GetClickedOption(); if (ret>=0) { choice = WindowPrompt(tr("Do you want to change language?"), 0, tr("Yes"), tr("Cancel")); if (choice == 1) { if (isInserted(bootDevice)) { snprintf(Settings.language_path, sizeof(Settings.language_path), "%s%s", Settings.languagefiles_path, GetFileName(ret)); cfg_save_global(); if (!checkfile(Settings.language_path)) { sprintf(Settings.language_path, tr("not set")); WindowPrompt(tr("File not found."),tr("Loading standard language."),tr("OK")); } gettextCleanUp(); HaltGui(); CFG_Load(); ResumeGui(); returnhere = 2; break; } else { WindowPrompt(tr("No SD-Card inserted!"), tr("Insert an SD-Card to save."), tr("OK"), 0,0,0,-1); } } optionBrowser4.SetFocus(1); } } w.SetEffect(EFFECT_FADE, -20); while (w.GetEffect()>0) usleep(50); HaltGui(); mainWindow->Remove(&w); ResumeGui(); return returnhere; }
int main(int argc, char *argv[]) { setlocale(LC_ALL, "en.UTF-8"); geckoinit = InitGecko(); if (hbcStubAvailable() || geckoinit) { InitTextVideo(); } // DEBUG_Init(GDBSTUB_DEVICE_USB, 1); //_break(); __exception_setreload(5); //auto reset code dump nobody gives us codedump info anyways. gprintf("\n\n------------------"); gprintf("\nUSB Loader GX rev%s",GetRev()); gprintf("\nmain(%d", argc); for (int i=0;i<argc;i++) gprintf(", %s",argv[i]?argv[i]:"<NULL>"); gprintf(")"); // This part is added, because we need a identify patched ios // printf("\n\tReloading into ios 236"); if (IOS_ReloadIOSsafe(236) < 0) { // printf("\n\tIOS 236 not found, reloading into 36"); IOS_ReloadIOSsafe(36); } printf("\n\tStarting up"); MEM2_init(36); // Initialize 36 MB MEM2_takeBigOnes(true); s32 ret; bool startupproblem = false; bool bootDevice_found=false; if (argc >= 1) { if (!strncasecmp(argv[0], "usb:/", 5)) { strcpy(bootDevice, "USB:"); bootDevice_found = true; } else if (!strncasecmp(argv[0], "sd:/", 4)) bootDevice_found = true; } printf("\n\tInitializing controllers"); /** PAD_Init has to be before InitVideo don't move that **/ PAD_Init(); // initialize PAD/WPAD printf("\n\tInitialize USB (wake up)"); USBDevice_Init(); // seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5") gprintf("\n\tChecking for stub IOS"); ios222rev = getIOSrev(0x00000001000000dell); ios249rev = getIOSrev(0x00000001000000f9ll); //if we don't like either of the cIOS then scram if (!(ios222rev==4 || ios222rev==5 || (ios249rev>=9 && ios249rev<65280))) { InitTextVideo(); printf("\x1b[2J"); if ((ios222rev < 0 && ios222rev != WII_EINSTALL) && (ios249rev < 0 && ios249rev != WII_EINSTALL)) { printf("\n\n\n\tWARNING!"); printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+"); printf("\n\n\tWe cannot determine the versions on your system,\n\tsince you have no patched ios 36 or 236 installed."); printf("\n\tTherefor, if loading of USB Loader GX fails, you\n\tprobably have installed the 4.2 update,"); printf("\n\tand you should go figure out how to get some cios action going on\n\tin your Wii."); printf("\n\n\tThis message will show every time."); sleep(5); } else { printf("\n\n\n\tERROR!"); printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+"); printf("\n\n\tI found \n\t\t222 = %d%s",ios222rev,ios222rev==65280?" (Stubbed by 4.2 update)":""); printf("\n\t\t249 = %d%s",ios249rev,ios249rev==65280?" (Stubbed by 4.2 update)":""); printf("\n\n\tGo figure out how to get some cIOS action going on\n\tin your Wii and come back and see me."); sleep(15); printf("\n\n\tBye"); USBDevice_deInit(); exit(0); } } printf("\n\tReloading ios 249..."); ret = IOS_ReloadIOSsafe(249); printf("%d", ret); if (ret < 0) { printf("\n\tIOS 249 failed, reloading ios 222..."); ret = IOS_ReloadIOSsafe(222); printf("%d", ret); if (ret < 0) { printf("\n\tIOS 222 failed, reloading ios 250..."); ret = IOS_ReloadIOSsafe(250); printf("%d", ret); if(ret < 0) { printf("\n\tIOS 250 failed, reloading ios 223..."); ret = IOS_ReloadIOSsafe(223); printf("%d", ret); if (ret < 0) { printf("\n\tERROR: cIOS could not be loaded!\n"); sleep(5); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } } } printf("\n\tInitialize sd card"); SDCard_Init(); printf("\n\tLoad ehc module"); load_ehc_module(); printf("\n\tdeinit sd card"); SDCard_deInit(); } printf("\n\tInit wbfs..."); ret = WBFS_Init(WBFS_DEVICE_USB); printf("%d", ret); if (ret < 0) { printf("\n\tYou have issues with a slow disc, or a difficult disc\n\tReloading 222..."); ret = IOS_ReloadIOSsafe(222); printf("%d", ret); /*if(ret < 0) { // printf("\n\tSleeping for 4 seconds"); // sleep(4); InitVideo(); // Initialise video Menu_Render(); BootUpProblems(); startupproblem = true; ret = 1; }*/ printf("\n\tInitialize sd card"); SDCard_Init(); printf("\n\tLoad ehc module"); load_ehc_module(); printf("\n\tdeinit sd card"); SDCard_deInit(); printf("\n\tInitialize wbfs..."); USBDevice_deInit(); USBDevice_Init(); ret = WBFS_Init(WBFS_DEVICE_USB); printf("%d", ret); if(ret < 0) { // printf("\n\tSleeping for 4 seconds"); // sleep(4); InitVideo(); // Initialise video Menu_Render(); BootUpProblems(); startupproblem = true; ret = 1; } } printf("\n\tInitialize sd card"); SDCard_Init(); // mount SD for loading cfg's //this should have already been done by now in order to WBFS_Init(). printf("\n\tInitialize usb device"); USBDevice_Init(); // and mount USB:/ if (!bootDevice_found) { printf("\n\tSearch for configuration file"); //try USB //left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config if (checkfile((char*) "USB:/config/GXglobal.cfg") || (checkfile((char*) "USB:/apps/usbloader_gx/boot.elf")) || checkfile((char*) "USB:/apps/usbloadergx/boot.dol") || (checkfile((char*) "USB:/apps/usbloadergx/boot.elf")) || checkfile((char*) "USB:/apps/usbloader_gx/boot.dol")) strcpy(bootDevice, "USB:"); printf("\n\tConfiguration file is on %s", bootDevice); } // Try opening and closing the configuration file here // to prevent a crash dump later on - giantpune char GXGlobal_cfg[26]; sprintf(GXGlobal_cfg, "%s/config/GXGlobal.cfg", bootDevice); FILE *fp = fopen(GXGlobal_cfg, "r"); if (fp) { fclose(fp); } gettextCleanUp(); printf("\n\tLoading configuration..."); CFG_Load(); printf("done"); // gprintf("\n\tbootDevice = %s",bootDevice); /* Load Custom IOS */ if ((Settings.cios == ios222 && IOS_GetVersion() != 222) || (Settings.cios == ios223 && IOS_GetVersion() != 223)) { printf("\n\tReloading IOS to config setting (%d)...", Settings.cios == ios222 ? 222 : 223); SDCard_deInit(); // unmount SD for reloading IOS USBDevice_deInit(); // unmount USB for reloading IOS USBStorage2_Deinit(); ret = IOS_ReloadIOSsafe(Settings.cios == ios222 ? 222 : 223); printf("%d", ret); SDCard_Init(); load_ehc_module(); if (ret < 0) { SDCard_deInit(); Settings.cios = ios249; ret = IOS_ReloadIOSsafe(249); // now mount SD:/ //no need to keep mindlessly mounting and unmounting SD card SDCard_Init(); } USBDevice_Init(); // and mount USB:/ WBFS_Init(WBFS_DEVICE_USB); } else if ((Settings.cios == ios249 && IOS_GetVersion() != 249) || (Settings.cios == ios250 && IOS_GetVersion() != 250)) { printf("\n\tReloading IOS to config setting (%d)...", ios249 ? 249 : 250); SDCard_deInit(); // unmount SD for reloading IOS USBDevice_deInit(); // unmount USB for reloading IOS USBStorage2_Deinit(); ret = IOS_ReloadIOSsafe(ios249 ? 249 : 250); printf("%d", ret); if (ret < 0) { Settings.cios = ios222; ret = IOS_ReloadIOSsafe(222); SDCard_Init(); load_ehc_module(); } else SDCard_Init(); // now mount SD:/ //no need to keep mindlessly mounting and unmounting SD card USBDevice_Init(); // and mount USB:/ WBFS_Init(WBFS_DEVICE_USB); } // Partition_GetList(&partitions); if (ret < 0) { printf("\nERROR: cIOS could not be loaded!"); sleep(5); exit(0); //SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } //gprintf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());//don't need gprintf if sending console shit to gecko, too printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision()); // printf("Sleeping for 5 seconds\n"); // sleep(5); //if a ID was passed via args copy it and try to boot it after the partition is mounted //its not really a headless mode. more like hairless. if (argc > 1 && argv[1]) { if (strlen(argv[1])==6) strncpy(headlessID, argv[1], sizeof(headlessID)); } //! Init the rest of the System Sys_Init(); Wpad_Init(); if(!startupproblem) InitVideo(); InitAudio(); // Initialize audio WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); // load main font from file, or default to built-in font fontSystem = new FreeTypeGX(); char *fontPath = NULL; asprintf(&fontPath, "%sfont.ttf", CFG.theme_path); fontSystem->loadFont(fontPath, font_ttf, font_ttf_size, 0); fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); free(fontPath); fontClock = new FreeTypeGX(); fontClock->loadFont(NULL, clock_ttf, clock_ttf_size, 0); fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); gprintf("\n\tEnd of Main()"); InitGUIThreads(); MainMenu(MENU_CHECK); return 0; }