Skip to content

Some RDS fixes #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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