void ICACHE_FLASH_ATTR app_check_mcu_save(mcu_status_t *st) { if(st == NULL) return; if(sys_status.mcu_status.r != st->r || sys_status.mcu_status.g != st->g || sys_status.mcu_status.b != st->b || sys_status.mcu_status.w != st->w || sys_status.mcu_status.s != st->s) { if(st->s == 1) { INFO("saved the new status into flash when mcu_status changed when led is on\r\n"); sys_status.mcu_status.r = st->r; sys_status.mcu_status.g = st->g; sys_status.mcu_status.b = st->b; sys_status.mcu_status.w = st->w; } sys_status.mcu_status.s = st->s; app_save(); } }
void ICACHE_FLASH_ATTR app_load(void) { system_param_load( (APP_START_SEC), 0, (void *)(&sys_status), sizeof(sys_status)); uint32_t warm_boot = 0; system_rtc_mem_read(64+20, (void *)&warm_boot, sizeof(warm_boot)); //INFO("rtc warm_boot = %X\r\n", warm_boot); if (sys_status.init_flag) { if (warm_boot != 0x66AA) { INFO("Cold boot up, set the switch on!\r\n"); sys_status.mcu_status.s = 1; warm_boot = 0x66AA; system_rtc_mem_write(64+20, (void *)&warm_boot, sizeof(warm_boot)); } else { INFO("Warm boot up, use the status saved in flash!\r\n"); } } else { sys_status.init_flag = 1; } sys_status.start_count += 1; sys_status.start_continue += 1; app_save(); }
static void save_options(void) { XFILE *file; long n; int error = 0, h; graf_mouse(HOURGLASS, NULL); if ((file = x_fopen(optname, O_DENYRW | O_WRONLY, &error)) != NULL) { if ((n = x_fwrite(file, &options, sizeof(Options))) == sizeof(Options)) { if (options.cprefs & SAVE_COLORS) error = save_colors(file); if (error == 0) if ((error = dsk_save(file)) == 0) if ((error = ft_save(file)) == 0) if ((error = icnt_save(file)) == 0) if ((error = app_save(file)) == 0) if ((error = prg_save(file)) == 0) error = wd_save(file); } else error = (int) n; if (((h = x_fclose(file)) < 0) && (error == 0)) error = h; } graf_mouse(ARROW, NULL); if (error != 0) hndl_error(MSAVECFG, error); wd_set_update(WD_UPD_COPIED, optname, NULL); wd_do_update(); }
void ICACHE_FLASH_ATTR app_start_check(uint32_t system_start_seconds) { if ((sys_status.start_continue != 0) && (system_start_seconds > 5)) { sys_status.start_continue = 0; app_save(); } #if defined(APP_AGEING) if (sys_status.start_count >= 65535) { INFO("Mjyun APP: clean ageing\r\n"); sys_status.start_count = 65534; app_save(); } else if (sys_status.start_count <= 1) { INFO("Mjyun APP: begin ageing\r\n"); mjpwm_send_duty( PIN_DI, PIN_DCKI, 4095, 4095, 4095, 4095 ); } #endif if (sys_status.start_continue >= 6) { if (APP_STATE_RESTORE != app_state) { INFO("Mjyun APP: system restore\r\n"); app_state = APP_STATE_RESTORE; // Init flag and counter sys_status.init_flag = 0; sys_status.start_continue = 0; // Save param app_save(); // waitting the mjyun_storage init is ok os_timer_disarm(&delay_timer); os_timer_setfn(&delay_timer, (os_timer_func_t *)factory_reset, NULL); os_timer_arm(&delay_timer, 2000, 0); } } else if (sys_status.start_continue >= 5) { os_timer_disarm(&app_smart_timer); mjpwm_send_duty( PIN_DI, PIN_DCKI, 4095, 0, 0, 0 ); } else if (sys_status.start_continue >= 4) { os_timer_disarm(&app_smart_timer); mjpwm_send_duty( PIN_DI, PIN_DCKI, 0, 4095, 0, 0 ); } else if (sys_status.start_continue >= 3) { if (APP_STATE_SMART != app_state) { INFO("Mjyun APP: force into smart config mode\r\n"); app_state = APP_STATE_SMART; /* wait the network_init is ok */ os_timer_disarm(&delay_timer); os_timer_setfn(&delay_timer, (os_timer_func_t *)mjyun_forceentersmartlinkmode, NULL); os_timer_arm(&delay_timer, 200, 0); os_timer_disarm(&app_smart_timer); os_timer_setfn(&app_smart_timer, (os_timer_func_t *)app_smart_timer_tick, NULL); os_timer_arm(&app_smart_timer, 20, 1); } } if ((WIFI_SMARTLINK_START == mjyun_state()) || (WIFI_SMARTLINK_LINKING == mjyun_state()) || (WIFI_SMARTLINK_FINDING == mjyun_state()) || (WIFI_SMARTLINK_GETTING == mjyun_state())) { if (APP_STATE_SMART != app_state) { INFO("Mjyun APP: begin smart config effect\r\n"); app_state = APP_STATE_SMART; os_timer_disarm(&app_smart_timer); os_timer_setfn(&app_smart_timer, (os_timer_func_t *)app_smart_timer_tick, NULL); os_timer_arm(&app_smart_timer, 20, 1); } } else if (APP_STATE_SMART == app_state && (mjyun_state() == WIFI_SMARTLINK_OK || mjyun_state() == WIFI_AP_STATION_OK || mjyun_state() == WIFI_STATION_OK || mjyun_state() == MJYUN_CONNECTED)) { app_state = APP_STATE_NORMAL; app_apply_settings(NULL); app_push_status(NULL); os_timer_disarm(&app_smart_timer); } }
static WORD do_optnmenu(WORD item) { WORD done, rebld, curr; WORD newres, newmode; done = FALSE; rebld = FALSE; curr = win_isel(G.g_screen, G.g_croot, 0); switch(item) { case IDSKITEM: rebld = ins_devices(); if (rebld) { app_blddesk(); do_wredraw(0, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk); } break; case IAPPITEM: curr = 0; while( (curr = win_isel(G.g_screen, G.g_croot, curr)) ) { WORD change; change = ins_app(curr); if (change < 0) /* user cancelled */ break; if (change > 0) /* install or remove */ rebld++; } if (rebld) desk_all(FALSE); break; case IICNITEM: rebld = ins_icon(curr); if (rebld > 0) { app_blddesk(); do_wredraw(0, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk); } #if CONF_WITH_WINDOW_ICONS else if (rebld < 0) { win_bdall(); win_shwall(); } #endif break; case RICNITEM: if (curr) rebld = rmv_icon(curr); if (rebld) { app_blddesk(); do_wredraw(0, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk); } break; case PREFITEM: if (inf_pref()) desk_all(FALSE); break; case SAVEITEM: desk_wait(TRUE); cnx_put(); app_save(TRUE); desk_wait(FALSE); break; case RESITEM: rebld = change_resolution(&newres,&newmode); if (rebld == 1) { if (FALSE) { /* Dummy case for conditional compilation */ } #if CONF_WITH_VIDEL else if (newres == FALCON_REZ) shel_write(5,newmode,1,NULL,NULL); #endif #if CONF_WITH_ATARI_VIDEO else shel_write(5,newres+2,0,NULL,NULL); #endif done = TRUE; } break; } return done; }