#include /* module scales9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include union REGS inregs,outregs; /* raw values max out at 32k for +5 volts input, -32k for -5 volts input */ /**************************************************************************/ scales(void) /* meter scale factors */ { char string[30]; int fail=0,slot,i,j=0,index,k,m=0,n=0,mold=0,nold=0,x,y,value; int x1,y1,hack=0; int des[32]; if(inlog()||inhist()||insimu()) { clkey(); goto abort; } boxit3("ADJUST SCALES?"); start: while(!kbhit()) { odapc(); if(click()==1) { x1=outregs.x.cx; y1=479-outregs.x.dx; if(y1>140||y1<120) goto start; if(x1>220&&x1<240) { k='Y'; goto skip; } if(x1>400&&x1<420) { k='N'; goto skip; } } } k=caps(); skip: if(k=='Y') { boxit("ENTER CIPHER"); for(i=0;i<=3;i++) { k=caps(); if(k!=codec[i]) hack=1; } if(hack) { status[46]|=0x02; clkey(); goto abort; } } else { clkey(); goto abort; /* (RS) */ } if(parse[4]!=CR) { slot=atoi(&parse[4]); /* slot number */ if(slot<1||slot>32) goto failed; index=slot-1; n=comma(2)-comma(1)-1; /* argument length */ if(n>0) { strncpy(string,&parse[comma(1)+1],n); /* value */ string[n]=0; value=atoi(string); if(value<0||value>9999) goto failed; scale[index]=value; } clkey(); goto abort; } clear(); font(1); text(PALEBLUE,100,479,"METER MULTIPLIERS"); txnumber(); stamp(); text(WHITE,140,420,"TITLE"); tex(300,420,"SCALE"); tex(360,440,"DESIRED"); tex(360,420,"READING"); tex(420,440,"ACTUAL"); tex(420,420,"READING"); tex(500,440,"RAW"); tex(500,420,"VALUE"); for(i=0;i<32;i++) des[i]=0; loop2: rect(BLACK,0,0,639,400); rect(DARKGREY,0,85,280,405); for(i=0;i<=15;i++) { index=i+16*j; y=400-20*i; text(WHITE,5,y,itoa(index+1,numb,10)); tex(100,y,metlist[index]); text(PALEBLUE,300,y,itoa(scale[index],numb,10)); tex(360,y,itoa(des[index],numb,10)); tex(500,y,ltoa(raw[index],numb,10)); } loop: clkey(); message(WHITE,"USE CURSOR KEYS OR CLICK LEFT; & PageUp, PageDown TO SELECT"); onmouse(); while(!kbhit()) { calendar(); if(!average()) { rect(BLACK,420,400,600,80); for(i=0;i<16;i++) { index=i+16*j; y=400-20*i; tex(420,y,itoa(avmet[index],numb,10)); tex(500,y,ltoa(raw[index],numb,10)); } } switch(click()) /* mouse button */ { case 1: /* left click */ x=outregs.x.cx; y=479-outregs.x.dx; m=(x-300)/60; if(m<0||m>1) m=0; n=(400-y)/20; if(n>15||n<0) n=0; goto exec; case 3: /* both click */ k=ESC; goto abort; } } k=caps(); if(k>128) cursor: switch(k) { case LEFT: --m; if(m==-1) m=1; break; case RIGHT: ++m; if(m==2) m=0; break; case UP: --n; if(n==-1) n=15; /* wrap */ break; case DOWN: ++n; if(n==16) n=0; /* wrap */ break; case HOME: n=0; break; case END: n=15; break; case PDN: if(++j>1) j=0; goto loop2; case PUP: if(--j<0) j=1; goto loop2; default: goto key; } else /* not a function key */ { key: keyboard[0]=k; if(k<128) prompt(keyboard); goto abort; } exec: index=nold+16*j; x=300+60*mold; y=400-20*nold; offmouse(); rect(BLACK,x,y,x+40,y-10); switch(mold) { case 0: text(PALEBLUE,x,y,itoa(scale[index],numb,10)); break; case 1: text(PALEBLUE,x,y,itoa(des[index],numb,10)); break; } mold=m; nold=n; index=n+16*j; x=300+60*m; y=400-20*n; rect(BLUE,x,y,x+40,y-10); switch(m) { case 0: text(PALEBLUE,x,y,itoa(scale[index],numb,10)); break; case 1: text(PALEBLUE,x,y,itoa(des[index],numb,10)); break; } clkey(); switch(m) { case 0: message(LIGHTGREEN,"ENTER NEW MULTIPLIER (1000 = 1.000), OR Esc TO EXIT"); break; case 1: message(LIGHTGREEN,"ENTER DESIRED READING (0 TO 9999), OR Esc TO EXIT"); break; } onmouse(); while(!kbhit()) switch(click()) /* mouse button */ { case 1: /* left click */ x=outregs.x.cx; y=479-outregs.x.dx; m=(x-300)/60; if(m<0||m>1) m=0; n=(400-y)/20; if(n>15||n<0) n=0; goto exec; case 3: /* both click */ k=ESC; goto abort; } k=caps(); /* null char */ if(k>128) goto cursor; if(k==ESC) goto abort; if(k==CR) goto abort; offmouse(); keyboard[0]=k; string[0]=k; string[1]=0; prompt(string); while(console()!=(int)CR); value=atoi(keyboard); /* convert to integer */ rect(BLACK,x,y,x+40,y-10); /* erase old value */ switch(m) { case 0: scale[index]=value; break; case 1: des[index]=value; if(avmet[index]) scale[index]=((double)scale[index]*(double)des[index])/(double)avmet[index]; rect(BLACK,300,y,x+40,y-10); text(PALEBLUE,300,y,itoa(scale[index],numb,10)); break; } text(GREEN,x,y,keyboard); /* display new value */ goto loop; failed: clkey(); illarg(); fail=1; status[12]|=0x01; /* command failed */ abort: savscale(); /* update hard drive */ refresh=1; return(fail); }