void main() { /* Declare the variables to be used */ int i,j,tempchar; int results[5][100]; char logString[100]; for(i=0;i<5;i++) { for(j=0;j<100;j++) { results[i][j]=0; } } clrscreen(); for(j=0;j<100;j++) { printf("Answer %d:",j + 1); while ((tempchar < 97) || (tempchar > 101)) { tempchar=getch(); if (tempchar = 8) { return; } } results[tempchar - 97][j]++; clrscreen(); } for(j=0;j<100;j++) { strcpy(logString,""); sprintf(logString,"A: %d",results[0][j]); sprintf(logString,"%s|B: %d",logString,results[1][j]); sprintf(logString,"%s|C: %d",logString,results[2][j]); sprintf(logString,"%s|D: %d",logString,results[3][j]); sprintf(logString,"%s|E: %d\n",logString,results[4][j]); printf("%s",logString); LogInformation(logString); } } // End of main()
void main () { auto int rawdata, datapoint1, datapoint2; auto float voltequ, lovoltage, hivoltage; auto int channel, cal_error, done, key; auto char buffer[128]; brdInit(); // Required for BL2100 series boards while(1) { DispStr(1, 1,"!!!Caution this will overwrite the calibration constants set at the factory."); DispStr(1, 2,"Do you want to continue(Y/N)?"); while(!kbhit()); key = getchar(); if(key == 'Y' || key == 'y') { break; } else if(key == 'N' || key == 'n') { exit(0); } } clrscreen(0, 3); DispStr(1, 1, "ADC0 - ADC10 Calibration Program"); DispStr(1, 2, "--------------------------------"); for(;;) { DispStr(1, 3, "Please enter an input channel, 0 thru A (10)...."); do { channel = getchar(); } while (!(isdigit(channel)) && (channel != 'a') && (channel != 'A')); // convert the ascii hex value to a interger if( channel >= '0' && channel <='9') { channel = channel - 0x30; } else { channel = tolower(channel); channel = (channel - 'a') + 10; } printf("%d", channel); /////get raw data from two known voltage points sprintf(buffer, "Adjust the voltage to appox %.2f volts and then ENTER the actual", MINVOLT); DispStr(1, 5, buffer); DispStr(1, 6, "voltage being measured, (floating point value) = "); gets(buffer); datapoint1 = anaIn(channel); lovoltage = atof(buffer); sprintf(buffer, "Adjust the voltage to appox +%.2f volts and then ENTER the actual", MAXVOLT); DispStr(1, 8, buffer); DispStr(1, 9, "voltage being measured, (floating point value) = "); gets(buffer); datapoint2 = anaIn(channel); hivoltage = atof(buffer); /////calculate gains and offsets cal_error = FALSE; if (anaInCalib(channel, datapoint1, lovoltage, datapoint2, hivoltage)) { cal_error = TRUE; DispStr(1, 12, "Cannot make coefficients...Press any key to retry"); while(!kbhit()); clrscreen(3, 20); } else { /////store coefficients into eeprom (simulated in flash memory) while (anaInEEWr(channel)); /////read back coefficients from eeprom while (anaInEERd(channel)); DispStr(1, 11, "Calibration constants has been written to the eeprom"); // display user options DispStr(1, 17, "User Options:"); DispStr(1, 18, "-------------"); DispStr(1, 19, "- Press the 'C' key to calibrate another ADC channel"); DispStr(1, 20, "- Press the 'Q' key to quit"); } done = FALSE; while (!done && !cal_error) { sprintf(buffer, "Vary voltage on channel %d (voltage range -10 to +10 volts)", channel); DispStr(1, 13, buffer); voltequ = anaInVolts(channel); sprintf(buffer, "Voltage at CH%d is %.4f ", channel, voltequ); DispStr(1, 14, buffer); // check if a key was pressed if(kbhit()) { key = getchar(); if(key == 'C' || key == 'c') { // exit and prompt user for next channel to be calibrated done = TRUE; clrscreen(3, 20); // empty keyboard buffer while(kbhit()) getchar(); } if (key == 'Q' || key == 'q') // check if it's the q or Q key { // exit sample program exit(0); } } } } }
void qnxctrl( int ch ) { int i,j,x,y; switch ( ch ) { case ETX: if ( debses ) break; break; case EOT: if ( debses ) break; break; case ENQ: if ( debses ) break; break; case ACK: if ( debses ) break; break; case BEL: if ( debses ) break; bleep(BP_BEL); break; case BS: if ( debses ) break; /* wraps to previous line from left margin */ /* wraps to bottom right from upper left */ wrtch(BS); break; case HT: if ( debses ) break; i = wherex[VTERM]; if (i < marginright) { do { i++; cursorright(0); } while ((htab[i] != 'T') && (i <= marginright-1)); } if ( i == marginright ) { wrtch(CR); wrtch(LF); } VscrnIsDirty(VTERM); break; case LF: if ( debses ) break; wrtch(LF); break; case VT: if ( debses ) break; break; case FF: if ( debses ) break; /* clear screen to Fill color and home cursor */ clrscreen(VTERM,SP); lgotoxy(VTERM,1,1); /* and home the cursor */ break; case CR: if ( debses ) break; wrtch(CR); break; case SO: if ( debses ) break; break; case SI: if ( debses ) break; break; case DLE: if ( debses ) break; break; case DC1: break; case DC2: if ( debses ) break; case DC3: break; case DC4: if ( debses ) break; break; case NAK: if ( debses ) break; break; case SYN: if ( debses ) break; break; case ETB: if ( debses ) break; break; case CAN: if ( debses ) break; break; case XEM: break; case SUB: if ( debses ) break; break; case ESC: /* initiate escape sequence */ escstate = ES_GOTESC ; break; case XRS: if ( debses ) break; break; case US: if ( debses ) break; break; } }
void main() { auto int channel; auto float voltout, volt1, volt2; auto char tmpbuf[24]; auto int key, done, cal_error; // Initialize I/O to use PowerCoreFLEX prototyping board brdInit(); DispStr(1, 1, "DAC0 - DAC2 Voltage Out Program"); DispStr(1, 2, "-------------------------------"); for(;;) { DispStr(1, 3, "Please enter an output channel (0 - 2) = "); do { channel = getchar(); } while (!((channel >= '0') && (channel <= '2'))); printf("%d", channel-=0x30); done = FALSE; while (!done) { // display DAC voltage message DispStr(1, 6, "Type a desired voltage (in Volts) = "); // get user voltage value for the DAC thats being monitored voltout = atof(gets(tmpbuf)); // send voltage value to DAC for it to output the voltage anaOutVolts(channel, voltout); DispStr(1, 7, "Observe voltage on meter....."); // display user options DispStr(1, 10, "User Options:"); DispStr(1, 11, "-------------"); DispStr(1, 12, "- Press the SPACEBAR to change the voltage"); DispStr(1, 13, "- Press 'C' to change the DAC channel"); DispStr(1, 14, "- Press the 'Q' key to quit"); while(1) { // wait for a key to be pressed while(!kbhit()); key = getchar(); if(key == 'C' || key == 'c') { // exit while loop and clear previous calibration infor done = TRUE; clrscreen(3, 14); // empty keyboard buffer while(kbhit()) getchar(); break; } if (key == 'Q' || key == 'q') // check if it's the q or Q key { // exit sample program exit(0); } if(key == 0x20) { // empty the keyboard buffer and clear user options while(kbhit()) getchar(); clrscreen(6, 14); break; } } } } }
void loop_SHELL() { FILE* _io_=fopen("commands.txt","a+"); realpath("commands.txt", history_file_path); while(1) { char cwd[MAX_SIZE]; char buf[MAX_SIZE]; FILE* _out_; if(getcwd(cwd, MAX_SIZE) != NULL) printf(" %s > ",cwd); else{ printf("Command Prompt error ! Terminating...\n "); exit(1); } if(fgets(buf, MAX_SIZE, stdin)==NULL) continue; if(strlen(buf)<=1) continue; if(updateHistory(buf)==-1) printf("Trouble updating History !\n"); char **args = (char**)malloc(MAX_SIZE*sizeof(char*)); char** p =args; *p=strtok(buf, " \t\n"); while(*p!=NULL) { p++; *p=strtok(NULL, " \t\n"); } if(args==NULL) continue; if(strcmp(args[0],"clear")==0 && args[1]==NULL) clrscreen(); else if(strcmp(args[0],"ls")==0) listContents(args[1]); else if(strcmp(args[0],"env")==0 && args[1]==NULL) showEnvironmentVariables(); else if(strcmp(args[0],"exit")==0 && args[1]==NULL) exit(0); else if(strcmp(args[0],"pwd")==0 && args[1]==NULL) { if (showWorkingDirectory() == -1) printf("Error showing current directory !\n"); } else if(strcmp(args[0],"cd")==0) { if(changeDirectory(args[1])==-1) printf("ERROR : No such directory exists!\n"); } else if(strcmp(args[0],"mkdir")==0) { if(args[1]==NULL) printf("Invalid Command ! Please enter : \n mkdir <dir_name>\n"); else if(makeDirectory(args[1])==-1) printf("ERROR in creating directory !\n"); } else if(strcmp(args[0],"rmdir")==0) { if(args[1]==NULL) printf("Invalid Command ! Please enter : \n rmdir <dir_name>\n"); else if(removeDirectory(args[1])==-1) printf("ERROR in deleting directory !\n"); } else if(strcmp(args[0],"history")==0) { if(showHistory(args[1])==-1) printf("ERROR ! Trouble showing history !\n"); } else executeCommand(args); } }