/* *------------------------------------------------------------------------------ * void APP-task(void) *------------------------------------------------------------------------------ */ void APP_task(void) { UINT8 i,*ptr, data; UINT32 addr; UINT8 resetBuzzer = TRUE; ias.curAppTime = GetAppTime(); //Fetches the application time from timer driver if(ias.preAppTime != ias.curAppTime) { ias.preAppTime = ias.curAppTime; for(i = 0; i <MAX_ISSUES; i++) //check for timeout of issues raised { if(ias.issues[i].state == ISSUE_RAISED ) { ias.issues[i].timeout -= 1; ptr = (UINT8*)&ias.issues[i].timeout; data = *ptr; addr = (i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT, *ptr); Busy_eep(); ClrWdt(); data=*(ptr+1); addr = (i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT+1; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT+1, *(ptr+1)); Busy_eep(); ClrWdt(); } } if(update_timeouts() == TRUE) { LAMP_RED = 1; if( ias.issues_raised == 0 ) { LAMP_YELLOW = 0; LAMP_GREEN = 0; } } if(ias.updateCount >= 5) { ias.updateCount = 0; update(); } } ++ias.updateCount; }
void COM_task() { volatile UINT8 uartData = 0,i; communication.curAppTime = GetAppTime(); if(RCSTA1bits.OERR == 1) { RCSTA1bits.CREN = 0; Delay10us(1); RCSTA1bits.CREN = 1; } if( communication.prevAppTime != communication.curAppTime) { if( communication.prevState == communication.state && (communication.state == COM_IN_PACKET_COLLECTION)) { --communication.timeout ; if( communication.timeout == 0) { //COM_txStr("RESTART"); COM_restart(); return; } } communication.prevAppTime = communication.curAppTime; } switch( communication.state) { case COM_START: #if(defined __18F8722_H) ||(defined __18F46K22_H) if( UART1_hasData() == FALSE ) return; uartData = UART1_read(); #else if( UART1_hasData() == FALSE ) return; uartData = UART_read(); #endif if( uartData == communication.rx_sop ) { communication.rxPacketIndex = 0; communication.state = COM_IN_PACKET_COLLECTION; communication.timeout = TIMEOUT; } break; case COM_IN_PACKET_COLLECTION: #if(defined __18F8722_H) ||(defined __18F46K22_H) if( UART1_hasData()==FALSE ) return; uartData = UART1_read(); #else if( UART_hasData()==FALSE ) return; uartData = UART_read(); #endif if(uartData == communication.rx_eop ) { UINT8 parseResult = 0; COM_RESP_CODE txCode = COM_RESP_NONE; UINT8 *txData ; parseResult = parsePacket(&txCode); //parse packet switch( parseResult) { case IGNORE: COM_reset(); return; case PARSE_SUCCESS: if( communication.callBack != 0 ) { communication.txPacketLength = communication.callBack(&communication.rxPacketBuffer[COM_RX_DATA_START_INDEX], &communication.txCode, &txData); communication.txPacketBuffer[COM_DEVICE_ADDRESS_INDEX] = BROADCAST_ADDRESS; //store BROADCAST_ADDRESS ++communication.txPacketLength; communication.txPacketBuffer[COM_TX_CODE_INDEX] = communication.txCode; //store tx code ++communication.txPacketLength; for( i = COM_TX_DATA_START_INDEX ; i < communication.txPacketLength ; i++) //store data { communication.txPacketBuffer[i] = *txData; txData++; } } else { COM_reset(); } break; case PARSE_FAILURE: { communication.txPacketBuffer[COM_DEVICE_ADDRESS_INDEX] = DEVICE_ADDRESS; //store device address ++communication.txPacketLength; communication.txPacketBuffer[COM_TX_CODE_INDEX] = communication.txCode; //store tx code ++communication.txPacketLength; } break; default: break; } communication.state = COM_IN_TX_DATA; } else { communication.rxPacketBuffer[communication.rxPacketIndex++]=uartData; if( communication.rxPacketIndex >= RX_PACKET_SIZE) { communication.txPacketBuffer[COM_DEVICE_ADDRESS_INDEX] = DEVICE_ADDRESS; //store device address ++communication.txPacketLength; communication.txPacketBuffer[COM_TX_CODE_INDEX] = COM_RESP_OVERRUN; //store tx code ++communication.txPacketLength; communication.state = COM_IN_TX_DATA; } } break; case COM_IN_TX_DATA: COM_txData(); COM_reset(); break; default: COM_reset(); break; } communication.prevState = communication.state; }
/* *------------------------------------------------------------------------------ * void APP-task(void) *------------------------------------------------------------------------------ */ void APP_task(void) { UINT8 i,*ptr, data; UINT32 addr; UINT8 resetBuzzer = TRUE; ias.curAppTime = GetAppTime(); //Fetches the application time from timer driver if(ias.preAppTime != ias.curAppTime) { ias.preAppTime = ias.curAppTime; for(i = 0; i <MAX_ISSUES; i++) //check for timeout of issues raised { if(ias.issues[i].state == ISSUE_RAISED ) { ias.issues[i].timeout -= 1; ptr = (UINT8*)&ias.issues[i].timeout; data = *ptr; addr = (i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT, *ptr); Busy_eep(); ClrWdt(); data=*(ptr+1); addr = (i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT+1; Write_b_eep((i*ISSUE_ENTRY_SIZE)+ISSUE_TIMEOUT+1, *(ptr+1)); Busy_eep(); ClrWdt(); } } for(i = 1; i <= 4 ; i++) { switch(i) { case 1: if(ias.department_raised[i] > 0 ) LAMP_GREEN = 1; else LAMP_GREEN = 0; break; case 2: if(ias.department_raised[i] > 0 ) LAMP_YELLOW = 1; else LAMP_YELLOW = 0; break; case 3: if(ias.department_raised[i] > 0 ) LAMP_RED = 1; else LAMP_RED = 0; break; case 4: if ((ias.department_raised[i] > 0 ) || (ias.department_raised[i+1] > 0 ) || (ias.department_raised[i+2] > 0 ) ) LAMP_BLUE = 1; else LAMP_BLUE = 0; break; default: break; } } } }
void APP_task( void ) { UINT8 i; switch(app.state) { case HALT_STATE: if (LinearKeyPad_getPBState(COUNT_PB) == KEY_PRESSED) { ResetAppTime(); app.state = COUNT_STATE; } if (LinearKeyPad_getPBState(MILDSTONE1_PB) == KEY_PRESSED) { //Reset Target buffer which is used to hold preset data APP_resetBuffer1(); //Blink first digit in the display app.blinkIndex = 0; DigitDisplay_updateBuffer(app.mildstone1); DigitDisplay_blinkOn_ind(500, app.blinkIndex); GREEN_LAMP = RESET; RED_LAMP = RESET; app.mildstone1Flag = TRUE; //Change state to setting state app.state = SETTING_STATE; } //Check the keypress Status of HOOTER_OFF_PB if(LinearKeyPad_getPBState(MILDSTONE2_PB) == KEY_PRESSED) { //Reset Target buffer which is used to hold preset data APP_resetBuffer2(); //Blink first digit in the display app.blinkIndex = 0; DigitDisplay_updateBuffer(app.mildstone2); DigitDisplay_blinkOn_ind(500, app.blinkIndex); GREEN_LAMP = RESET; RED_LAMP = RESET; app.mildstone2Flag = TRUE; //Change state to setting state app.state = SETTING_STATE; } break; case SETTING_STATE: // Code to handle Digit index PB if (LinearKeyPad_getPBState(DIGIT_INDEX_PB ) == KEY_PRESSED) { app.blinkIndex++; if(app.blinkIndex > (NO_OF_DIGITS - 1)) app.blinkIndex = 0 ; DigitDisplay_blinkOn_ind(500, app.blinkIndex); } // Code to handle increment PB if (LinearKeyPad_getPBState(INCREMENT_PB) == KEY_PRESSED) { if( app.mildstone1Flag == TRUE ) { app.mildstone1[app.blinkIndex]++; if(app.mildstone1[app.blinkIndex] > max[app.blinkIndex]) app.mildstone1[app.blinkIndex] = '0'; DigitDisplay_updateBuffer(app.mildstone1); } if( app.mildstone2Flag == TRUE) { app.mildstone2[app.blinkIndex]++; if(app.mildstone2[app.blinkIndex] > max[app.blinkIndex]) app.mildstone2[app.blinkIndex] = '0'; DigitDisplay_updateBuffer(app.mildstone2); } } if ((LinearKeyPad_getPBState(MILDSTONE1_PB) == KEY_PRESSED) && (app.mildstone1Flag == TRUE)) { app.mildstone1Flag = FALSE; //Turn of blink DigitDisplay_blinkOff(); //Display the preset value on the display DigitDisplay_updateBuffer(app.mildstone1); //Store preset value in the EEPROM for(i = 0; i < NO_OF_DIGITS ; i++ ) { Write_b_eep( EEPROM_MILDSTONE1_ADDRESS + i ,app.mildstone1[i] ); Busy_eep( ); } app.mildstone1Value = (UINT16)(((app.mildstone1[3]- '0' )* 10 )+ ( app.mildstone1[2] - '0') )* 60 +(((app.mildstone1[1]- '0' )* 10 )+ (app.mildstone1[0] - '0')); app.state = HALT_STATE; } if ((LinearKeyPad_getPBState(MILDSTONE2_PB) == KEY_PRESSED) && (app.mildstone2Flag == TRUE)) { app.mildstone2Flag = FALSE; //Turn of blink DigitDisplay_blinkOff(); //Display the preset value on the display DigitDisplay_updateBuffer(app.mildstone2); //Store preset value in the EEPROM for(i = 0; i < NO_OF_DIGITS ; i++ ) { Write_b_eep( EEPROM_MILDSTONE2_ADDRESS + i ,app.mildstone2[i] ); Busy_eep( ); } app.mildstone2Value = (UINT16)(((app.mildstone2[3]- '0' )* 10 )+ ( app.mildstone2[2] - '0') )* 60 +(((app.mildstone2[1]- '0' )* 10 )+ (app.mildstone2[0] - '0')); app.state = HALT_STATE; } break; case COUNT_STATE: if (LinearKeyPad_getPBState(HALT_PB) == KEY_PRESSED) { APP_resetDisplayBuffer(); DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4); GREEN_LAMP = RESET; RED_LAMP = RESET; app.state = HALT_STATE; break; } app.currentTime = GetAppTime(); if(app.currentTime < 6000) { APP_conversion(); DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4); } else { APP_resetDisplayBuffer(); DigitDisplay_updateBufferPartial(app.displayBuffer , 0, 4); app.state = HALT_STATE; break; } if( (app.currentTime >= app.mildstone1Value ) && (app.currentTime < app.mildstone2Value) ) { GREEN_LAMP = SET; } else if (app.currentTime >= app.mildstone2Value) { GREEN_LAMP = RESET; RED_LAMP = SET; } break; } }
int OculusRoomTinyApp::OnStartup(const char* args) { OVR_UNUSED(args); // *** Oculus HMD & Sensor Initialization // Create DeviceManager and first available HMDDevice from it. // Sensor object is created from the HMD, to ensure that it is on the // correct device. pManager = *DeviceManager::Create(); // We'll handle it's messages in this case. pManager->SetMessageHandler(this); int detectionResult = IDCONTINUE; const char* detectionMessage; do { // Release Sensor/HMD in case this is a retry. pSensor.Clear(); pHMD.Clear(); RenderParams.MonitorName.Clear(); pHMD = *pManager->EnumerateDevices<HMDDevice>().CreateDevice(); if (pHMD) { pSensor = *pHMD->GetSensor(); // This will initialize HMDInfo with information about configured IPD, // screen size and other variables needed for correct projection. // We pass HMD DisplayDeviceName into the renderer to select the // correct monitor in full-screen mode. if (pHMD->GetDeviceInfo(&HMDInfo)) { RenderParams.MonitorName = HMDInfo.DisplayDeviceName; RenderParams.DisplayId = HMDInfo.DisplayId; SConfig.SetHMDInfo(HMDInfo); } } else { // If we didn't detect an HMD, try to create the sensor directly. // This is useful for debugging sensor interaction; it is not needed in // a shipping app. pSensor = *pManager->EnumerateDevices<SensorDevice>().CreateDevice(); } // If there was a problem detecting the Rift, display appropriate message. detectionResult = IDCONTINUE; if (!pHMD && !pSensor) detectionMessage = "Oculus Rift not detected."; else if (!pHMD) detectionMessage = "Oculus Sensor detected; HMD Display not detected."; else if (!pSensor) detectionMessage = "Oculus HMD Display detected; Sensor not detected."; else if (HMDInfo.DisplayDeviceName[0] == '\0') detectionMessage = "Oculus Sensor detected; HMD display EDID not detected."; else detectionMessage = 0; if (detectionMessage) { String messageText(detectionMessage); messageText += "\n\n" "Press 'Try Again' to run retry detection.\n" "Press 'Continue' to run full-screen anyway."; detectionResult = ::MessageBoxA(0, messageText.ToCStr(), "Oculus Rift Detection", MB_CANCELTRYCONTINUE|MB_ICONWARNING); if (detectionResult == IDCANCEL) return 1; } } while (detectionResult != IDCONTINUE); if (HMDInfo.HResolution > 0) { Width = HMDInfo.HResolution; Height = HMDInfo.VResolution; } if (!setupWindow()) return 1; if (pSensor) { // We need to attach sensor to SensorFusion object for it to receive // body frame messages and update orientation. SFusion.GetOrientation() // is used in OnIdle() to orient the view. SFusion.AttachToSensor(pSensor); SFusion.SetDelegateMessageHandler(this); } // *** Initialize Rendering // Enable multi-sampling by default. RenderParams.Multisample = 4; RenderParams.Fullscreen = true; // Setup Graphics. pRender = *RenderTiny::D3D10::RenderDevice::CreateDevice(RenderParams, (void*)hWnd); if (!pRender) return 1; // *** Configure Stereo settings. SConfig.SetFullViewport(Viewport(0,0, Width, Height)); SConfig.SetStereoMode(Stereo_LeftRight_Multipass); // Configure proper Distortion Fit. // For 7" screen, fit to touch left side of the view, leaving a bit of invisible // screen on the top (saves on rendering cost). // For smaller screens (5.5"), fit to the top. if (HMDInfo.HScreenSize > 0.0f) { if (HMDInfo.HScreenSize > 0.140f) // 7" SConfig.SetDistortionFitPointVP(-1.0f, 0.0f); else SConfig.SetDistortionFitPointVP(0.0f, 1.0f); } pRender->SetSceneRenderScale(SConfig.GetDistortionScale()); SConfig.Set2DAreaFov(DegreeToRad(85.0f)); // *** Populate Room Scene // This creates lights and models. PopulateRoomScene(&Scene, pRender); LastUpdate = GetAppTime(); return 0; }
void OculusRoomTinyApp::OnIdle() { double curtime = GetAppTime(); float dt = float(curtime - LastUpdate); LastUpdate = curtime; // Handle Sensor motion. // We extract Yaw, Pitch, Roll instead of directly using the orientation // to allow "additional" yaw manipulation with mouse/controller. if (pSensor) { Quatf hmdOrient = SFusion.GetOrientation(); float yaw = 0.0f; hmdOrient.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &EyePitch, &EyeRoll); EyeYaw += (yaw - LastSensorYaw); LastSensorYaw = yaw; } // Gamepad rotation. EyeYaw -= GamepadRotate.x * dt; if (!pSensor) { // Allow gamepad to look up/down, but only if there is no Rift sensor. EyePitch -= GamepadRotate.y * dt; const float maxPitch = ((3.1415f/2)*0.98f); if (EyePitch > maxPitch) EyePitch = maxPitch; if (EyePitch < -maxPitch) EyePitch = -maxPitch; } // Handle keyboard movement. // This translates EyePos based on Yaw vector direction and keys pressed. // Note that Pitch and Roll do not affect movement (they only affect view). if (MoveForward || MoveBack || MoveLeft || MoveRight) { Vector3f localMoveVector(0,0,0); Matrix4f yawRotate = Matrix4f::RotationY(EyeYaw); if (MoveForward) localMoveVector = ForwardVector; else if (MoveBack) localMoveVector = -ForwardVector; if (MoveRight) localMoveVector += RightVector; else if (MoveLeft) localMoveVector -= RightVector; // Normalize vector so we don't move faster diagonally. localMoveVector.Normalize(); Vector3f orientationVector = yawRotate.Transform(localMoveVector); orientationVector *= MoveSpeed * dt * (ShiftDown ? 3.0f : 1.0f); EyePos += orientationVector; } else if (GamepadMove.LengthSq() > 0) { Matrix4f yawRotate = Matrix4f::RotationY(EyeYaw); Vector3f orientationVector = yawRotate.Transform(GamepadMove); orientationVector *= MoveSpeed * dt; EyePos += orientationVector; } // Rotate and position View Camera, using YawPitchRoll in BodyFrame coordinates. // Matrix4f rollPitchYaw = Matrix4f::RotationY(EyeYaw) * Matrix4f::RotationX(EyePitch) * Matrix4f::RotationZ(EyeRoll); Vector3f up = rollPitchYaw.Transform(UpVector); Vector3f forward = rollPitchYaw.Transform(ForwardVector); // Minimal head modelling. float headBaseToEyeHeight = 0.15f; // Vertical height of eye from base of head float headBaseToEyeProtrusion = 0.09f; // Distance forward of eye from base of head Vector3f eyeCenterInHeadFrame(0.0f, headBaseToEyeHeight, -headBaseToEyeProtrusion); Vector3f shiftedEyePos = EyePos + rollPitchYaw.Transform(eyeCenterInHeadFrame); shiftedEyePos.y -= eyeCenterInHeadFrame.y; // Bring the head back down to original height View = Matrix4f::LookAtRH(shiftedEyePos, shiftedEyePos + forward, up); // This is what transformation would be without head modeling. // View = Matrix4f::LookAtRH(EyePos, EyePos + forward, up); switch(SConfig.GetStereoMode()) { case Stereo_None: Render(SConfig.GetEyeRenderParams(StereoEye_Center)); break; case Stereo_LeftRight_Multipass: Render(SConfig.GetEyeRenderParams(StereoEye_Left)); Render(SConfig.GetEyeRenderParams(StereoEye_Right)); break; } pRender->Present(); // Force GPU to flush the scene, resulting in the lowest possible latency. pRender->ForceFlushGPU(); }
void COM1_task(void) { volatile UINT8 uartData = 0,i; communication[0].curAppTime = GetAppTime(); if(RCSTA1bits.OERR == 1) { RCSTA1bits.CREN = 0; Delay10us(1); RCSTA1bits.CREN = 1; } #ifdef UART2_ACTIVE if(RCSTA2bits.OERR == 1) { RCSTA2bits.CREN = 0; Delay10us(1); RCSTA2bits.CREN = 1; } #endif for(i = 0 ; i < ACTIVE_USARTS ; i++ ) { if( communication[i].prevAppTime != communication[i].curAppTime) { if( communication[i].prevState == communication[i].state && (communication[i].state == COM_IN_PACKET_COLLECTION)) { --communication[i].timeout ; if( communication[i].timeout == 0) { COM1_restart(); return; } } communication[i].prevAppTime = communication[i].curAppTime; } switch( communication[i].state) { case COM_START: if( i == UART1) { if( UART1_hasData() == FALSE ) return; uartData = UART1_read(); #ifdef PASS_THROUGH UART2_write(uartData); UART2_transmit(); #endif } else if( i == UART2) { if( UART2_hasData() == FALSE ) return; uartData = UART2_read(); } if( uartData == communication[i].rx_sop ) { communication[i].rxPacketIndex = 0; communication[i].state = COM_IN_PACKET_COLLECTION; } break; case COM_IN_PACKET_COLLECTION: if( i == UART1) { if( UART1_hasData() == FALSE ) return; uartData = UART1_read(); #ifdef PASS_THROUGH UART2_write(uartData); UART2_transmit(); #endif } else if( i == UART2) { if( UART2_hasData() == FALSE ) return; uartData = UART2_read(); } if(uartData == communication[i].rx_eop ) { UINT8 parseResult = 0; COM_RESP_CODE txCode = COM_RESP_NONE; UINT8 *txData ; #ifdef __NO_CHECKSUM__ parseResult = PARSE_SUCCESS; #else parseResult = parse1Packet((&txCode), i); //parse packet #endif switch( parseResult) { case IGNORE: COM1_reset(); return; case PARSE_SUCCESS: if( communication[i].callBack != 0 ) { communication[i].txPacketLength = communication[i].callBack(&communication[i].rxPacketBuffer[COM_RX_DATA_START_INDEX], &communication[i].txCode, &txData); if(communication[i].txCode == COM_RESP_NONE ) { COM1_reset(); return; } communication[i].txPacketBuffer[COM_DEVICE_ADDRESS_INDEX] = DEVICE_ADDRESS; //store device address ++communication[i].txPacketLength; communication[i].txPacketBuffer[COM_TX_CODE_INDEX] = communication[i].txCode; //store tx code ++communication[i].txPacketLength; for( i = COM_TX_DATA_START_INDEX ; i < communication[i].txPacketLength ; i++) //store data { communication[i].txPacketBuffer[i] = *txData; txData++; } } else { COM1_reset(); } break; case PARSE_FAILURE: { communication[i].txPacketBuffer[COM_DEVICE_ADDRESS_INDEX] = DEVICE_ADDRESS; //store device address ++communication[i].txPacketLength; communication[i].txPacketBuffer[COM_TX_CODE_INDEX] = txCode; //store tx code ++communication[i].txPacketLength; } break; default: break; } communication[i].state = COM_IN_TX_DATA; } else { communication[i].rxPacketBuffer[communication[0].rxPacketIndex++]=uartData; communication[i].timeout = 0; if( communication[i].rxPacketIndex >= RX_PACKET_SIZE) { communication[i].txPacketBuffer[COM_DEVICE_ADDRESS_INDEX] = DEVICE_ADDRESS; //store device address ++communication[i].txPacketLength; communication[i].txPacketBuffer[COM_TX_CODE_INDEX] = COM_RESP_OVERRUN; //store tx code ++communication[i].txPacketLength; communication[i].state = COM_IN_TX_DATA; } } break; case COM_IN_TX_DATA: COM_txData(); COM1_reset(); break; default: COM1_reset(); break; } communication[i].prevState = communication[i].state; } }