Skip to content

Commit

Permalink
Adjusted method signature of transfer methods in README
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-meissner committed Jan 11, 2018
1 parent f965744 commit 1c48005
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Communication is handled by the following classes
* BitBangingInterface: In case of using any other GPIO pins

## Regular interface
Don't forget to close connection before object gets deleted.
Otherwise new connection could fail.
### Opening/Closing the connection
```PHP
use Volantus\BerrySpi\RegularInterface;

Expand All @@ -42,20 +45,11 @@ $interface = new RegularInterface(1, 32768, 0);
// Opening the connection
$interface->open();

// Sending + retrieving data simustanisly
$retrievedData = $interface->transfer(0x1269493);

// Reading 8 bytes of data
$retrievedData = $interface->read(8);

// Just sending data
$interface->write('abc');

// Don't forget to close the connection
$interface->close();
```

### Parameters
#### Parameters
The constructor accept three parameters

| Parameter | Description |
Expand All @@ -65,7 +59,34 @@ The constructor accept three parameters
| | 32K-125M (values above 30M are unlikely to work) |
| flags | Additional configuration, see [details](http://abyz.me.uk/rpi/pigpio/cif.html#spiOpen) |

### Bit banging interface

### Cross transferring data
Sending + retrieving data simultaneously. Same count of byte as send is read.
Method accepts an array of words(bytes) to send.
```PHP
$retrievedData = $interface->transfer([1, 2, 3]);
echo '1. received byte: ' . $retrievedData[0];
echo '2. received byte: ' . $retrievedData[1];
echo '3. received byte: ' . $retrievedData[2];
```
### Just reading
Reads given count of bytes
```PHP
// Reading 8 bytes of data
$retrievedData = $interface->read(8);
```

### Just writing
Sends the given bytes
```PHP
// Just sending data
$interface->write([1, 2, 3]);
```

## Bit banging interface
Don't forget to close connection before object gets deleted.
Otherwise new connection could fail.
### Opening/Closing the connection
```PHP
use Volantus\BerrySpi\BitBangingInterface;

Expand All @@ -74,14 +95,11 @@ $interface = new BitBangingInterface(12, 16, 20, 21, 512, 0);
// Opening the connection
$interface->open();

// Sending + retrieving data simustanisly
$retrievedData = $interface->transfer(0x1269493);

// Don't forget to close the connection
$interface->close();
```

### Parameters
#### Parameters
The constructor accept three parameters

| Parameter | Description |
Expand All @@ -98,6 +116,17 @@ The constructor accept three parameters

*² This pin can be shared with multiple slave devices, if no parallel data transfer is required


### Cross transferring data
Sending + retrieving data simultaneously. Same count of byte as send is read.
Method accepts an array of words(bytes) to send.
```PHP
$retrievedData = $interface->transfer([1, 2, 3]);
echo '1. received byte: ' . $retrievedData[0];
echo '2. received byte: ' . $retrievedData[1];
echo '3. received byte: ' . $retrievedData[2];
```

## Error handling
All errors are wrapped in exceptions within the namespace Volantus\BerrySpi.
To see which method throws which exception please consult the stubs.
Expand Down

0 comments on commit 1c48005

Please sign in to comment.