Skip to content

Commit

Permalink
Fixed wrong class name of spi bit banging device
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-meissner committed Mar 21, 2018
1 parent 5989c52 commit 90d22ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
28 changes: 14 additions & 14 deletions src/SPI/BitBangingDeviceErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class BitBangingDeviceErrorHandler implements ErrorHandler
public function handleTransfer(Request $request, Response $response)
{
switch ($response->getResponse()) {
case BitBaningSpiDevice::PI_BAD_USER_GPIO:
throw new TransferFailedException('Cross transfer failed (internal library error) => bad GPIO pin given (PI_BAD_USER_GPIO)', BitBaningSpiDevice::PI_BAD_USER_GPIO);
case BitBangingSpiDevice::PI_BAD_USER_GPIO:
throw new TransferFailedException('Cross transfer failed (internal library error) => bad GPIO pin given (PI_BAD_USER_GPIO)', BitBangingSpiDevice::PI_BAD_USER_GPIO);
break;
case BitBaningSpiDevice::PI_NOT_SPI_GPIO:
throw new TransferFailedException('Cross transfer failed (internal library error) => no SPI action in progress on this pin (PI_NOT_SPI_GPIO)', BitBaningSpiDevice::PI_NOT_SPI_GPIO);
case BitBangingSpiDevice::PI_NOT_SPI_GPIO:
throw new TransferFailedException('Cross transfer failed (internal library error) => no SPI action in progress on this pin (PI_NOT_SPI_GPIO)', BitBangingSpiDevice::PI_NOT_SPI_GPIO);
break;
default:
throw new TransferFailedException('Cross transfer failed => unknown error', $response->getResponse());
Expand All @@ -41,14 +41,14 @@ public function handleTransfer(Request $request, Response $response)
public function handleOpen(Response $response)
{
switch ($response->getResponse()) {
case BitBaningSpiDevice::PI_BAD_USER_GPIO:
throw new OpeningDeviceFailedException('Opening device failed => bad GPIO pin given (PI_BAD_USER_GPIO)', BitBaningSpiDevice::PI_BAD_USER_GPIO);
case BitBangingSpiDevice::PI_BAD_USER_GPIO:
throw new OpeningDeviceFailedException('Opening device failed => bad GPIO pin given (PI_BAD_USER_GPIO)', BitBangingSpiDevice::PI_BAD_USER_GPIO);
break;
case BitBaningSpiDevice::PI_BAD_SPI_BAUD:
throw new OpeningDeviceFailedException('Opening device failed => bad baud rate given (PI_BAD_SPI_BAUD)', BitBaningSpiDevice::PI_BAD_SPI_BAUD);
case BitBangingSpiDevice::PI_BAD_SPI_BAUD:
throw new OpeningDeviceFailedException('Opening device failed => bad baud rate given (PI_BAD_SPI_BAUD)', BitBangingSpiDevice::PI_BAD_SPI_BAUD);
break;
case BitBaningSpiDevice::PI_GPIO_IN_USE:
throw new OpeningDeviceFailedException('Opening device failed => GPIO pin is already in use (PI_GPIO_IN_USE)', BitBaningSpiDevice::PI_GPIO_IN_USE);
case BitBangingSpiDevice::PI_GPIO_IN_USE:
throw new OpeningDeviceFailedException('Opening device failed => GPIO pin is already in use (PI_GPIO_IN_USE)', BitBangingSpiDevice::PI_GPIO_IN_USE);
break;
default:
throw new OpeningDeviceFailedException('Opening device failed => unknown error', $response->getResponse());
Expand All @@ -64,11 +64,11 @@ public function handleOpen(Response $response)
public function handleClose(Response $response)
{
switch ($response->getResponse()) {
case BitBaningSpiDevice::PI_BAD_USER_GPIO:
throw new ClosingDeviceFailedException('Closing device failed (internal library error) => bad GPIO pin given (PI_BAD_USER_GPIO)', BitBaningSpiDevice::PI_BAD_USER_GPIO);
case BitBangingSpiDevice::PI_BAD_USER_GPIO:
throw new ClosingDeviceFailedException('Closing device failed (internal library error) => bad GPIO pin given (PI_BAD_USER_GPIO)', BitBangingSpiDevice::PI_BAD_USER_GPIO);
break;
case BitBaningSpiDevice::PI_NOT_SPI_GPIO:
throw new ClosingDeviceFailedException('Closing device failed (internal library error) => no SPI action in progress on this pin (PI_NOT_SPI_GPIO)', BitBaningSpiDevice::PI_NOT_SPI_GPIO);
case BitBangingSpiDevice::PI_NOT_SPI_GPIO:
throw new ClosingDeviceFailedException('Closing device failed (internal library error) => no SPI action in progress on this pin (PI_NOT_SPI_GPIO)', BitBangingSpiDevice::PI_NOT_SPI_GPIO);
break;
default:
throw new ClosingDeviceFailedException('Closing device failed => unknown error', $response->getResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use Volantus\Pigpio\Protocol\Request;

/**
* Class BitBaningSpiDevice
* Class BitBangingSpiDevice
*
* @package Volantus\Pigpio\SPI
*/
class BitBaningSpiDevice extends SpiDevice
class BitBangingSpiDevice extends SpiDevice
{
const PI_BAD_SPI_BAUD = -141;
const PI_BAD_USER_GPIO = -2;
Expand Down
37 changes: 18 additions & 19 deletions tests/SPI/BitBangingSpiDeviceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
use Volantus\Pigpio\Protocol\ExtensionRequest;
use Volantus\Pigpio\Protocol\ExtensionResponseStructure;
use Volantus\Pigpio\Protocol\Response;
use Volantus\Pigpio\SPI\BitBaningSpiDevice;
use Volantus\Pigpio\SPI\RegularSpiDevice;
use Volantus\Pigpio\SPI\BitBangingSpiDevice;
use Volantus\Pigpio\SPI\SpiFlags;

/**
Expand All @@ -27,19 +26,19 @@ class BitBangingSpiDeviceTest extends TestCase
private $client;

/**
* @var RegularSpiDevice
* @var BitBangingSpiDevice
*/
private $device;

protected function setUp()
{
$this->client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
$this->device = new BitBaningSpiDevice($this->client, 32000, 6, 8, 21, 22, new SpiFlags(['notReserved' => [0]]));
$this->device = new BitBangingSpiDevice($this->client, 32000, 6, 8, 21, 22, new SpiFlags(['notReserved' => [0]]));
}

public function test_constructor_flagsNull()
{
$this->device = new BitBaningSpiDevice($this->client, 32000, 6, 8, 21, 22, null);
$this->device = new BitBangingSpiDevice($this->client, 32000, 6, 8, 21, 22, null);

$this->client->expects(self::once())
->method('sendRaw')
Expand Down Expand Up @@ -78,11 +77,11 @@ public function test_open_calledTwice_idempotent()
*/
public function test_open_badGpioPin()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_BAD_USER_GPIO);
$this->expectExceptionCode(BitBangingSpiDevice::PI_BAD_USER_GPIO);

$this->client->expects(self::once())
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_BAD_USER_GPIO));
->willReturn(new Response(BitBangingSpiDevice::PI_BAD_USER_GPIO));

$this->device->open();
}
Expand All @@ -93,11 +92,11 @@ public function test_open_badGpioPin()
*/
public function test_open_gpioAlreadyInUse()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_GPIO_IN_USE);
$this->expectExceptionCode(BitBangingSpiDevice::PI_GPIO_IN_USE);

$this->client->expects(self::once())
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_GPIO_IN_USE));
->willReturn(new Response(BitBangingSpiDevice::PI_GPIO_IN_USE));

$this->device->open();
}
Expand All @@ -108,11 +107,11 @@ public function test_open_gpioAlreadyInUse()
*/
public function test_open_badBaudRate()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_BAD_SPI_BAUD);
$this->expectExceptionCode(BitBangingSpiDevice::PI_BAD_SPI_BAUD);

