Skip to content

Commit

Permalink
Update ProviderSpi.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev authored Dec 17, 2023
1 parent b13a8aa commit fba37ac
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sources/leddevice/dev_spi/ProviderSpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ int ProviderSpi::open()
int ProviderSpi::close()
{
uint8_t rpBuffer[] = { 0x41, 0x77, 0x41, 0x2a, 0xa2, 0x35, 0x68, 0x79, 0x70, 0x65, 0x72, 0x68, 0x64, 0x72 };
uint8_t accBuffer[] = { 0x6a, 0x77, 0x57, 0x2a, 0xa2, 0x35, 0x68, 0x79, 0x70, 0x65, 0x72, 0x68, 0x64, 0x72 };

// LedDevice specific closing activities
int retval = 0;
Expand All @@ -139,12 +138,7 @@ int ProviderSpi::close()
if (_spiType == "rp2040")
{
writeBytesRp2040(sizeof(rpBuffer), rpBuffer);
writeBytesRp2040(sizeof(accBuffer), accBuffer);
}
else if (_spiType == "esp32")
{
writeBytesEsp32(sizeof(rpBuffer), rpBuffer);
}

// Test, if device requires closing
if (_fid > -1)
Expand Down Expand Up @@ -238,12 +232,15 @@ int ProviderSpi::writeBytesRp2040(unsigned size, const uint8_t* data)

_spi.tx_buf = __u64(&buffer);
_spi.len = __u32(BUFFER_SIZE);
_spi.delay_usecs = 1000;
_spi.delay_usecs = 0;

int retVal = 0;

while (retVal >= 0 && startData < endData)
{
if (startData != data)
usleep(1000);

memset(buffer, 0, sizeof(buffer));
for (int i = 0; i < REAL_BUFFER && startData < endData; i++, startData++)
{
Expand Down Expand Up @@ -278,6 +275,9 @@ int ProviderSpi::writeBytesEsp32(unsigned size, const uint8_t* data)

while (retVal >= 0 && startData < endData)
{
if (startData != data)
usleep(1000);

memset(buffer, 0, sizeof(buffer));
for (int i = 0; i < REAL_BUFFER && startData < endData; i++, startData++)
{
Expand Down

0 comments on commit fba37ac

Please sign in to comment.