User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:sub2r-lib [2022/08/30 18:42] – [byte_span] Igor Yefmovcode:sub2r-lib [2022/09/10 20:39] (current) – [Basic "vendor request" call] Igor Yefmov
Line 11: Line 11:
  
 ===== Basic "vendor request" call ===== ===== Basic "vendor request" call =====
 +
 +SUB2r API calls are implemented as USB "vendor request" commands, where ''USB_SETUP_PACKET::bmRequest::Type'' is set to ''2'', following the USB specification.
  
 Sample usage: Sample usage:
Line 19: Line 21:
     array<std::byte, 4> vi{};     array<std::byte, 4> vi{};
     const auto rc{m_fx3.vrCmd(Fx3Cmd::fx3_version // vendor request command     const auto rc{m_fx3.vrCmd(Fx3Cmd::fx3_version // vendor request command
-                              , VrCmdOpType::read // read from device +                            , VrCmdOpType::read   // read from device 
-                              , 0                 // "value" +                            , 0                   // "value" 
-                              , 0                 // "index" +                            , 0                   // "index" 
-                              , vi)};             // buffer to read into+                            , vi)};               // buffer to read into
     return vi;                                    // 32 bits of the "version info" (4 bytes)     return vi;                                    // 32 bits of the "version info" (4 bytes)
 } }
Line 357: Line 359:
 | <code c++>m_rollingbar</code> | enable/disable a rolling bar, only valid when ''m_mode == color_bar'' | | <code c++>m_rollingbar</code> | enable/disable a rolling bar, only valid when ''m_mode == color_bar'' |
 | <code c++>m_enabled</code> | enable/disable the test pattern mode | | <code c++>m_enabled</code> | enable/disable the test pattern mode |
