@@ -683,9 +683,9 @@ void Freenect2DeviceImpl::start()
683683 command_tx_.execute (ReadFirmwareVersionsCommand (nextCommandSeq ()), firmware_result);
684684 firmware_ = FirmwareVersionResponse (firmware_result.data , firmware_result.length ).toString ();
685685
686- command_tx_.execute (ReadData0x14Command (nextCommandSeq ()), result);
687- LOG_DEBUG << " ReadData0x14 response " ;
688- LOG_DEBUG << GenericResponse (result. data , result. length ). toString ();
686+ command_tx_.execute (ReadHardwareInfoCommand (nextCommandSeq ()), result);
687+ // The hardware version is currently useless. It is only used to select the
688+ // IR normalization table, but we don't have that.
689689
690690 command_tx_.execute (ReadSerialNumberCommand (nextCommandSeq ()), serial_result);
691691 std::string new_serial = SerialNumberResponse (serial_result.data , serial_result.length ).toString ();
@@ -749,17 +749,28 @@ void Freenect2DeviceImpl::start()
749749 rgb_camera_params_.my_x0y0 = rgb_p->my_x0y0 ; // 1
750750 setColorCameraParams (rgb_camera_params_);
751751
752- command_tx_.execute (ReadStatus0x090000Command (nextCommandSeq ()), result);
753- LOG_DEBUG << " ReadStatus0x090000 response" ;
754- LOG_DEBUG << GenericResponse (result.data , result.length ).toString ();
752+ command_tx_.execute (SetModeEnabledWith0x00640064Command (nextCommandSeq ()), result);
753+ command_tx_.execute (SetModeDisabledCommand (nextCommandSeq ()), result);
754+
755+ for (uint32_t status = 0 , last = 0 ; (status & 1 ) == 0 ; last = status)
756+ {
757+ command_tx_.execute (ReadStatus0x090000Command (nextCommandSeq ()), result);
758+ if (result.length < sizeof (uint32_t ))
759+ continue ; // TODO should report error
760+ status = *reinterpret_cast <const uint32_t *>(result.data );
761+ if (status != last)
762+ LOG_DEBUG << " status 0x090000: " << status;
763+ if ((status & 1 ) == 0 )
764+ this_thread::sleep_for (chrono::milliseconds (100 ));
765+ }
755766
756767 command_tx_.execute (InitStreamsCommand (nextCommandSeq ()), result);
757768
758769 usb_control_.setIrInterfaceState (UsbControl::Enabled);
759770
760771 command_tx_.execute (ReadStatus0x090000Command (nextCommandSeq ()), result);
761- LOG_DEBUG << " ReadStatus0x090000 response " ;
762- LOG_DEBUG << GenericResponse (result.data , result. length ). toString ( );
772+ if (result. length >= sizeof ( uint32_t ))
773+ LOG_DEBUG << " status 0x090000: " << * reinterpret_cast < const uint32_t *> (result.data );
763774
764775 command_tx_.execute (SetStreamEnabledCommand (nextCommandSeq ()), result);
765776
@@ -813,8 +824,14 @@ void Freenect2DeviceImpl::stop()
813824 usb_control_.setIrInterfaceState (UsbControl::Disabled);
814825
815826 CommandTransaction::Result result;
816- command_tx_.execute (Unknown0x0ACommand (nextCommandSeq ()), result);
827+ command_tx_.execute (SetModeEnabledWith0x00640064Command (nextCommandSeq ()), result);
828+ command_tx_.execute (SetModeDisabledCommand (nextCommandSeq ()), result);
829+ command_tx_.execute (StopCommand (nextCommandSeq ()), result);
817830 command_tx_.execute (SetStreamDisabledCommand (nextCommandSeq ()), result);
831+ command_tx_.execute (SetModeEnabledCommand (nextCommandSeq ()), result);
832+ command_tx_.execute (SetModeDisabledCommand (nextCommandSeq ()), result);
833+ command_tx_.execute (SetModeEnabledCommand (nextCommandSeq ()), result);
834+ command_tx_.execute (SetModeDisabledCommand (nextCommandSeq ()), result);
818835
819836 usb_control_.setVideoTransferFunctionState (UsbControl::Disabled);
820837
@@ -837,6 +854,11 @@ void Freenect2DeviceImpl::close()
837854 stop ();
838855 }
839856
857+ CommandTransaction::Result result;
858+ command_tx_.execute (SetModeEnabledWith0x00640064Command (nextCommandSeq ()), result);
859+ command_tx_.execute (SetModeDisabledCommand (nextCommandSeq ()), result);
860+ command_tx_.execute (ShutdownCommand (nextCommandSeq ()), result);
861+
840862 if (pipeline_->getRgbPacketProcessor () != 0 )
841863 pipeline_->getRgbPacketProcessor ()->setFrameListener (0 );
842864
0 commit comments