int LayoutInput( Layout layout, View *view, int *row, int *column ) { float ix, iy; int event; event = DisplayInput( layout->display, &ix, &iy ); for ( *row = 0; *row < layout->rows; (*row)++ ) { for ( *column = 0; *column < layout->columns; (*column)++ ) { *view = LayoutView( layout, *row, *column ); if ( ViewDisplayPointInside( *view, ix, iy ) ) { return( event ); } } } *view = 0; return( event ); }
int main (void) { uint8_t SequenceNumber = 0; uint8_t Char; int8_t NumberSent = 0, NumberToSend = 0, LoopCount = 0, UnexpectedPacketCount = 0, NoAckCount = 0; InitPinInActive (RED_LED_PIN); InitPinInActive (GREEN_LED_PIN); SerialInit (57600); SendString (UI8_P("JeeNodeRfm12B (1.8 wcb)\r\n")); SendString (UI8_P("a(uto-test), e(nd-test), (r)eset, [n](s)end\r\n")); Radio.Initialize (); while(1) { if ((Char = ReadChar())) switch (Char) { case 'a': if (NumberToSend == -1) break; SendString (UI8_P("Starting auto-test\r\n")); NumberToSend = -1; SequenceNumber = MacLayer.MakeRequestPacket (PacketBfr, 1, 2, UI8_P("123"), 3); SendPacket (PacketBfr, SequenceNumber); LoopCount = UnexpectedPacketCount = NoAckCount = 0; SetPinActive (GREEN_LED_PIN); break; case 'e': if (NumberToSend == 0) break; SendString (UI8_P("Ending auto-test\r\n")); sprintf ((char*) StrBfr, "unexpected # = %d, no_ack # = %d\r\n", UnexpectedPacketCount, NoAckCount); SendString (StrBfr); NumberToSend = 0; break; case 'r': SendString (UI8_P("RESETING!\r\n")); cli(); // irq's off wdt_enable (WDTO_15MS); // watch dog on, 15ms while(1); // loop until watch dog fires case 's': if (NumberToSend <= 0) NumberToSend = 1; SendStringAndInt (UI8_P("Sending "), NumberToSend, UI8_P(" packets\r\n")); NumberSent = -1; while (NumberToSend > ++NumberSent) { SequenceNumber = MacLayer.MakeRequestPacket (PacketBfr, 1, 2, UI8_P("123"), 3); if (0 == SendPacket (PacketBfr, SequenceNumber)) { NumberSent = -1; break; } } if (NumberToSend == NumberSent) { SetPinActive (GREEN_LED_PIN); _delay_ms (100); SetPinInActive (GREEN_LED_PIN); } NumberToSend = 0; break; default : if ((0x30 <= Char) && (Char <= 0x39)) NumberToSend = (NumberToSend * 10) + Char - 0x30; else { sprintf ((char*) StrBfr, "Unexpected input character %c\r\n", Char); SendString (StrBfr); } } if (Radio.Recv (&Input[0]) > 0) { DisplayInput (); if ((Input[PACKET_TYPE_INDEX] == MAC_RESPONSE_PACKET_TYPE) && (Input[PACKET_SEQUENCE_INDEX] == SequenceNumber)) { sprintf ((char*) StrBfr, "Got ack response for %d\r\n", SequenceNumber); SendString (StrBfr); if (NumberToSend < 0) { _delay_ms (100); SequenceNumber = MacLayer.MakeRequestPacket (PacketBfr, 1, 2, UI8_P("123"), 3); SendPacket (PacketBfr, SequenceNumber); SetPinActive (GREEN_LED_PIN); LoopCount = 0; } //Radio.DisplayStatus (); //Radio.ResetStatus(); //NumberSent = 0; } else if (Input[PACKET_TYPE_INDEX] == MAC_REQUEST_PACKET_TYPE) { sprintf ((char*) StrBfr, "Got request packet with sequence %d\r\n", Input[PACKET_SEQUENCE_INDEX]); SendString (StrBfr); SetPinActive (GREEN_LED_PIN); LoopCount = 0; SequenceNumber = Input[PACKET_SEQUENCE_INDEX]; MacLayer.MakeResponsePacket (PacketBfr, 1, 2, SequenceNumber, UI8_P("123"), 3); if (0 == SendPacket (PacketBfr, SequenceNumber)) SendStringAndInt (UI8_P("Could not send response for "), Input[PACKET_SEQUENCE_INDEX], UI8_P("\r\n")); } else { sprintf ((char*) StrBfr, "\r\nGot unexpected packet !!!!!!!!!!!!!!!!!!!!!!\r\n\n"); SendString (StrBfr); UnexpectedPacketCount++; } } _delay_ms (10); LoopCount++; if (LoopCount == 10) SetPinInActive (GREEN_LED_PIN); else if ((NumberToSend < 0) && (LoopCount == 100)) { SendStringAndInt (UI8_P("!!!!!!!!!!!!!!!!!!!!!!! Did not get Ack for "), SequenceNumber, UI8_P(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n")); NoAckCount++; SendPacket (PacketBfr, SequenceNumber); LoopCount = 0; SetPinActive (GREEN_LED_PIN); } //else if (NumberSent > 0) { //Radio.DisplayStatus (); //Radio.ResetStatus(); //NumberSent = 0; //} } }
DisplayConfigPtr DisplayConfigFactory::create(OSVR_ClientContext ctx) { DisplayConfigPtr cfg(new DisplayConfig); try { auto const descriptorString = ctx->getStringParameter("/display"); auto desc = display_schema_1::DisplayDescriptor(descriptorString); cfg->m_viewers.container().emplace_back(Viewer(ctx, HEAD_PATH)); auto &viewer = cfg->m_viewers.container().front(); auto eyesDesc = desc.getEyes(); /// Set up stereo vs mono std::vector<uint8_t> eyeIndices; Eigen::Vector3d offset; if (eyesDesc.size() == 2) { // stereo offset = desc.getIPDMeters() / 2. * Eigen::Vector3d::UnitX(); eyeIndices = {0, 1}; } else { // if (eyesDesc.size() == 1) // mono offset = Eigen::Vector3d::Zero(); eyeIndices = {0}; } /// Handle radial distortion parameters boost::optional<OSVR_RadialDistortionParameters> distort; auto k1 = desc.getDistortion(); if (k1.k1_red != 0 || k1.k1_green != 0 || k1.k1_blue != 0) { OSVR_RadialDistortionParameters params; params.k1.data[0] = k1.k1_red; params.k1.data[1] = k1.k1_green; params.k1.data[2] = k1.k1_blue; distort = params; } /// Compute angular offset about Y of the optical (view) axis util::Angle axisOffset = 0. * util::radians; { auto overlapPct = desc.getOverlapPercent(); if (overlapPct < 1.) { const auto hfov = desc.getHorizontalFOV(); const auto angularOverlap = hfov * overlapPct; axisOffset = (hfov - angularOverlap) / 2.; } } /// Infer the number of display inputs and their association with /// eyes (actually surfaces) based on the descriptor. std::vector<OSVR_DisplayInputCount> displayInputIndices; if (eyesDesc.size() == 2 && display_schema_1::DisplayDescriptor::FULL_SCREEN == desc.getDisplayMode()) { // two eyes, full screen - that means two screens. displayInputIndices = {0, 1}; cfg->m_displayInputs.push_back(DisplayInput( desc.getDisplayWidth(), desc.getDisplayHeight())); cfg->m_displayInputs.push_back(DisplayInput( desc.getDisplayWidth(), desc.getDisplayHeight())); } else { // everything else, assume 1 screen. // Note that it's OK that displayInputIndices.size() >= // eyesDesc.size(), we'll just not end up using the second // entry. displayInputIndices = {0, 0}; cfg->m_displayInputs.push_back(DisplayInput( desc.getDisplayWidth(), desc.getDisplayHeight())); } BOOST_ASSERT_MSG(displayInputIndices.size() >= eyesDesc.size(), "Must have at least as many indices as eyes"); /// Create the actual eye (with implied surface) objects for (auto eye : eyeIndices) { // This little computation turns 0 into -1 and 1 into 1, used as // a coefficient to make the two eyes do opposite things. // Doesn't affect mono, which has a zero offset vector. double offsetFactor = (2. * eye) - 1.; // Set up per-eye distortion parameters, if needed boost::optional<OSVR_RadialDistortionParameters> distortEye( distort); if (distortEye) { distortEye->centerOfProjection.data[0] = eyesDesc[eye].m_CenterProjX; distortEye->centerOfProjection.data[1] = eyesDesc[eye].m_CenterProjY; } // precompute translation offset for this eye auto xlateOffset = (offsetFactor * offset).eval(); // precompute the optical axis rotation for this eye // here, the left eye should get a positive offset since it's a // positive rotation about y, hence the -1 factor. auto eyeAxisOffset = axisOffset * -1. * offsetFactor; // Look up the display index for this eye. auto displayInputIdx = displayInputIndices[eye]; /// Create the ViewerEye[Surface] and add it to the container. viewer.container().emplace_back(ViewerEye( ctx, xlateOffset, HEAD_PATH, computeViewport(eye, desc), computeRect(desc), eyesDesc[eye].m_rotate180, desc.getPitchTilt().value(), distortEye, displayInputIdx, eyeAxisOffset)); } OSVR_DEV_VERBOSE("Display: " << desc.getHumanReadableDescription()); return cfg; } catch (std::exception const &e) { OSVR_DEV_VERBOSE( "Couldn't create a display config internally! Exception: " << e.what()); return DisplayConfigPtr{}; } catch (...) { OSVR_DEV_VERBOSE("Couldn't create a display config internally! " "Unknown exception!"); return DisplayConfigPtr{}; } }