#include /* module scope9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include /*****************************************************************************/ scope(void) /* oscilloscope */ { char string[30]; int histo=0,i,fail,index,j,k,x,y,ylo,yhi; int ex=2,delay=0,xold,yold[125],ybuf[125],color,metno=1; int scal[]={1,2,4,5,10,20,25,50,100,200}; unsigned int msb,lsb,start,count,thousand; long diff,sum; if(fail=(inlog()||inhist()||insimu()||inremo())) { clkey(); goto abort; } if(parse[4]!=CR) { if(arg(1,32)) goto abort; metno=atoi(&parse[4]); } for(i=0;i<=124;i++) yold[i]=0; clkey(); loop2: clear(); font(1); if(histo) strcpy(string,"HISTOGRAPH"); else strcpy(string,"OSCILLOGRAPH"); text(PALEBLUE,160,479,string); txnumber(); loop: index=metno-1; rect(BLACK,0,0,639,450); /* clear screen */ text(PALEBLUE,0,15,itoa(metno,numb,10)); /* meter no */ if(metno<33) tex(20,15,metlist[index]); /* meter name */ else { strncpy(string,&aname[0]+20*(metno-17),20); string[20]=0; tex(20,15,string); /* user meter title */ } tex(560,38,"MILLISEC"); setcolor(WHITE); for(i=0;i<=10;i++) /* horizontal lines */ line(40,40+40*i,540,40+40*i); for(i=0;i<=10;i++) /* vertical lines */ line(40+50*i,40,40+50*i,440); ylo=40+lolim[index]/10*scal[ex]; if(ylo<450) { line2(BLACK,40,ylo,540,ylo); setcolor(YELLOW); dashline(40,ylo,540,ylo,1); /* lower warning limit */ text(YELLOW,550,ylo+10,"LOWER WARN"); } yhi=40+hilim[index]/10*scal[ex]; if(yhi<450) { line2(BLACK,40,yhi,540,yhi); setcolor(RED); dashline(40,yhi,540,yhi,1); /* upper warning limit */ text(RED,550,yhi+10,"UPPER WARN"); } setcolor(WHITE); texcolor(WHITE); vaxis(0,50,40,11,0,400/scal[ex],0); /* label vertical axis */ text(PALEBLUE,200,15,"PageDown, PageUp, Cursor, ctrl-H, ctrl-R"); while(!kbhit()) { odapc(); sum=0; for(i=0;i<=124;i++) /* convert */ { outp(0x43,0x00); lsb=inp(0x40); /* pit counter0 lower byte */ msb=inp(0x40); /* pit counter0 upper byte */ start=256*msb+lsb; avtxmet(index,1); if(delay) thous(delay); ybuf[i]=40+avmet[index]/10*scal[ex]; outp(0x43,0x00); lsb=inp(0x40); msb=inp(0x40); count=256*msb+lsb; diff=start-count; /* one conversion time */ if(diff<0) diff=diff+65536L; sum=sum+diff; } thousand=sum/2386L; /* total conversion time */ for(i=0;i<=124;i++) /* display */ { x=40+i*4; if(!histo&&(yold[i]<450&&yold[i]>39)) { rect(BLACK,x,yold[i],x+2,yold[i]+2); /* old dot */ for(j=0;j<=10;j++) { xold=40+50*j; y=40+40*j; if((yold[i]==y)||(yold[i]+1==y)||(yold[i]+2==y)) line2(WHITE,x,y,x+2,y); if((xold==x)||(xold==x+1)||(xold==x+2)) line2(WHITE,xold,yold[i],xold,yold[i]+2); } } if(ybuf[i]<450&&ybuf[i]>39) { color=GREEN; if(ybuf[i]yhi) color=RED; rect(color,x,ybuf[i],x+2,ybuf[i]+2); /* new dot */ } else { text(YELLOW,250,35,"OFF SCALE"); texcolor(PALEBLUE); } yold[i]=ybuf[i]; } number2(530,38,thousand,0); } k=caps(); if(k==PUP) { --metno; if(!metno) metno=32; /* wrap */ goto loop; /* next meter curve */ } if(k==PDN) { ++metno; if(metno>32) metno=1; /* wrap */ goto loop; /* next meter curve */ } if(k==LEFT) /* reduce time interval */ { if(--delay<0) delay=32; goto loop; } if(k==RIGHT) /* increase time interval */ { if(++delay>32) delay=0; goto loop; } if(k==UP) { if(++ex>9) ex=0; goto loop; } if(k==DOWN) { if(--ex<0) ex=9; goto loop; } if(k==CTRLH) { histo=histo^0x01; goto loop2; } if(k==REFRESH) goto loop2; abort: keyboard[0]=k; if(k<128) prompt(keyboard); restdata(); /* restore database */ logno=0; refresh=1; return(fail); }