- 
- 
-==== UFix_8_8 ==== 
-{{ :code:class-ufix_8_8.png?nolink|Class diagram - UFix_8_8}} 
- 
-A helper class for working with a 2-byte floating number format used to specify fractional parameters for the FX3. More details are available in  [[code:numberformats#ufix_88|UFIX 8.8 documentation]]. 
- 
-^ Method ^ Signature ^ Functionality ^ 
-| ''constructor'' | <code c++>constexpr 
-  UFix_8_8( 
-      uint8_t _i 
-    , uint8_t _f = 0 
-    ) noexcept</code> | construct a number from provided integer (''_i'') and fractional (''_f'') parts, for example: <code c++>auto uf88{1, 128}; // uf88 is now 1.5</code>No validation is performed to make sure the ''_f'' is in range [''0''..''255''] | 
-| ''constructor'' | <code c++>constexpr 
-  UFix_8_8(double _d) 
-    noexcept;</code> | construct from a floating-point number, i.e.: <code c++>auto uf88{1.2};</code> | 
-| ''constructor'' | <code c++>UFix_8_8( 
-    gsl::span<const std::byte> _buf 
-    ) noexcept;</code> | use this constructor when you read a 2-byte ''UFix_8_8'' value from FX3 | 
-| ''operator double'' | <code c++>constexpr 
-  operator double() const 
-    noexcept;</code> | a type conversion into a floating-point number | 
-| ''operator uint16_t'' | <code c++>constexpr 
-  operator uint16_t() const 
-    noexcept;</code> | make 2 bytes that are ready to be written to FX3, for example:<code c++>// omitting all the error checks!!! 
-uint8_t valI{1}, valF{128}; 
-auto val{S2R::UFix_8_8(valI, valF)}; 
-S2R::I2C dev; 
-// a port to set the image adjustment auto- 
-// functions' update interval 
-constexpr uint8_t port{0xDF}; 
-dev.vrCmd(port, S2R::FX3::write, val, 0); 
-</code> | 
  
  
Line 408: Line 377:
     using namespace S2R;     using namespace S2R;
  
-    cout << "SUB2r-lib sample #1: basic functionality" << endl << endl;+    cout << "SUB2r-lib sample #1: basic functionality\n\n";
  
-    I2C dev; +    const auto numDevs{ImgSensor::deviceCount()}
-    const auto numDevs = dev.deviceCount(); +    cout << "Cypress devices attached to this system: " << static_cast<int>(numDevs) << "\n\n"; 
-    cout << "Cypress devices attached to this system: " << static_cast<int>(numDevs) << endl << endl+    ImgSensor dev(false)
-    for(uint8_t i = 0; i < numDevs; ++i){ +    for(uint8_t i{}; i < numDevs; ++i){ 
-        auto GAIN_R = IImgSensor::Value::gain_r;+        auto GAIN_R{IImgSensorChip::Value::gain_r};
         cout << "Opening device #" << static_cast<int>(i) << "... ";         cout << "Opening device #" << static_cast<int>(i) << "... ";
         if(dev.open(i)){         if(dev.open(i)){
-            wcout << L"success.\nDevice name is: " << dev[FX3::PropWString::friendly_name].c_str() << endl+            wcout << L"success.\nDevice name is: " << dev[FX3::PropWString::friendly_name].c_str() << "\n"
-            cout << "Sensor chipset: " << dev->chipsetName() << endl+            cout << "Sensor chipset: " << dev->chipsetName() << "\n"
-            cout << "FX3 version info: " << string(dev.fx3Version()) << endl+            cout << "FX3 version info: " << string(dev.fx3Version()) << "\n"
-            cout << "FPGA version info: " << string(dev.fpgaVersion()) << endl+            cout << "FPGA version info: " << string(dev.fpgaVersion()) << "\n"
-            auto & ov = *dev.sensor();  // make a shortcut to the sensor chip +            
-            if(dev){    // or dev.isValid() works, too +                auto & ov{dev.sensor()}  // shortcut to the sensor chip 
-                cout << "current red channel gain is: " << dev->val(GAIN_R) << endl+                cout << "current red channel gain is: " << dev->val(GAIN_R) << "\n"
-                auto gainR ov[GAIN_R];+                auto gainR{ov[GAIN_R]};
                 gainR = gainR + 1;  // increment the red gain by one and update the sensor with the new value                 gainR = gainR + 1;  // increment the red gain by one and update the sensor with the new value
-                cout << "after increasing red channel gain by 1 it is now: " << gainR << endl;+                cout << "after increasing red channel gain by 1 it is now: " << gainR << "\n";
                 ov[GAIN_R] -= 1;                 ov[GAIN_R] -= 1;
-                cout << "and back to the previous value of: " << gainR << endl;+                cout << "and back to the previous value of: " << gainR << "\n";
                 ov[GAIN_R] *= 1.0;                 ov[GAIN_R] *= 1.0;
             }             }
Line 434: Line 403:
             dev.close();    // or the destructor (or even the next call to open()) will take care of that             dev.close();    // or the destructor (or even the next call to open()) will take care of that
             if(dev){             if(dev){
-                cout << "something has gone terribly wrong - the device was supposed to be closed by now!" << endl;+                cout << "something has gone terribly wrong - the device was supposed to be closed by now!\n";
             }else{             }else{
-                cout << "the device is now closed and cannot be accessed without re-opening it" << endl+                cout << "the device is now closed and cannot be accessed without re-opening it\n"; 
-                cout << "For example the red channel gain is now: " << ov[GAIN_R] << endl+                cout << "For example the red channel gain is now: " << dev.sensor()[GAIN_R] << "\n"
-                cout << "But some info is still available, like the sensor chipset: " << dev->chipsetName() << endl+                cout << "But some info is still available, like the sensor chipset: " << dev->chipsetName() << "\n"
-                cout << "Or the information about the limit of red channel gain: " << dev->getLimit(GAIN_R) << endl;+                cout << "Or the information about the limit of red channel gain: " << dev->getLimit(GAIN_R) << "\n";
             }             }
         }else{         }else{
-            cout << "failed." << endl;+            cout << "failed.\n";
             if(dev.isValid()){             if(dev.isValid()){
-                wcout << L"But the FX3 part is still functional, so we can get info like the device's name: " << dev[FX3::PropWString::friendly_name].c_str() << endl;+                wcout << L"But the FX3 part is still functional, so we can get info like the device's name: " << dev[FX3::PropWString::friendly_name].c_str() << "\n";
             }             }
         }         }
-        cout << endl;+        cout << "\n";
     }     }
     return 0;     return 0;

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information