Skip to content

Commit

Permalink
Merge pull request #7 from caternuson/iss2_rds
Browse files Browse the repository at this point in the history
Some RDS fixes
  • Loading branch information
caternuson committed Jul 12, 2019
2 parents a8d990a + 442759f commit 71c5a54
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions adafruit_si4713.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,36 +453,32 @@ def _set_rds_station(self, station):
# Set the RDS station broadcast value.
station_length = len(station)
assert 0 <= station_length <= 96
self._BUFFER[0] = _SI4710_CMD_TX_RDS_PS
# Fire off each 4 byte update of the station value.
for i in range(0, station_length, 4):
self._BUFFER[0] = _SI4710_CMD_TX_RDS_PS
self._BUFFER[1] = i // 4
self._BUFFER[2] = station[i] if i < station_length else ' '
self._BUFFER[3] = station[i+1] if i+1 < station_length else ' '
self._BUFFER[4] = station[i+2] if i+2 < station_length else ' '
self._BUFFER[5] = station[i+3] if i+3 < station_length else ' '
self._BUFFER[2] = station[i] if i < station_length else 0x00
self._BUFFER[3] = station[i+1] if i+1 < station_length else 0x00
self._BUFFER[4] = station[i+2] if i+2 < station_length else 0x00
self._BUFFER[5] = station[i+3] if i+3 < station_length else 0x00
self._write_from(self._BUFFER, count=6)

def _set_rds_buffer(self, rds_buffer):
# Set the RDS buffer broadcast value.
buf_length = len(rds_buffer)
# 53 blocks in the circular buffer, each 2 bytes long.
assert 0 <= buf_length <= 106
self._BUFFER[0] = _SI4710_CMD_TX_RDS_BUFF
self._BUFFER[1] = 0x06 # Clear the buffer and start update with first
# request, then future requests will turn off
# the empty bit to continue setting data.
self._BUFFER[2] = 0x20
# Fire off each 4 byte update of the station value.
for i in range(0, buf_length, 4):
self._BUFFER[0] = _SI4710_CMD_TX_RDS_BUFF
self._BUFFER[1] = 0x06 if i == 0 else 0x04
self._BUFFER[2] = 0x20
self._BUFFER[3] = i // 4
self._BUFFER[4] = rds_buffer[i] if i < buf_length else ' '
self._BUFFER[5] = rds_buffer[i+1] if i+1 < buf_length else ' '
self._BUFFER[6] = rds_buffer[i+2] if i+2 < buf_length else ' '
self._BUFFER[7] = rds_buffer[i+3] if i+3 < buf_length else ' '
self._BUFFER[4] = rds_buffer[i] if i < buf_length else 0x00
self._BUFFER[5] = rds_buffer[i+1] if i+1 < buf_length else 0x00
self._BUFFER[6] = rds_buffer[i+2] if i+2 < buf_length else 0x00
self._BUFFER[7] = rds_buffer[i+3] if i+3 < buf_length else 0x00
self._write_from(self._BUFFER, count=8)
# Make sure to turn off empty bit for next requests.
self._BUFFER[1] = 0x04

rds_station = property(None, _set_rds_station, None,
"""Set the RDS broadcast station to the specified
Expand Down

0 comments on commit 71c5a54

Please sign in to comment.