#ifndef __usr_c #define __usr_c #include "usr.h" //0 = no, 1 = yes const prog_char row_yesno[2][4] = { "No \0", "Yes\0" }; //0 = off, 1 = on const prog_char row_onoff[2][4] = { "Off\0", "On \0" }; //0 = cfg1, 1 = cfg2, 2 = cfg3 const prog_char row_cfg[4][6] = { "Cfg 1\0", "Cfg 2\0", "Cfg 3\0", "Abort\0" }; const prog_char row_view[5][6] = { "RaDec\0", "AzAlt\0", "Encod\0", "DTime\0", "RAW \0" }; const prog_char row_motms[5][4] = { "HS \0", "4 \0", "8 \0", "16 \0", "32 \0" }; const prog_char row_usechange[3][4] = { "Use\0", "Can\0", "Mod\0" }; const prog_char row_blank[17] = " \0"; unsigned char usr_choose_table( unsigned char row, char max, char start, const prog_char * ptr, unsigned char len ) { unsigned char k; char c,oldc; c = start; oldc = c + 1; while( (( k = readkey()) == NOKEY) || (k == KEY_MENU_LEFT) || (k == KEY_MENU_RIGHT) ){ if( oldc != c ){ oldc = c; LCDPos(row,0); LCDWriteP((char *)&row_blank); LCDPos(row,0); LCDWriteP((char *)ptr + ( c * len)); LCDPos(row,0); } if( k == KEY_MENU_RIGHT ){ c++; if( c > max ){c = 0;} } if( k == KEY_MENU_LEFT ){ c--; if( c < 0 ){c = max;} } } LCDPos(row,0); LCDWriteP((char *)&row_blank); return( c ); } //start must be one of '+', or '-' unsigned char usr_choose_sign(unsigned char row, unsigned char pos,unsigned char start ) { unsigned char k,c; c = start; while( (( k = readkey()) == NOKEY) || (k == KEY_UP) || (k == KEY_DOWN) ){ LCDPos(row,pos); LCDWriteByte(c); LCDPos(row,pos); if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ if( c == '+' ){ c = '-'; } else { c ='+'; } } } if( k == KEY_NAK ){ return(start); } return(c); } //for numbers 0..9 top should be 0x30, and bottom 0x39, and start inside this range. //for chars A..Z top should be 0x31, and bottom 0x5a, and start inside this range. //for chars a..z top should be 0x61, and bottom 0x7a, and start inside this range. unsigned char usr_choose_nr(unsigned char row, unsigned char pos,unsigned char top, unsigned char bottom, unsigned char start ) { unsigned char k,c; c = start; while( (( k = readkey()) == NOKEY) || (k == KEY_UP) || (k == KEY_DOWN) ){ LCDPos(row,pos); LCDWriteByte(c); LCDPos(row,pos); if( ( k == KEY_UP ) && ( c < bottom ) ){ c++; } if( ( k == KEY_DOWN ) && ( c > top ) ){ c--; } } if( k == KEY_NAK ){ return(start); } return(c); } void printDateTime(void) { char str[16]; sprintf(str,"%02d.%02d.%04d",DAY,MONTH,YEAR); LCDPos(2,0); LCDWrite(str); sprintf(str,"%02d:%02d:%02d UTC",HOUR,MINUTE,SECOND); LCDPos(3,0); LCDWrite(str); } int setusrDate(unsigned char row) { unsigned char k,p,c; char str[16]; LCDPos(row,0); LCDWriteP((char *)&row_blank); sprintf(str,"%02d.%02d.%04d UTC",DAY,MONTH,YEAR); LCDPos(row,0); LCDWrite(str); k = 0; p = 0; LCDPos(row,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(0); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; if( p == 5 ){ p = 4; } if( p == 2 ){ p = 1; } LCDPos(row,p); } } if( k == KEY_RIGHT ){ if( p < 9 ){ p++; if( p == 2 ){ p = 3; } if( p == 5 ){ p = 6; } LCDPos(row,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ c = usr_choose_nr(row, p, 0x30, 0x39, str[p] ); if( c ){ str[p] = c; } LCDPos(row,0); LCDWrite(str); LCDPos(row,p); } } str[2] = 0; str[5] = 0; str[10] = 0; DAY = atoi(&str[0]); MONTH = atoi(&str[3]); YEAR = atoi(&str[6]); return(1); } int setusrTime(unsigned char row) { unsigned char k,p,c; char str[14]; LCDPos(row,0); LCDWriteP((char *)&row_blank); sprintf(str,"%02d:%02d:%02d UTC",HOUR,MINUTE,SECOND); LCDPos(row,0); LCDWrite(str); k = 0; p = 0; LCDPos(row,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(0); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; if( p == 5 ){ p = 4; } if( p == 2 ){ p = 1; } LCDPos(row,p); } } if( k == KEY_RIGHT ){ if( p < 7 ){ p++; if( p == 2 ){ p = 3; } if( p == 5 ){ p = 6; } LCDPos(row,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ c = usr_choose_nr(row, p, 0x30, 0x39, str[p] ); if( c ){ str[p] = c; } LCDPos(row,0); LCDWrite(str); LCDPos(row,p); } } str[2] = 0; str[5] = 0; str[8] = 0; HOUR = atoi(&str[0]); MINUTE = atoi(&str[3]); SECOND = atoi(&str[6]); return(1); } //prints a double as string in the format //example: //+024.12345000000 //max number is +/- 999.99999999999 //min number is +/- 000.00000000001 //normally used for printing degrees, startime, or //hours in a decimal value. //if trg not NULL function also writes the internal formated string //to trg, which should provide place for 17 bytes. void printDoubleDegree(unsigned char row, double val, char *trg) { char str[24]; unsigned char ct,pt,si,st,et; ct = 0; while( ct < 4 ){ str[ct] = 0; ct++; } dtostrf( val,5,11,&str[ct]); while( ct < 10 ){ if( str[ct] == '.' ){ break; } ct++; } if( str[ct] != '.'){ LCDPos(row,0); LCDWrite(&str[4]); return; } pt = ct; ct--; si = '+'; if( str[0] == '-'){ si = '-'; } while( ct > 0 ){ if( str[ct] == '-' ){ si = '-'; } if( ( str[ct] < 0x30 ) || ( str[ct] > 0x39 ) ){ str[ct] = '0'; } ct--; } st = pt - 4; str[st] = si; ct = pt + 1; et = pt + 12; str[et] = 0; while( ct < et ){ if( ( str[ct] < 0x30 ) || ( str[ct] > 0x39 ) ){ str[ct] = '0'; } ct++; } LCDPos(row,0); LCDWrite(&str[st]); if( trg != NULL ){ ct = st; si = 0; while( si < 16 ){ trg[si] = str[ct]; si++; ct++; } trg[si] = 0; } } //prints a long to row like example: //+0000012345 void printLong(unsigned char row, long val){ char str[16]; sprintf(str,"%+011ld",val); LCDPos(row,0); LCDWrite(&str[0]); } //prints an int to row like example: //+00020 void printInt(unsigned char row, int val){ char str[8]; sprintf(str,"%+06d",val); LCDPos(row,0); LCDWrite(&str[0]); } double setusrDoubleDegree( unsigned char row,double init ) { double val; char str[18]; unsigned char k,p,c; LCDPos(row,0); LCDWriteP((char *)&row_blank); printDoubleDegree(row, init, &str[0]); k = 0; p = 0; LCDPos(row,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(init); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; if( p == 4 ){ p = 3; } LCDPos(row,p); } } if( k == KEY_RIGHT ){ if( p < 15 ){ p++; if( p == 4 ){ p = 5; } LCDPos(row,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ if( p == 0 ){ c = usr_choose_sign(row, p, str[p] ); } else { c = usr_choose_nr(row, p, 0x30, 0x39, str[p] ); } if( c ){ str[p] = c; } LCDPos(row,0); LCDWrite(str); LCDPos(row,p); } } val = strtod( &str[0], NULL ); return(val); } long setusrLong( unsigned char row,long init ) { long val; char str[18]; unsigned char k,p,c; LCDPos(row,0); LCDWriteP((char *)&row_blank); sprintf(str,"%+011ld",init); LCDPos(row,0); LCDWrite(&str[0]); k = 0; p = 0; LCDPos(row,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(init); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; LCDPos(row,p); } } if( k == KEY_RIGHT ){ if( p < 10 ){ p++; LCDPos(row,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ if( p == 0 ){ c = usr_choose_sign(row, p, str[p] ); } else { c = usr_choose_nr(row, p, 0x30, 0x39, str[p] ); } if( c ){ str[p] = c; } LCDPos(row,0); LCDWrite(str); LCDPos(row,p); } } val = atol( &str[0] ); return(val); } int setusrInt( unsigned char row,int init ) { int val; char str[8]; unsigned char k,p,c; LCDPos(row,0); LCDWriteP((char *)&row_blank); sprintf(str,"%+06d",init); LCDPos(row,0); LCDWrite(&str[0]); k = 0; p = 0; LCDPos(row,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(init); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; LCDPos(row,p); } } if( k == KEY_RIGHT ){ if( p < 5 ){ p++; LCDPos(row,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ if( p == 0 ){ c = usr_choose_sign(row, p, str[p] ); } else { c = usr_choose_nr(row, p, 0x30, 0x39, str[p] ); } if( c ){ str[p] = c; } LCDPos(row,0); LCDWrite(str); LCDPos(row,p); } } val = atoi( &str[0] ); return(val); } //mode: 0 val is a value representing a value in hours like 23,..... //mode: 1 val is a value representing a value in arcseconds //mode: 2 val is a value representing a value in 1/10 arcseconds //mode: >=3 val is a value representing a value in degrees like 160,.... //hours: 0 output is done as degrees in form +000.00.00 degrees:arcminutes:arcseconds ( like dec,alt,az ) //hours: 1 output is done as hours in form +000:00:00 hours:minutes:seconds ( like ra ) //if trg not NULL, the formatted string will also be stored to trg, which have to be //point to a string with 14 chars. void printDegrees(unsigned char row, double val, char mode, char hours, char *trg){ char str[14]; double d,dd,rest; int a,b,c,e; switch( mode ){ case 0: d = val * 15.0 * 3600.0; break; case 1: d = val; break; case 2: d = val / 10.0; break; case 3: d = val * 3600.0; break; default: d = val * 3600.0; break; } //now d is the value in arcseconds. if( hours ){ d = d / 15.0; } dd = d / 3600.0; modf(dd,&rest); d = d - ( rest * 3600.0 ); a = (int)rest; dd = d / 60.0; modf(dd,&rest); d = d - ( rest * 60.0 ); b = (int)rest; dd = d / 1.0; modf(dd,&rest); d = d - ( rest * 1.0 ); c = (int)rest; dd = d / 0.01; modf(dd,&rest); d = d - ( rest * 0.01 ); e = (int)rest; sprintf(str,"%+04d:%02d:%02d.%02d",a,b,c,e); LCDPos(row,0); LCDWrite(&str[0]); if( trg != NULL ){ a = 0; while( a < 12 ){ trg[a] = str[a]; a++; } trg[a] = 0; } } void showRaDec( struct RADECKOOR *koor ) { LCDPos(1,0); LCDWriteP((char *)&row_blank); LCDPos(1,0); LCDWrite((char *)&koor->name[0]); printDegrees( 2, koor->ra, 0, 1, NULL); printDegrees( 3, koor->dec, 3, 0, NULL); } unsigned char setusrRaDec( struct RADECKOOR *koor ) { double val; char ra[14]; char dec[14]; char name[12]; int ia,ib,ic,id; unsigned char k,p,c,y; ia = 0; while( ia < 12 ){ name[ia] = koor->name[ia]; if( ( name[ia] < 0x20 ) || ( name[ia] > 0x5a ) ){ name[ia] = 0x20; } ia++; } name[11] = 0; LCDCls(); LCDPos(1,0); LCDWrite((char *)&name[0]); printDegrees( 2, koor->ra, 0, 1, &ra[0]); printDegrees( 3, koor->dec, 3, 0, &dec[0]); ra[1] = '0'; k = 0; p = 0; y = 1; LCDPos(y,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(0); } if( k == KEY_LEFT ){ switch( y ){ case 1: if( p > 0 ){ p--; }else{ p = 12; y = 3; } break; case 2: if( p > 0 ){ p--; }else{ p = 10; y = 1; } if( p == 1 ){ p--; } if( p == 4 ){ p--; } if( p == 7 ){ p--; } if( p == 10 ){ p--; } break; case 3: if( p > 0 ){ p--; }else{ p = 12; y = 2; } if( p == 4 ){ p--; } if( p == 7 ){ p--; } if( p == 10 ){ p--; } break; default:break; } LCDPos(y,p); } if( k == KEY_RIGHT ){ switch( y ){ case 1: if( p < 10 ){ p++; }else{ p = 0; y = 2; } break; case 2: if( p < 12 ){ p++; }else{ p = 0; y = 3; } if( p == 1 ){ p++; } if( p == 4 ){ p++; } if( p == 7 ){ p++; } if( p == 10 ){ p++; } break; case 3: if( p < 12 ){ p++; }else{ p = 0; y = 1; } if( p == 4 ){ p++; } if( p == 7 ){ p++; } if( p == 10 ){ p++; } break; default:break; } LCDPos(y,p); } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ switch( y ){ case 1: c = usr_choose_nr(y, p, 0x20, 0x5a, name[p] ); if( c ){ name[p] = c;} break; case 2: if( p == 0 ){ c = usr_choose_sign(y, p, ra[p] ); } else { c = usr_choose_nr(y, p, 0x30, 0x39, ra[p] ); } if( c ){ ra[p] = c;} break; case 3: if( p == 0 ){ c = usr_choose_sign(y, p, dec[p] ); } else { c = usr_choose_nr(y, p, 0x30, 0x39, dec[p] ); } if( c ){ dec[p] = c;} break; default:break; } LCDPos(y,0); switch( y ){ case 1:LCDWrite( (char *)&name[0] );break; case 2:LCDWrite( (char *)&ra[0] );break; case 3:LCDWrite( (char *)&dec[0] );break; default:break; } LCDPos(y,p); } } ra[4] = 0; ra[7] = 0; ra[10] = 0; ia = atoi( &ra[1] ); ib = atoi( &ra[5] ); ic = atoi( &ra[8] ); id = atoi( &ra[11] ); val = (double)ia * 3600.0; val = val + ( (double)ib * 60.0); val = val + (double)ic; val = val + ((double)id * 0.01 ); val = val / 3600.0; if( ra[0] == '-'){ val = val * -1.0; } koor->ra = val; dec[4] = 0; dec[7] = 0; dec[10] = 0; ia = atoi( &dec[1] ); ib = atoi( &dec[5] ); ic = atoi( &dec[8] ); id = atoi( &dec[11] ); val = (double)ia * 3600.0; val = val + ( (double)ib * 60.0); val = val + (double)ic; val = val + ((double)id * 0.01 ); val = val / 3600.0; if( dec[0] == '-'){ val = val * -1.0; } koor->dec = val; ia = 0; while( ia < 12 ){ koor->name[ia] = name[ia]; ia++; } return(1); } #endif