/************************************************************************ * Main Program ***** Programa Principal * ************************************************************************/ void main() { setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); setup_timer_2(T2_DIV_BY_16,0xFF,16); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_adc( ADC_OFF ); enable_interrupts(INT_TIMER1); enable_interrupts(INT_TIMER2); enable_interrupts(INT_RDA); enable_interrupts(INT_EXT1); enable_interrupts(global); str_init(print_date); str_init(print_time); set_timer1(0); init_ext_eeprom(); ds1307_init(); glcd_init(ON); readconfig(); draw_sect(); while (1) { if (firstrun==255) { glcd_fillscreen(OFF); glcd_loadscreen(); glcd_showlogo(); delay_ms(1500); menu_mainmenu(); firstrun = 0; write_eeprom(0x00, firstrun); } if (config==1) { menu_mainmenu(); if(UniTemp[0]==0x43) { write_eeprom(0x01, 1); } else if(UniTemp[0]==0x46) { write_eeprom(0x01, 2); } if(UniPres[0]==0x6D) { write_eeprom(0x02, 1); } else if(UniPres[0]==0x50) { write_eeprom(0x02, 2); } if(UniVel[0]==0x4E) { write_eeprom(0x03, 1); } else if(UniVel[0]==0x6B) { write_eeprom(0x03, 2); } else if(UniVel[0]==0x6D) { write_eeprom(0x03, 3); } update_readings(); button = !PRESSED; config=0; } if (uh>40) { twop[0]=":"; guion[0]="-"; spa[0]=" "; str_init(print_time); str_init(print_date); ds1307_get_time(aux_hr,aux_min,aux_sec); ds1307_get_date(aux_day, aux_month, aux_year, aux_dow); itoa(aux_day,10,print_day); itoa(aux_month,10,print_month); itoa(aux_year,10,print_year); switch(aux_dow) { case 0: { print_dow[0] = "D"; break; } case 1: { print_dow[0] = "L"; break; } case 2: { print_dow[0] = "M"; break; } case 3: { print_dow[0] = "I"; break; } case 4: { print_dow[0] = "J"; break; } case 5: { print_dow[0] = "V"; break; } case 6: { print_dow[0] = "S"; break; } } sprintf(print_date,"%s:%s-%s-%s",print_dow,print_day,print_month,print_year); //strcat(print_date,print_dow); //strcat(print_date,twop); //strcat(print_date,print_day); //strcat(print_date,guion); // strcat(print_date,print_month); //strcat(print_date,guion); //strcat(print_date,print_year); if(aop[0]==0x50) { aux_hr=aux_hr-20; } itoa(aux_hr,10,print_hr); itoa(aux_min,10,print_min); strcat(print_time,print_hr); strcat(print_time,twop); strcat(print_time,print_min); if ((aop[0]==0x41)||(aop[0]==0x50)) { strcat(print_time,twop); strcat(print_time,aop); } rcv_td=1; uh=0; } poll_ok(); lightbuttons(); while(bkbhit) { auxi = bgetc(); switch (auxi) { case 0x54: //T { type=1; str_init(string); break; } case 0x50: //P { type=2; str_init(string); break; } case 0x48: //H { type=3; str_init(string); break; } case 0x41: //A { type=4; str_init(string); break; } case 0x57: //W { type=5; str_init(string); break; } case 0x52: //R { type=6; str_init(string); break; } case 0x44: //D { type=7; str_init(string); break; } case 0x4C: //L { type=8; str_init(string); break; } case 0x56: //V { type=9; str_init(string); break; } case 0x42: //B { type=10; str_init(string); break; } } switch (type) { case 1: //Temperatura { if ((auxi!=0x0D)&&(auxi!=0x54)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(tprint); tt = atol(string); if(UniTemp[0]==0x46) { tt = ((tt*9)/5)+320; } strcat(temp_buffer_eeprom,string); eep+=3; sprintf(ttt,"%3.1w",tt); strcat(tprint,ttt); strcat(tprint,UniTemp); strcpy(t2_print,tprint); rcv_t=1; } break; } case 2: //Presion { if ((auxi!=0x0D)&&(auxi!=0x50)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(pprint); pp = atoi32(string); if(UniPres[0]==0x50) { pp = pp*10; sprintf(ppp,"%6.0w",pp); strcat(pprint,ppp); strcat(pprint,UniPres); } else { sprintf(ppp,"%4.1w",pp); strcat(pprint,ppp); strcat(pprint,UniPres); } rcv_p=1; } break; } case 3: //Humedad { if ((auxi!=0x0D)&&(auxi!=0x48)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="%"; str_init(hprint); hh = atol(string); sprintf(hhh,"%2.1w",hh); strcat(hprint,hhh); strcat(hprint,uni); rcv_h=1; } break; } case 4: //Altitud { if ((auxi!=0x0D)&&(auxi!=0x41)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="m"; str_init(aprint); aa = atol(string); sprintf(aaa,"%5.1w",aa); strcat(aprint,aaa); strcat(aprint,uni); rcv_a=1; } break; } case 5: //Clima { if ((auxi!=0x0D)&&(auxi!=0x57)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; ww = atoi(string); rcv_w=1; } break; } case 6: //Probabilidad de lluvia { if ((auxi!=0x0D)&&(auxi!=0x52)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="%"; str_init(pdlprint); ppdl = atol(string); sprintf(pppdl,"%2.0w",ppdl); strcat(pdlprint,pppdl); strcat(pdlprint,uni); rcv_pdl=1; } break; } case 7: //Direccion del viento { if ((auxi!=0x0D)&&(auxi!=0x44)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(dprint); dd = atol(string); switch(dd) { case 0: { dprint[0]="N"; dprint[1]="\0"; break; } case 1: { dprint[0]="N"; dprint[1]="E"; dprint[2]="\0"; break; } case 2: { dprint[0]="E"; dprint[1]="\0"; break; } case 3: { dprint[0]="S"; dprint[1]="E"; dprint[2]="\0"; break; } case 4: { dprint[0]="S"; dprint[1]="\0"; break; } case 5: { dprint[0]="S"; dprint[1]="O"; dprint[2]="\0"; break; } case 6: { dprint[0]="O"; dprint[1]="\0"; break; } case 7: { dprint[0]="N"; dprint[1]="O"; dprint[2]="\0"; break; } } rcv_d=1; } break; } case 8: //Intensidad de luz { if ((auxi!=0x0D)&&(auxi!=0x4C)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; ll = atoi(string); ll = ll*6.3+67; rcv_l=1; } break; } case 9: //Velocidad del viento { if ((auxi!=0x0D)&&(auxi!=0x56)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(vprint); vv = atoi32(string); if(UniVel[0]==0x6D) { vv = vv * 0.5144; } else if(UniVel[0]==0x6B) { vv = vv * 1.852; } else { } sprintf(vvv,"%4.1w",vv); strcat(vprint,vvv); strcat(vprint,UniVel); rcv_v=1; } break; } case 10: //Bat Status { if ((auxi!=0x0D)&&(auxi!=0x42)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; bat1_st = atoi(string); rcv_bat1_st=1; } break; } } if(eep>=9) { update_eeprom(); eep=0; } update_readings(); glcd_update(); //END KBHIT } glcd_update(); //ENDWHILE } //ENDMAIN }
void main() { enable_interrupts(INT_RDA); enable_interrupts(INT_EXT1); enable_interrupts(global); setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_adc( ADC_OFF ); //setup_adc_ports(NO_ANALOGS|VREF_VREF); // setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_PLL_OFF); glcd_init(ON); int8 axt,axp,axv; axt = read_eeprom(0x01); axp = read_eeprom(0x02); axv = read_eeprom(0x03); if(axt==1) { UniTemp[0]="C"; } if(axt==2) { UniTemp[0]="F"; } if(axp==1) { UniPres[0]="Pa"; } if(axp==2) { UniPres[0]="mBa"; } if(axv==1) { UniVel[0]="m/s"; } if(axv==2) { UniVel[0]="km/h"; } if(axv==3) { UniVel[0]="Nud"; } int16 auxi; int8 type,z; int8 string[10]; int16 tt; int32 pp; char tprint [15]; char pprint [15]; char ttt[10]; char ppp[10]; char temp[] = "T:"; char pres[] = "P:"; for (z=0;z<15;z++) { tprint[z]=0; pprint[z]=0; } //firstrun = read_eeprom(0x00); draw_sect(); while (1) { if (firstrun==71) { glcd_loadscreen(); glcd_showlogo(); delay_ms(1500); menu_mainmenu(); firstrun = 0; write_eeprom(0x00, firstrun); } if (config==1) { menu_mainmenu(); if(UniTemp[1]=="C") { write_eeprom(0x01, 1); } else if(UniTemp[1]=="F") { write_eeprom(0x01, 2); } if(UniPres[1]=="P") { write_eeprom(0x02, 1); } else if(UniPres[1]=="m") { write_eeprom(0x02, 2); } if(UniVel[1]=="m") { write_eeprom(0x03, 1); } else if(UniVel[1]=="k") { write_eeprom(0x03, 2); } else if(UniVel[1]=="N") { write_eeprom(0x03, 3); } pressed=0; config=0; } if (try==1) { try=0; output_toggle(PIN_C2); } while(bkbhit) { auxi = bgetc(); if (auxi==0x54) { type=1; for(i=0;i<15;i++) { string[i]=0x00; } i = 0; } if (auxi==0x50) { type=2; for(i=0;i<15;i++) { string[i]=0x00; } i = 0; } if (auxi!=0x0D) { } if (type==1) //Temperatura { if ((auxi!=0x0D)&&(auxi!=0x54)) { string[i] = auxi; i++; } if (auxi==0x0D) { str_init(tprint); tt = atol(string); sprintf(ttt,"%3.1w",tt); strcat(tprint,temp); strcat(tprint,ttt); strcat(tprint,UniTemp); draw_sect(); glcd_text_sec(1, 1, tprint, OFF); glcd_update(); } } if (type==2) //Presion { if ((auxi!=0x0D)&&(auxi!=0x50)) { string[i] = auxi; i++; } if (auxi==0x0D) { str_init(pprint); pp = atoi32(string); sprintf(ppp,"%3.1w",pp); strcat(pprint,pres); strcat(pprint,ppp); strcat(pprint,UniPres); draw_sect(); glcd_text_sec(1, 2, pprint, OFF); glcd_update(); } } glcd_update(); //END KBHIT } glcd_update(); //ENDWHILE } //ENDMAIN }
int main(int argc, char **argv) { int interactive = 1; time_t start = time(NULL); // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); printf("Starting recovery on %s", ctime(&start)); ui_init(); ui_set_background(BACKGROUND_ICON_INSTALLING); // djp952 - at least for now I want to see everything ui_show_text(1); volumes_init("/sbin/recovery.fstab"); get_args(&argc, &argv); int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; int wipe_data = 0, wipe_cache = 0; int toggle_secure_fs = 0; // TEMP: Dump arguments to see what they look like //int index = 0; //for(index = 0; index < argc; index++) ui_print("ARG%d = [%s]\n", index, argv[index]); int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { switch (arg) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; case 'w': wipe_data = 1; break; case 'c': wipe_cache = 1; break; case 't': ui_show_text(1); break; case '?': LOGE("Invalid command argument: %c\n", arg); continue; } } device_recovery_start(); //if (update_package) { // // For backwards compatibility on the cache partition only, if // // we're given an old 'root' path "CACHE:foo", change it to // // "/cache/foo". // if (strncmp(update_package, "CACHE:", 6) == 0) { // int len = strlen(update_package) + 10; // char* modified_path = malloc(len); // strlcpy(modified_path, "/cache/", len); // strlcat(modified_path, update_package+6, len); // printf("(replacing path \"%s\" with \"%s\")\n", // update_package, modified_path); // update_package = modified_path; // } //} //printf("\n"); property_list(print_property, NULL); printf("\n"); // // EXECUTE RECOVERY // // Automatic: --wipe_data if(wipe_data) { interactive = 0; // No interactive menu mode cmd_wipe_device(); // Wipe the device } // Automatic: --wipe_cache if(wipe_cache) { interactive = 0; // No interactive menu mode cmd_wipe_cache(); // Wipe the cache } // Interactive if(interactive) { cmd_show_usage(); // Explain how to navigate menu_mainmenu(); // Launch the main menu } // // FINISH RECOVERY // // Clean up and write out the logs finish_recovery(send_intent); // Unmount all volumes const Volume* iterator = foreach_volume(NULL); while(iterator != NULL) { unmount_volume(iterator, NULL); iterator = foreach_volume(iterator); } sync(); // One more sync for good luck reboot(RB_AUTOBOOT); // Reboot return EXIT_SUCCESS; // Done }