/// <summary> /// wait for the specficed ms until keypressed /// </summary> /// <param name="ms">The ms to wait.</param> /// <returns>The key pressed(ASC-II not guaranteed).</returns> int waitkey(double ms) { int key = -1; double start = get_real_time(); double end = start + ms / 1000; #if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) set_conio_terminal_mode(); #endif if (ms <= 0) { // disable timer if ms <= 0 end = DBL_MAX; } while (key == -1) { key = kb_hit(); //printf("%d", (int)get_elapsed_time_ms(start)); if (get_real_time() >= end) { break; } } //std::cin.get(); #if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) reset_terminal_mode(); #endif return key; }
//------------------------------------------------------------ void ofAppNoWindow::exitApp(){ ofLogVerbose("ofAppNoWindow") << "terminating headless (no window) app!"; #if defined TARGET_OSX || defined TARGET_LINUX // this doesn't exist on windows and gives linking errors, so commented out. reset_terminal_mode(); #endif OF_EXIT_APP(0); }
int get_last_key() { int r; uchar c; if ((r = read(0, &c, sizeof(c))) < 0) { return r; } else { reset_terminal_mode(); return c; } }
void motor_usals(int frontend_fd, double site_lat, double site_long, double sat_long) { if (ioctl(frontend_fd, FE_SET_TONE, SEC_TONE_OFF) == -1) perror("FE_SET_TONE ERROR!"); usleep(20000); if (ioctl(frontend_fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18) == -1) perror("FE_SET_VOLTAGE ERROR!"); usleep(20000); double r_eq = 6378.14; // Earth radius double r_sat = 42164.57; // Distance from earth centre to satellite site_lat = radian(site_lat); site_long = radian(site_long); sat_long = radian(sat_long); double declination = degree( atan( r_eq * sin(site_lat) / ( (r_sat - r_eq) + (r_eq * (1 - cos(site_lat))) ) ) ); // x = [0], y = [1], z = [2] double dishVector[3] = { r_eq * cos(site_lat), 0, r_eq * sin(site_lat) }; double satVector[3] = { r_sat * cos(site_long - sat_long), r_sat * sin(site_long - sat_long), 0 }; double satPointing[3] = { satVector[0] - dishVector[0], satVector[1] - dishVector[1], satVector[2] - dishVector[2] } ; double motor_angle = degree( atan( satPointing[1]/satPointing[0] ) ); int sixteenths = fabs(motor_angle) * 16.0 + 0.5; int angle_1, angle_2; angle_1 = motor_angle > 0.0 ? 0xd0 : 0xe0; angle_1 |= sixteenths >> 8; angle_2 = sixteenths & 0xff; printf("Long: %.2f, Lat: %.2f, Orbital Pos: %.2f, RotorCmd: %02x %02x, motor_angle: %.2f declination: %.2f\n", degree(site_long), degree(site_lat), degree(sat_long), angle_1, angle_2, motor_angle, declination); struct dvb_diseqc_master_cmd usals_cmd = { { 0xe0, 0x31, 0x6e, angle_1, angle_2, 0x00 }, 5 }; diseqc_send_msg(frontend_fd, usals_cmd); printf("Waiting for motor to move, either wait 45sec or hit 's' to skip\n"); int c; int sec = time(NULL); set_conio_terminal_mode(); do { sleep(1); if ( kbhit() ) c = kbgetchar(); /* consume the character */ } while( (char)c != 's' && sec+45 > time(NULL) ); reset_terminal_mode(); }
void motor_gotox(int frontend_fd, int pmem) { struct dvb_diseqc_master_cmd gotox_cmd = { { 0xe0, 0x31, 0x6B, pmem, 0x00, 0x00 }, 4 }; diseqc_send_msg(frontend_fd, gotox_cmd); printf("Waiting for motor to move, either wait 45sec or hit 's' to skip\n"); int c; int sec = time(NULL); set_conio_terminal_mode(); do { sleep(1); if ( kbhit() ) c = kbgetchar(); /* consume the character */ } while( (char)c != 's' && sec+45 > time(NULL) ); reset_terminal_mode(); }
//------------------------------------------------------------ void ofAppNoWindow::exitApp() { // -- This already exists in ofExitCallback static ofEventArgs voidEventArgs; #ifdef OF_USING_POCO ofNotifyEvent( ofEvents().exit, voidEventArgs ); #endif ofLog(OF_LOG_VERBOSE,"No Window OF app is being terminated!"); reset_terminal_mode(); OF_EXIT_APP(0); }
int main(){ set_conio_terminal_mode(); int nCount=0; int bLoop=1; int xpos,ypos; xpos=0;ypos=1; char cmd; while(bLoop){ // scanf("%c",&cmd); if(kbhit() != 0){ cmd = getch(); switch(cmd){ case 'w': ypos-=1; break; case 's': ypos+=1; break; case 'a': xpos-=1; break; case 'd': xpos+=1; break; case 'q': bLoop = 0; break; } if(cmd == 'q'){ bLoop =0; } printf("%d \r\n",(int)cmd); } printf("%d \r",nCount); nCount++; nCount %=10; system("clear"); drawMyBox(xpos,ypos,0,44,1,3); drawMyBox(nCount,5,0,42,1,5); gotoxy(0,20); printf("-----------------------"); } reset_terminal_mode(); return 0; }
//------------------------------------------------------------ void ofxAppNoWindow::exitApp(){ // -- This already exists in ofExitCallback // static ofEventArgs voidEventArgs; // // if(ofAppPtr)ofAppPtr->exit(); // // #ifdef OF_USING_POCO // ofNotifyEvent( ofEvents.exit, voidEventArgs ); // #endif ofLogVerbose("ofxAppNoWindow") << "terminating headless (no window) app!"; #if defined TARGET_OSX || defined TARGET_LINUX // this doesn't exist on windows and gives linking errors, so commented out. reset_terminal_mode(); #endif OF_EXIT_APP(0); }
int main(int argc, char *argv[]) { set_conio_terminal_mode(); fdFifo = open("./RobotFifo", O_WRONLY); SendCommand("RW:0\r"); bool autoMode = true; char c = 0; int leftPower = 0; int rightPower = 0; int turn = 0; int speed = 0; int prevSpeed = 0; int mode = MODE_MOTOR; while (c != 'q') { while (!kbhit()) { usleep(1000); } c = getch(); if (c == 'q') exit(0); if (c == 'h') { reset_terminal_mode(); printf("\n\nNew heading: "); char hdg[255]; fgets(hdg, 255, stdin); int newHeading = strtol(hdg, 0, 10); char cmd[255]; sprintf(cmd, "H:%d\r", newHeading); SendCommand(cmd); set_conio_terminal_mode(); continue; } if (c == 'c') { reset_terminal_mode(); printf("\n\nCalibrating. Rotate 360 degrees over 10 seconds...\n\n"); char cmd[255]; sprintf(cmd, "CAL:0\r"); SendCommand(cmd); set_conio_terminal_mode(); continue; } if (mode == MODE_MOTOR) { switch (c) { case '+': case '8': speed += 5; autoMode = false; break; case '-': case '2': speed -= 5; autoMode = false; break; case '4': turn -= 5; autoMode = false; break; case '6': turn += 5; autoMode = false; break; case '5': turn = 0; autoMode = false; break; case '0': speed = 0; turn = 0; autoMode = false; break; case 's': mode = MODE_SERVO; break; case 'a': speed = 0; turn = 0; autoMode = true; SendCommand("A:0\r"); break; } if (!autoMode) { if (speed > 255) speed = 255; if (speed < -255) speed = -255; if (turn > 255) turn = 255; if (turn < -255) turn = -255; if (prevSpeed == 0 && speed < 0) { if (speed > -35) speed = -35; } if (prevSpeed == 0 && speed > 0) { if (speed < 35) speed = 35; } if (speed == 0 && turn < 0) { if (turn > -35) turn = -35; } if (speed == 0 && turn > 0) { if (turn < 35) turn = 35; } leftPower = speed - turn; rightPower = speed + turn; prevSpeed = speed; if (leftPower > 255) leftPower = 255; if (leftPower < -255) leftPower = -255; if (rightPower > 255) rightPower = 255; if (rightPower < -255) rightPower = -255; char cmd[256]; sprintf(cmd, "M:%d,%d\r", leftPower, rightPower); SendCommand(cmd); } } else { switch (c) { case '4': panServo += 1; break; case '6': panServo -= 1; break; case '8': tiltServo += 1; break; case '2': tiltServo -= 1; break; case '5': panServo = PAN_CENTER; tiltServo = TILT_CENTER; break; case 'm': mode = MODE_MOTOR; break; case 'a': speed = 0; turn = 0; autoMode = true; SendCommand("A:0\r"); break; } if (panServo > 180) panServo = 180; if (panServo < 0) panServo = 0; if (tiltServo > 180) tiltServo = 180; if (tiltServo < 0) tiltServo = 0; char cmd[256]; sprintf(cmd, "PT:%d,%d\r", panServo, tiltServo); SendCommand(cmd); } } }