cp2112 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -6
- data/lib/cp2112.rb +5 -0
- data/lib/cp2112/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5467902d6e8f89ff62a73acf8e28bb51a778cdc5ea652e7001c4bde10a62cae0
         | 
| 4 | 
            +
              data.tar.gz: e8efdc37c5eb2e521c9c137b137f6b20a2f8d5e594efce07d5112759c1059e6a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: '058eaa9c4f60fe090ae5167b13873a4d0a03e3f90a5e4ee03ba2cbadcb0867dd27bc4b50effc20eb8f013e5128d90dd210f1229e15d91de35d424c83a0965b65'
         | 
| 7 | 
            +
              data.tar.gz: bb77bcb5ace5927c926ed7349e53068564d8866a911b9930dfe7dae1e9633a1dfe2d14e025903e3442e10f6c971f4e84517f44c291b44215b3a64c21355cca18
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            # CP2112
         | 
| 2 2 |  | 
| 3 | 
            +
            [](https://badge.fury.io/rb/cp2112)
         | 
| 4 | 
            +
             | 
| 3 5 | 
             
            Ruby wrapper for Silicon Laboratories CP2112 USB(HID) i2c/SMBus bridge library
         | 
| 4 6 |  | 
| 5 7 | 
             
            ## Installation
         | 
| @@ -41,18 +43,20 @@ raise unless (dev.getGpioConfig == gpio_new) | |
| 41 43 | 
             
            }
         | 
| 42 44 |  | 
| 43 45 | 
             
            # Read via I2C
         | 
| 44 | 
            -
            i2c_read = proc{|addr, size|
         | 
| 46 | 
            +
            i2c_read = proc{|addr, size| # addr is shifted by 1 bit (0bAAAA_AAAx, A=0/1, x=ignored)
         | 
| 45 47 | 
             
              dev.readRequest(addr, size)
         | 
| 46 48 | 
             
              dev.forceReadResponse(size)
         | 
| 47 | 
            -
               | 
| 48 | 
            -
               | 
| 49 | 
            +
              s0, buf, buf_read = dev.getReadResponse
         | 
| 50 | 
            +
              raise unless s0 == CP2112::Return_Code::HID_SMBUS_S0_COMPLETE
         | 
| 51 | 
            +
              buf[0...buf_read] # return is [byte, ...]
         | 
| 49 52 | 
             
            }
         | 
| 50 53 |  | 
| 51 54 | 
             
            # Write via I2C
         | 
| 52 | 
            -
            i2c_write = proc{|addr, data| #  | 
| 53 | 
            -
              dev.writeRequest(addr, data, data.size)
         | 
| 55 | 
            +
            i2c_write = proc{|addr, data| # byte array data is expected; data = [byte, ...]
         | 
| 56 | 
            +
              dev.writeRequest(addr, data.pack('C*'), data.size)
         | 
| 54 57 | 
             
              dev.transferStatusRequest
         | 
| 55 | 
            -
              dev.getTransferStatusResponse
         | 
| 58 | 
            +
              s0, s1 = dev.getTransferStatusResponse
         | 
| 59 | 
            +
              raise unless s0 == CP2112::Return_Code::HID_SMBUS_S0_COMPLETE
         | 
| 56 60 | 
             
            }
         | 
| 57 61 |  | 
| 58 62 | 
             
            # TODO: your i2c_read, i2c_write operation
         | 
    
        data/lib/cp2112.rb
    CHANGED
    
    | @@ -332,7 +332,12 @@ end | |
| 332 332 | 
             
              Device.send(:define_method, :initialize, proc{|*args| @device = CP2112::open(*args)[0]})
         | 
| 333 333 |  | 
| 334 334 | 
             
              class <<self
         | 
| 335 | 
            +
                def devices(vid = 0x0000, pid = 0x0000)
         | 
| 336 | 
            +
                  getNumDevices(vid, pid)[0]
         | 
| 337 | 
            +
                end
         | 
| 335 338 | 
             
                def [](index, vid = 0x0000, pid = 0x0000)
         | 
| 339 | 
            +
                  lim = devices(vid, pid)
         | 
| 340 | 
            +
                  raise "Incorrect index (must be < #{lim})" unless lim > index
         | 
| 336 341 | 
             
                  Device::new(index, vid, pid)
         | 
| 337 342 | 
             
                end
         | 
| 338 343 | 
             
              end
         | 
    
        data/lib/cp2112/version.rb
    CHANGED