$this->client->expects(self::once())
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_BAD_SPI_BAUD));
->willReturn(new Response(BitBangingSpiDevice::PI_BAD_SPI_BAUD));

$this->device->open();
}
Expand Down Expand Up @@ -171,15 +170,15 @@ public function test_close_idempotent()
*/
public function test_close_badGpioPin()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_BAD_USER_GPIO);
$this->expectExceptionCode(BitBangingSpiDevice::PI_BAD_USER_GPIO);

$this->client->expects(self::at(0))
->method('sendRaw')
->willReturn(new Response(0));

$this->client->expects(self::at(1))
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_BAD_USER_GPIO));
->willReturn(new Response(BitBangingSpiDevice::PI_BAD_USER_GPIO));

$this->device->open();
$this->device->close();
Expand All @@ -191,15 +190,15 @@ public function test_close_badGpioPin()
*/
public function test_close_noSpiInProgress()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_NOT_SPI_GPIO);
$this->expectExceptionCode(BitBangingSpiDevice::PI_NOT_SPI_GPIO);

$this->client->expects(self::at(0))
->method('sendRaw')
->willReturn(new Response(0));

$this->client->expects(self::at(1))
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_NOT_SPI_GPIO));
->willReturn(new Response(BitBangingSpiDevice::PI_NOT_SPI_GPIO));

$this->device->open();
$this->device->close();
Expand Down Expand Up @@ -257,15 +256,15 @@ public function test_crossTransfer_notOpen()
*/
public function test_crossTransfer_badGpioPin()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_BAD_USER_GPIO);
$this->expectExceptionCode(BitBangingSpiDevice::PI_BAD_USER_GPIO);

$this->client->expects(self::at(0))
->method('sendRaw')
->willReturn(new Response(0));

$this->client->expects(self::at(1))
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_BAD_USER_GPIO));
->willReturn(new Response(BitBangingSpiDevice::PI_BAD_USER_GPIO));

$this->device->open();
$this->device->crossTransfer([32]);
Expand All @@ -277,15 +276,15 @@ public function test_crossTransfer_badGpioPin()
*/
public function test_crossTransfer_noSpiInProgress()
{
$this->expectExceptionCode(BitBaningSpiDevice::PI_NOT_SPI_GPIO);
$this->expectExceptionCode(BitBangingSpiDevice::PI_NOT_SPI_GPIO);

$this->client->expects(self::at(0))
->method('sendRaw')
->willReturn(new Response(0));

$this->client->expects(self::at(1))
->method('sendRaw')
->willReturn(new Response(BitBaningSpiDevice::PI_NOT_SPI_GPIO));
->willReturn(new Response(BitBangingSpiDevice::PI_NOT_SPI_GPIO));

$this->device->open();
$this->device->crossTransfer([32]);
Expand Down

0 comments on commit 90d22ed

Please sign in to comment.