// SET CALIB. VALUES //input: // s Sensor structure. // index Point to a specific sensor. //description: // function devoted to set each (x,y) // point to be used in the linear // regression. //------------------------------------------- static void set_calib_values(sensor s,unsigned int index) { unsigned int j; float v,w; for(j=0;j<NKVAL;j++){ w=0.0; v=0.0; while(OK==0){ get_adc(s); v=(float) s[index].adc*5/1023; w=counter(w); glcd_rect(0,10,90,30,YES,OFF); sprintf(text,"X[%d]= %.1f gr",j+1,w); glcd_text57(0,10, text,1,ON); sprintf(text,"Y[%d]= %.1f V ",j+1,v); glcd_text57(0,20, text,1,ON); #ifdef FAST_GLCD glcd_update(); #endif } load[j]=w; voltage[j]=v; delay_ms(600); } }
void glcd_text_sec(char sec, char line, char* textptr, int1 color) { int8 ly=0; ly = (line-1)*9; switch (sec) { case 1: { glcd_text57(3, 3+ly, textptr, 1, color); break; } case 2: { glcd_text57(66, 3+ly, textptr, 1, color); break; } case 3: { glcd_text57(3, 34+ly, textptr, 1, color); break; } case 4: { glcd_text57(66, 34+ly, textptr, 1, color); break; } } }
void menu_drawmain(void) { glcd_fillScreen(OFF); glcd_text57(0, 0, mainmenu[0].menutext, 1, ON); glcd_bar(0, 9, 127, 9, 2, ON); //div for(i=1;i<mm;i++) { glcd_text57(0, 14+((i-1)*9), mainmenu[i].menutext, 1, ON); menu_enter(14+((i-1)*9),ON); } glcd_update(); }
// LINEAR REGRESSION ALGORITHM //input: // s Sensor structure. // index Point to a specific sensor. //description: // algorithm based in a simple linear // regression. // At the end, it writes the new calib. // parameters (m and b) in the EEPROM. //------------------------------------------- static void linear_reg(sensor s,unsigned int index) { float Xm,Ym,Sx,Sy,Sxy,r,b0,b1; int i; Xm=0; Ym=0; for(i=0;i<NKVAL;i++){ Xm = Xm + load[i]; Ym = Ym + Voltage[i]; } Xm=Xm/NKVAL; Ym=Ym/NKVAL; Sx=0; Sy=0; Sxy=0; for(i=0;i<NKVAl;i++){ Sx= Sx + pow(load[i]-Xm,2); Sy= Sy + pow(voltage[i]-Ym,2); Sxy = Sxy + (load[i]-Xm)*(voltage[i]-Ym); } b1=Sxy/Sx; b0=Ym-b1*Xm; r=Sxy/(sqrt(Sx)*sqrt(Sy)); s[index].m=b1; s[index].b=b0; glcd_fillScreen(OFF); sprintf(text,"Sensor # %d",index+1); glcd_text57(0,0, text,1,ON); sprintf(text,"R=%.3f",r); glcd_text57(20,30, text,1,ON); sprintf(text,"m=%.3f",s[index].m); glcd_text57(20,40, text,1,ON); sprintf(text,"b=%.3f",s[index].b); glcd_text57(20,50, text,1,ON); #ifdef FAST_GLCD glcd_update(); #endif delay_ms(5000); write_2_eeprom(s,index); }
void GUI_drawLabel(const char *a,unsigned char x, unsigned char y, unsigned char color,unsigned char state){ char c; int i=0; while((c=a[i])!='\0')i++; //glcd_rect(x-6,y-3,x+(i*6)+4,y+8+1,YES,!state); glcd_text57(x,y,a,1,state); //glcd_rect(x-6,y-3,x+(i*6)+4,y+8+1,NO,state); //glcd_rect(x-7,y-4,x+(i*6)+5,y+8+2,NO,!color); }
/************************************************************************ * * * Purpose: Draw main menu * * * * Proposito: Dibuja el menu principal * * * * Passed: None * * Argumento: Nada * * Returned: None * * Retorno: Nada * * Note: * * * * * ************************************************************************/ void menu_drawmain(void) { glcd_fillScreen(OFF); glcd_text57(0, 0, MENUTITLE, 1, ON); glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU1, 1, ON); menu_entrar(14,ON); glcd_text57(0, 23, MENU2, 1, ON); glcd_text57(100, 23, UniTemp, 1, ON); menu_entrar(23,ON); glcd_text57(0, 32, MENU3, 1, ON); glcd_text57(100, 32, UniPres, 1, ON); menu_entrar(32,ON); glcd_text57(0, 41, MENU4, 1, ON); glcd_text57(100, 41, UniVel, 1, ON); menu_entrar(41,ON); glcd_update(); }
/************************************************************************ * * * Purpose: Draw and handles the time config menu * * * * Proposito: Dibuja y maneja el menu de configuracion de la hora * * * * Passed: None * * Argumento: Nada * * Returned: None * * Retorno: Nada * * Note: * * * * * ************************************************************************/ void menu_timemenu(void) { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU1, 1, ON); glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_rect(5, 20, 25, 35, NO, ON); //DoW glcd_text57(9, 24, dow, 1, ON); glcd_rect(35, 20, 55, 35, NO, ON); //Dia glcd_text57(39, 24, dia, 1, ON); glcd_rect(65, 20, 85, 35, NO, ON); //Mes glcd_text57(69, 24, mes, 1, ON); glcd_rect(95, 20, 115, 35, NO, ON); //Año glcd_text57(99, 24, ao, 1, ON); glcd_rect(5, 45, 25, 60, NO, ON); //Hora glcd_text57(9, 49, hora, 1, ON); glcd_rect(35, 45, 55, 60, NO, ON); //Minuto glcd_text57(39, 49, min, 1, ON); glcd_rect(65, 45, 85, 60, NO, ON); // AM/PM. glcd_text57(69, 49, aop, 1, ON); glcd_update(); while (1) { readbuttons(); if (right==PRESSED) { control+=1; if (control>=8) { control = 1; } } if (left==PRESSED) { control-=1; if (control<=0) { control = 7; } } if (enter==PRESSED) { control = 10; } switch (control) { case 1: { glcd_rect(65, 45, 85, 60, YES, OFF); glcd_rect(65, 45, 85, 60, NO, ON); // AM/PM. glcd_text57(69, 49, aop, 1, ON); glcd_rect(5, 20, 25, 35, YES, ON); //DoW glcd_text57(9, 24, dow, 1, OFF); glcd_rect(35, 20, 55, 35, YES, OFF); glcd_rect(35, 20, 55, 35, NO, ON); //Dia glcd_text57(39, 24, dia, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { k++; if(k>=7) { k=0; } switch(k) { case 0: { dow[0] = "L"; break; } case 1: { dow[0] = "M"; break; } case 2: { dow[0] = "I"; break; } case 3: { dow[0] = "J"; break; } case 4: { dow[0] = "V"; break; } case 5: { dow[0] = "S"; break; } case 6: { dow[0] = "D"; break; } } glcd_rect(5, 20, 25, 35, YES, ON); //DoW glcd_text57(9, 24, dow, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { k--; if((k<0)||(k>10)) { k=6; } switch(k) { case 0: { dow[0] = "L"; break; } case 1: { dow[0] = "M"; break; } case 2: { dow[0] = "I"; break; } case 3: { dow[0] = "J"; break; } case 4: { dow[0] = "V"; break; } case 5: { dow[0] = "S"; break; } case 6: { dow[0] = "D"; break; } } glcd_rect(5, 20, 25, 35, YES, ON); //DoW glcd_text57(9, 24, dow, 1, OFF); glcd_update(); } break; } case 2: // DIA { glcd_rect(5, 20, 25, 35, YES, OFF); glcd_rect(5, 20, 25, 35, NO, ON); // DoW glcd_text57(9, 24, dow, 1, ON); glcd_rect(35, 20, 55, 35, YES, ON); //Dia glcd_text57(39, 24, dia, 1, OFF); glcd_rect(65, 20, 85, 35, YES, OFF); glcd_rect(65, 20, 85, 35, NO, ON); //Mes glcd_text57(69, 24, mes, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { int8 auxdia; auxdia = atoi(dia); auxdia -=1; if (auxdia==0) { if (atoi(mes)==2) { auxdia = 28; } else { auxdia = 31; } } itoa(auxdia,10,dia); glcd_rect(35, 20, 55, 35, YES, ON); //Dia glcd_text57(39, 24, dia, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { int8 auxdia; auxdia = atoi(dia); auxdia +=1; if (atoi(mes)==2) { if(auxdia==29) { auxdia = 1; } } if (auxdia==32) { auxdia = 1; } itoa(auxdia,10,dia); glcd_rect(35, 20, 55, 35, YES, ON); //Dia glcd_text57(39, 24, dia, 1, OFF); glcd_update(); } break; } case 3: // MES { glcd_rect(35, 20, 55, 35, YES, OFF); glcd_rect(35, 20, 55, 35, NO, ON); //Dia glcd_text57(39, 24, dia, 1, ON); glcd_rect(65, 20, 85, 35, YES, ON); //Mes glcd_text57(69, 24, mes, 1, OFF); glcd_rect(95, 20, 115, 35, YES, OFF); glcd_rect(95, 20, 115, 35, NO, ON); //Año glcd_text57(99, 24, ao, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { int8 auxmes; auxmes = atoi(mes); auxmes -=1; if (auxmes==0) { auxmes = 12; } itoa(auxmes,10,mes); glcd_rect(65, 20, 85, 35, YES, ON); //Mes glcd_text57(69, 24, mes, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { int8 auxmes; auxmes = atoi(mes); auxmes +=1; if (auxmes==13) { auxmes = 1; } itoa(auxmes,10,mes); glcd_rect(65, 20, 85, 35, YES, ON); //Mes glcd_text57(69, 24, mes, 1, OFF); glcd_update(); } break; } case 4: // AÑO { glcd_rect(65, 20, 85, 35, YES, OFF); glcd_rect(65, 20, 85, 35, NO, ON); //Mes glcd_text57(69, 24, mes, 1, ON); glcd_rect(95, 20, 115, 35, YES, ON); //Año glcd_text57(99, 24, ao, 1, OFF); glcd_rect(5, 45, 25, 60, YES, OFF); glcd_rect(5, 45, 25, 60, NO, ON); //Hora glcd_text57(9, 49, hora, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { int8 auxao; auxao = atoi(ao); auxao -=1; if (auxao==0) { auxao = 99; } itoa(auxao,10,ao); glcd_rect(95, 20, 115, 35, YES, ON); //Año glcd_text57(99, 24, ao, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { int8 auxao; auxao = atoi(ao); auxao +=1; if (auxao==99) { auxao = 0; } itoa(auxao,10,ao); glcd_rect(95, 20, 115, 35, YES, ON); //Año glcd_text57(99, 24, ao, 1, OFF); glcd_update(); } break; } case 5: // HORA { glcd_rect(95, 20, 115, 35, YES, OFF); glcd_rect(95, 20, 115, 35, NO, ON); //Año glcd_text57(99, 24, ao, 1, ON); glcd_rect(5, 45, 25, 60, YES, ON); //Hora glcd_text57(9, 49, hora, 1, OFF); glcd_rect(35, 45, 55, 60, YES, OFF); glcd_rect(35, 45, 55, 60, NO, ON); //Minuto glcd_text57(39, 49, min, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { int8 auxhora; auxhora = atoi(hora); auxhora -=1; if ((aop[0]==0x41)||(aop[0]==0x50)) { if (auxhora<=0) { auxhora = 12; } } else { if ((auxhora<0)||(auxhora>50)) { auxhora = 23; } } itoa(auxhora,10,hora); glcd_rect(5, 45, 25, 60, YES, ON); //Hora glcd_text57(9, 49, hora, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { int8 auxhora; auxhora = atoi(hora); auxhora +=1; if ((aop[0]==0x41)||(aop[0]==0x50)) { if (auxhora>12) { auxhora = 1; } } else { if (auxhora>23) { auxhora = 0; } } itoa(auxhora,10,hora); glcd_rect(5, 45, 25, 60, YES, ON); //Hora glcd_text57(9, 49, hora, 1, OFF); glcd_update(); } break; } case 6: // MINUTOS { glcd_rect(5, 45, 25, 60, YES, OFF); glcd_rect(5, 45, 25, 60, NO, ON); //Hora glcd_text57(9, 49, hora, 1, ON); glcd_rect(35, 45, 55, 60, YES, ON); //Minuto glcd_text57(39, 49, min, 1, OFF); glcd_rect(65, 45, 85, 60, YES, OFF); glcd_rect(65, 45, 85, 60, NO, ON); // AM/PM. glcd_text57(69, 49, aop, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { int8 auxmin; auxmin = atoi(min); if (auxmin==0) { auxmin = 60; } auxmin -=1; itoa(auxmin,10,min); glcd_rect(35, 45, 55, 60, YES, ON); //Minuto glcd_text57(39, 49, min, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { int8 auxmin; auxmin = atoi(min); auxmin +=1; if (auxmin>=60) { auxmin = 0; } itoa(auxmin,10,min); glcd_rect(35, 45, 55, 60, YES, ON); //Minuto glcd_text57(39, 49, min, 1, OFF); glcd_update(); } break; } case 7: // AM - PM { glcd_rect(35, 45, 55, 60, YES, OFF); glcd_rect(35, 45, 55, 60, NO, ON); //Minuto glcd_text57(39, 49, min, 1, ON); glcd_rect(65, 45, 85, 60, YES, ON); //AM PM glcd_text57(69, 49, aop, 1, OFF); glcd_rect(5, 20, 25, 35, YES, OFF); glcd_rect(5, 20, 25, 35, NO, ON); //DoW glcd_text57(9, 24, dow, 1, ON); glcd_update(); if ((up==!PRESSED)&&(down==PRESSED)) { if (aop[0]==0x41) { aop[0] = "P"; } else if (aop[0]==0x50) { aop[0] = "M"; } else if (aop[0]==0x4D) { aop[0] = "A"; } glcd_rect(65, 45, 85, 60, YES, ON); //Minuto glcd_text57(69, 49, aop, 1, OFF); glcd_update(); } if ((up==PRESSED)&&(down==!PRESSED)) { if (aop[0]==0x41) { aop[0] = "M"; } else if (aop[0]==0x50) { aop[0] = "A"; } else if (aop[0]==0x4D) { aop[0] = "P"; } glcd_rect(65, 45, 85, 60, YES, ON); //Minuto glcd_text57(69, 49, aop, 1, OFF); glcd_update(); } break; } case 10: // SET { glcd_fillscreen(OFF); glcd_text57(0, 0, MENU1, 1, ON); glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_rect(5, 20, 25, 35, YES, ON); //DoW glcd_text57(9, 24, dow, 1, OFF); glcd_rect(5, 20, 25, 35, NO, ON); //Dia glcd_text57(9, 24, dia, 1, ON); glcd_rect(35, 20, 55, 35, NO, ON); //Mes glcd_text57(39, 24, mes, 1, ON); glcd_rect(65, 20, 85, 35, NO, ON); //Año glcd_text57(69, 24, ao, 1, ON); glcd_rect(5, 45, 25, 60, NO, ON); //Hora glcd_text57(9, 49, hora, 1, ON); glcd_rect(35, 45, 55, 60, NO, ON); //Minuto glcd_text57(39, 49, min, 1, ON); glcd_rect(65, 45, 85, 60, NO, ON); // AM/PM. glcd_text57(69, 49, aop, 1, ON); glcd_update(); break; } } button = !PRESSED; if (control==10) { /*GRABAR EN RTC*/ ds1307_set_date_time(atoi(dia),atoi(mes),atoi(ao),(k+1),atoi(hora),atoi(min),0,aop[0]); return; } } }
/************************************************************************ * * * Purpose: Draw and handle the submenu * * * * Proposito: Dibuja y maneja cada submenu * * * * Passed: SubMenu position identifier * * Argumento: Identificador de posicion del submenu * * Returned: None * * Retorno: Nada * * Note: * * * * * ************************************************************************/ void menu_submenu(char menu) { switch (menu) { case 1: { menu_timemenu(); i=0; return; break; } case 2: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU2, 1, ON) ; glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU2ITEM1, 1, ON) ; glcd_text57(0, 23, MENU2ITEM2, 1, ON) ; glcd_update(); i = 0; break; } case 3: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU3, 1, ON) ; glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU3ITEM1, 1, ON) ; glcd_text57(0, 23, MENU3ITEM2, 1, ON) ; glcd_update(); i = 0; break; } case 4: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU4, 1, ON) ; glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU4ITEM1, 1, ON) ; glcd_text57(0, 23, MENU4ITEM2, 1, ON) ; glcd_text57(0, 32, MENU4ITEM3, 1, ON) ; glcd_update(); i = 0; break; } } while(1) { readbuttons(); if ((up==!PRESSED)&&(down==PRESSED)) { i+=1; menu_select(i,menu); } if ((up==PRESSED)&&(down==!PRESSED)) { i-=1; menu_select(i,menu); } if (left==PRESSED) { i = 0; button = !PRESSED; break; } if (enter==PRESSED) { switch (menu) { case 2: { switch (i) { case 1: { UniTemp = "C"; break; } case 2: { UniTemp = "F"; break; } } break; } case 3: { switch (i) { case 1: { UniPres = "mBa"; break; } case 2: { UniPres = "Pa"; break; } } break; } case 4: { switch (i) { case 1: { UniVel = "Nud"; break; } case 2: { UniVel = "km/h"; break; } case 3: { UniVel = "m/s"; break; } } break; } } i=0; button = !PRESSED; break; } button = !PRESSED; } button = !PRESSED; }
/************************************************************************ * * * Purpose: Draw the selected item * * * * Proposito: Dibuja el item seleccionado * * * * Passed: char item - Nº of item * * char menu - The menu it belongs * * Argumento: char item - Posicion del item * * char menu - El menu al que pertenece * * Returned: None * * Retorno: Nada * * Note: * * * * * ************************************************************************/ void menu_select(char item, char menu) { switch (menu) { case 0: { switch (item) { case 1: { menu_drawmain(); glcd_bar(0, 17, 127, 17, 9, ON); //selected glcd_text57(0, 14, MENU1, 1, OFF); menu_entrar(14,OFF); glcd_update(); break; } case 2: { menu_drawmain(); glcd_bar(0, 26, 127, 26, 9, ON); //selected glcd_text57(0, 23, MENU2, 1, OFF); glcd_text57(100, 23, UniTemp, 1, OFF); menu_entrar(23,OFF); glcd_update(); break; } case 3: { menu_drawmain(); glcd_bar(0, 35, 127, 35, 9, ON); //selected glcd_text57(0, 32, MENU3, 1, OFF); glcd_text57(100, 32, UniPres, 1, OFF); menu_entrar(32,OFF); glcd_update(); break; } case 4: { menu_drawmain(); glcd_bar(0, 44, 127, 44, 9, ON); //selected glcd_text57(0, 41, MENU4, 1, OFF); glcd_text57(100, 41, UniVel, 1, OFF); menu_entrar(41,OFF); glcd_update(); break; } } break; } case 1: { break; } case 2: { switch (item) { case 1: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU2, 1, ON) ; //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_bar(0, 17, 127, 17, 9, ON); //selected glcd_text57(0, 14, MENU2ITEM1, 1, OFF); glcd_text57(0, 23, MENU2ITEM2, 1, ON) ; glcd_update(); break; } case 2: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU2, 1, ON); //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU2ITEM1, 1, ON); glcd_bar(0, 26, 127, 26, 9, ON); //selected glcd_text57(0, 23, MENU2ITEM2, 1, OFF); glcd_update(); break; } } break; } case 3: { switch (item) { case 1: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU3, 1, ON) ; //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_bar(0, 17, 127, 17, 9, ON); //selected glcd_text57(0, 14, MENU3ITEM1, 1, OFF); glcd_text57(0, 23, MENU3ITEM2, 1, ON) ; glcd_update(); break; } case 2: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU3, 1, ON); //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU3ITEM1, 1, ON); glcd_bar(0, 26, 127, 26, 9, ON); //selected glcd_text57(0, 23, MENU3ITEM2, 1, OFF); glcd_update(); break; } } break; } case 4: { switch (item) { case 1: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU4, 1, ON) ; //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_bar(0, 17, 127, 17, 9, ON); //selected glcd_text57(0, 14, MENU4ITEM1, 1, OFF); glcd_text57(0, 23, MENU4ITEM2, 1, ON) ; glcd_text57(0, 32, MENU4ITEM3, 1, ON) ; glcd_update(); break; } case 2: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU4, 1, ON); //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU4ITEM1, 1, ON); glcd_bar(0, 26, 127, 26, 9, ON); //selected glcd_text57(0, 23, MENU4ITEM2, 1, OFF); glcd_text57(0, 32, MENU4ITEM3, 1, ON) ; glcd_update(); break; } case 3: { glcd_fillScreen(OFF); glcd_text57(0, 0, MENU4, 1, ON); //Titulo glcd_bar(0, 9, 127, 9, 2, ON); //div glcd_text57(0, 14, MENU4ITEM1, 1, ON); glcd_text57(0, 23, MENU4ITEM2, 1, ON); glcd_bar(0, 35, 127, 35, 9, ON); //selected glcd_text57(0, 32, MENU4ITEM3, 1, OFF) ; glcd_update(); break; } } break; } } }
// SENSOR TEST ROUTINE //input: // s Sensor structure. //description: // This function perform a test to // each sensor. // First, it asks to the user to connect // all the sensors, then it checks for the // value read in all the ADC channels and // compares these values with those stored // in the EEPROM memory. If the full scale // error is bigger than MAXERROR a warning // is displayed. //------------------------------------------- unsigned int test_calib(sensor s) { unsigned int op,k,i,j; unsigned int status[4]={0 0 0 0}; float Vx,error; intro: glcd_fillScreen(OFF); sprintf(text,"Conectar todos\n\r los sensores"); glcd_text57(9,0, text,1,ON); sprintf(text,"2-> Ejecutar."); glcd_text57(10,40, text,1,ON); sprintf(text,"3-> Atras."); glcd_text57(10,50, text,1,ON); op=0; j=0; command: // code to attend the user request. #ifdef FAST_GLCD glcd_update(); #endif delay_ms(200); while(op==0){ op=swap( PORTB & 0b00110000); } if(op==2) goto exit; if(op==1){ if(j) goto done; } test: delay_ms(2000); get_adc(s); // read all ADC channels. for(i=0;i<NCH;i++){ Vx = (float) s[i].adc*5.0/1023.0; // compare the read value and the stored value. error=fabs(Vx - s[i].b)/5.0; if(error >= MAXERROR) status[i]=1; } glcd_fillScreen(OFF); // display warning menssage sprintf(text,"Recalibrar Sensores\a"); glcd_text57(0,0, text,1,ON); sprintf(text,"2-> Calibrar."); glcd_text57(10,40, text,1,ON); sprintf(text,"3-> Atras."); glcd_text57(10,50, text,1,ON); k=0; for(i=0;i<NCH;i++){ if(status[i]){ sprintf(text,"S%d",i+1); glcd_text57(10+k,20, text,1,ON); k+=20; } } j=1; op=0; goto command; done: return 0; exit: return 1; }
// SENSOR CALIBRATION //input: // s Sensor structure. //description: // This function stars the sensor's // calibration. // First, it allocate in memory the // arrays "voltage" and "load", used to // store the points for the linear // regression. // The code ask to the user to select a // sensor, then it calls for the values of // each point (load[i],voltage[i]) to be // used in the regression, and finaly it // computes the linear reg. //------------------------------------------- void sensor_calibration(sensor s) { unsigned int k=0,op=0; voltage=(float *)malloc(NKVAL*sizeof(float)); // allocate variables in memory. load=(float *)malloc(NKVAL*sizeof(float)); if((voltage==NULL) || (load==NULL)) goto exit; intro: glcd_fillScreen(OFF); // screen to select a sensor. sprintf(text,"Elegir Sensor"); glcd_text57(10,0, text,1,ON); sprintf(text,"1-> Siguiente."); glcd_text57(10,30, text,1,ON); sprintf(text,"2-> Ejecutar."); glcd_text57(10,40, text,1,ON); sprintf(text,"3-> Atras."); glcd_text57(10,50, text,1,ON); if(k<NCH){ sprintf(text,"Sensor %d",k+1); glcd_text57(20,15, text,1,ON); } else{ sprintf(text,"Todos"); glcd_text57(20,15, text,1,ON); } op=0; command: // code to attend the user request. #ifdef FAST_GLCD glcd_update(); #endif delay_ms(500); while(op==0){ op=swap( PORTB & 0b00110001); // wait until the user press a button. } if (op==2) // checks if the user wants to go out the from the menu. goto exit; if((op==16)){ // checks which sensor the user wants to calibrate. k++; if(k>NCH) k=0; op=0; goto intro; } if((op==1)){ switch (k){ case 0: { goto s0; break; } case 1: { goto s1; break; } case 2: { goto s2; break; } case 3: { goto s3; break; } case 4: { goto s0; break; } } } s0: // option to calibrate sensor one. glcd_fillScreen(OFF); sprintf(text,"Sensor # 1"); glcd_text57(0,0, text,1,ON); sprintf(text,"1-> Incre."); glcd_text57(0,35, text,1,ON); sprintf(text,"2-> Decre."); glcd_text57(0,45, text,1,ON); sprintf(text,"3-> Acep."); glcd_text57(0,55, text,1,ON); set_calib_values(s,0); linear_reg(s,0); if(k<NCH){ k=0; goto intro; } s1: // option to calibrate sensor two. glcd_fillScreen(OFF); sprintf(text,"Sensor # 2"); glcd_text57(0,0, text,1,ON); sprintf(text,"1-> Incre."); glcd_text57(0,35, text,1,ON); sprintf(text,"2-> Decre."); glcd_text57(0,45, text,1,ON); sprintf(text,"3-> Acep."); glcd_text57(0,55, text,1,ON); set_calib_values(s,1); // call the function to set the reg. points. linear_reg(s,1); // call the linear reg. algorithm. if(k<NCH){ k=0; goto intro; } s2: // option to calibrate sensor three. glcd_fillScreen(OFF); sprintf(text,"Sensor # 3"); glcd_text57(0,0, text,1,ON); sprintf(text,"1-> Incre."); glcd_text57(0,35, text,1,ON); sprintf(text,"2-> Decre."); glcd_text57(0,45, text,1,ON); sprintf(text,"3-> Acep."); glcd_text57(0,55, text,1,ON); set_calib_values(s,2); linear_reg(s,2); if(k<NCH){ k=0; goto intro; } s3: // option to calibrate sensor four. glcd_fillScreen(OFF); sprintf(text,"Sensor # 4"); glcd_text57(0,0, text,1,ON); sprintf(text,"1-> Incre."); glcd_text57(0,35, text,1,ON); sprintf(text,"2-> Decre."); glcd_text57(0,45, text,1,ON); sprintf(text,"3-> Acep."); glcd_text57(0,55, text,1,ON); set_calib_values(s,3); linear_reg(s,3); k=0; goto intro; exit: // end of calibration. free(voltage); free(load); }
void update_readings(void) { draw_sect(); //Sec1 if(rcv_t==1) { glcd_text_sec(1, 1, t2_print, OFF); } if(rcv_p==1) { glcd_text_sec(1, 2, pprint, OFF); } if(rcv_h==1) { glcd_text_sec(1, 3, hprint, OFF); } //Sec2 if(rcv_a==1) { glcd_text_sec(2, 1, aprint, ON); } if(rcv_v==1) { glcd_text_sec(2, 2, vprint, ON); } if(rcv_l==1) { glcd_rect(65, 21, 125, 28, NO, ON); glcd_rect(67, 23, ll, 26, YES, ON); } //Sec3 if(rcv_w==1) { switch(ww) { case 1: { glcd_showimg_xy(sun,3, 32, NO); break; } case 2: { glcd_showimg_xy(cloud,3, 32, NO); break; } case 3: { glcd_showimg_xy(rain,3, 32, NO); break; } case 4: { glcd_showimg_xy(snow,3, 32, NO); break; } } } if(rcv_pdl==1) { glcd_text_sec(3, 1, pdlprint, ON); } if(rcv_d==1) { glcd_text_sec(3, 2, dprint, ON); } //Sec4 if(rcv_bat1_st==1) { switch(bat1_st) { case 0: { glcd_showimg_xy(nobat,66, 33, YES); break; } case 1: { glcd_showimg_xy(bat1,66, 33, YES); break; } case 2: { glcd_showimg_xy(bat2,66, 33, YES); break; } case 3: { glcd_showimg_xy(bat3,66, 33, YES); break; } case 4: { glcd_showimg_xy(fullbat,66, 33, YES); break; } } } switch(bat2_st) { case 0: { glcd_showimg_xy(nobat,88, 33, YES); break; } case 1: { glcd_showimg_xy(bat1,88, 33, YES); break; } case 2: { glcd_showimg_xy(bat2,88, 33, YES); break; } case 3: { glcd_showimg_xy(bat3,88, 33, YES); break; } case 4: { glcd_showimg_xy(fullbat,88, 33, YES); break; } } switch(okst) { case 0: { glcd_showimg_xy(warning,115, 33, YES); break; } case 1: { glcd_text57(110,33,ok,1,OFF); break; } } if(rcv_td==1) { glcd_text_sec(4,2,print_date,OFF); glcd_text_sec(4,3,print_time,OFF); } }