// Given the file descriptor for a serial device, close that device. void CloseSerialPort(int fileDescriptor) { #if 1 // Block until all written output has been sent from the device. // Note that this call is simply passed on to the serial device driver. // See tcsendbreak(3) ("man 3 tcsendbreak") for details. if (tcdrain(fileDescriptor) == -1) { printf("Error waiting for drain - %s(%d).\n", strerror(errno), errno); } // Traditionally it is good practice to reset a serial port back to // the state in which you found it. This is why the original termios struct // was saved. if (tcsetattr(fileDescriptor, TCSANOW, &gOriginalTTYAttrs) == -1) { printf("Error resetting tty attributes - %s(%d).\n", strerror(errno), errno); } #endif KeyCheck(&key_data); // Clean up serial buffer; printf("Clena up uart buffer completed!\n"); close(fileDescriptor); }
unsigned int Read_joypad(void) { unsigned int button=0; if(KeyCheck(&key_data)) { if(key_data & 0x2000) button = BIT_U; //UP if(key_data & 0x1000) button |= BIT_D; //DOWN if(key_data & 0x8000) button |= BIT_L; //LEFT if(key_data & 0x4000) button |= BIT_R; //RIGHT if(key_data & 0x0010) button |= BIT_ST; // START if(key_data & 0x0020) button |= BIT_SEL; // SELECT if(key_data & 0x0040) button |= BIT_RPAD; // TR if(key_data & 0x0080) button |= BIT_LPAD; // TL if(key_data & 0x0400) button |= BIT_PUSH; // Y //if(key_data & 0x0800) button |= BIT_X; // X if(key_data & 0x0200) button |= BIT_A; // 1 - A if(key_data & 0x0100) button |= BIT_B; // 2 - B old_button=button; //printf("%02x %02x\n",(key_data&0xff00)>>8, key_data&0xff); } return old_button; }
void CKeyMgr::ProcessingSequence() { /* 1. 테이블을 바꾼다 2. 현재 테이블을 모두 KS_None으로 세팅 3. KeyCheck를 통해 눌린 상태를 조사한다 */ swapTable(); memset(curr_KeyTable, KS_None, sizeof(curr_KeyTable)); KeyCheck(); }
//#define BUFSIZE 100 //char readbuf[BUFSIZE]; int Init_joypad(void) { // kern_return_t kernResult; // on PowerPC this is an int (4 bytes) /* * error number layout as follows (see mach/error.h): * * hi lo * | system(6) | subsystem(12) | code(14) | */ // io_iterator_t serialPortIterator; char bsdPath[MAXPATHLEN]="/dev/tty.iap"; /* kernResult = FindModems(&serialPortIterator); kernResult = GetModemPath(serialPortIterator, bsdPath, sizeof(bsdPath)); IOObjectRelease(serialPortIterator); // Release the iterator. */ // Now open the modem port we found, initialize the modem, then close it if (!bsdPath[0]) { printf("No modem port found.\n"); return EX_UNAVAILABLE; } fileDescriptor = OpenSerialPort(bsdPath); if (-1 == fileDescriptor) { return EX_IOERR; } /* if (InitializeModem(fileDescriptor)) { printf("Modem initialized successfully.\n"); } else { printf("Could not initialize modem.\n"); } */ printf("Clena up uart buffer!\n"); KeyCheck(&key_data); // Clean up serial buffer; key_data=0; printf("Joynux init OK.!\n"); return EX_OK; }
void update(float time) { KeyCheck(); switch(STATE) { case stay: anim.set("stay"); break; case walk: anim.set("walk"); break; case jump: anim.set("jump"); break; case duck: anim.set("duck"); break; case climb: anim.set("climb"); anim.pause(); if(dy != 0) anim.play(); if(!onLadder) STATE = stay; break; } /*if (STATE == stay) anim.set("stay"); if (STATE==walk) anim.set("walk"); if (STATE==jump) anim.set("jump"); if (STATE==duck) anim.set("duck"); if (STATE==climb) {anim.set("climb"); anim.pause(); if (dy!=0) anim.play(); if (!onLadder) STATE=stay;} */ if (shoot) { switch(STATE) { case stay: anim.set("shoot"); break; case walk: anim.set("walking_attack"); break; case jump: anim.set("jumping_attack"); break; case duck: anim.set("ducking_attack"); break; case climb: anim.set("climbing_attack"); break; } /*if (STATE==jump) anim.set("jumping_attack"); if (STATE==duck) anim.set("ducking_attack"); if (STATE==climb) anim.set("climbing_attack"); if (STATE==walk) anim.set("walking_attack"); if (STATE==stay) anim.set("shoot"); */ } if(hit) { timer += time; if(timer > 1000) { hit = false; timer = 0; } //anim.set("hit"); } if(dir) anim.flip(); if((offsetX - x) < -260) { // если пытаемся выбежать вперед за правую границу экрана - нас отбрасывает назад x = offsetX + 260; } if((offsetX - x) > 300) { //если тупим и не успеваем, то нас выталкивает вперед и придает скорости x = offsetX - 300; dx = 0.3; } x += dx * time; Collision(0); //мы оказались за пределом экрана до этого и теперь dx>0, а так же Collision отбросила нас обратно за пределы if (((offsetX - x) > 300) && (dx > 0)) { // если после всего мы по прежнему за пределом экрана, то нас "прищемляет" Health -= 50; //screen_speed = 0; x = offsetX - 300; } if (STATE != climb) dy += 0.0005*time; y += dy*time; onLadder = false; Collision(1); anim.tick(time); key["R"] = key["L"] = key["Up"] = key["Down"] = key["Space"] = false; }
bool GGameMenu::Frame() { //if (g_pMain->m_nGameBeforePhase != g_pMain->m_nGamePhase) { // g_pMain->m_pSound.Play(SND_INTRO, true); // g_pMain->m_nGameBeforePhase = g_pMain->m_nGamePhase; //} SoundPlay(); KeyCheck(); /*GControlUI* pSelect = SelectRect(); if (pSelect != NULL && m_pSelectPlane != pSelect) { m_pSelectPlane = pSelect; } if (m_pSelectPlane) { D3DXVECTOR3 vPos(0, 0, 0); D3DXVECTOR3 vScale(0, 0, 0); if (g_InputData.bQKey) { vScale.x += 50 * g_fSecPerFrame; } if (g_InputData.bEKey) { vScale.x += -50 * g_fSecPerFrame; } if (g_InputData.bZKey) { vScale.y += 50 * g_fSecPerFrame; } if (g_InputData.bCKey) { vScale.y += -50 * g_fSecPerFrame; } if (g_InputData.bWKey) { vPos.y = 50 * g_fSecPerFrame; } if (g_InputData.bSKey) { vPos.y = -50 * g_fSecPerFrame; } if (g_InputData.bAKey) { vPos.x = -50 * g_fSecPerFrame; } if (g_InputData.bDKey) { vPos.x = 50 * g_fSecPerFrame; } m_pSelectPlane->Move(vPos.x, vPos.y, vPos.z); m_pSelectPlane->Scale(vScale.x, vScale.y, vScale.z); }*/ for (int iPlane = 0; iPlane < m_pUIList.size(); iPlane++) { GControlUI* pRect = m_pUIList[iPlane]; pRect->Update(); } return true; }