Skip to content

Instantly share code, notes, and snippets.

@wyojustin
Created April 23, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyojustin/9570546ff3ee8b1a9f50117c93ae0018 to your computer and use it in GitHub Desktop.
Save wyojustin/9570546ff3ee8b1a9f50117c93ae0018 to your computer and use it in GitHub Desktop.
Add GET_NUM_PIXELS command to BiblioPixel DriverSerial
enum CMDTYPE
{
SETUP_DATA = 1,
PIXEL_DATA = 2,
BRIGHTNESS = 3,
GETID = 4,
SETID = 5,
GETVER = 6,
GET_NUM_LEDS = 7
};
...
// TJS ADDED COMMAND
else if(cmd == CMDTYPE::GET_NUM_LEDS)
{
Serial.write((uint8_t)(NUM_LEDS >> 8));
Serial.write((uint8_t)(NUM_LEDS & 0xFF));
}
class MyCMDTYPE(CMDTYPE):
GET_NUM_PIXELS = 7
class MyDriver(DriverSerial):
def getNumPixels(self):
packet = DriverSerial._generateHeader(MyCMDTYPE.GET_NUM_PIXELS, 0)
try:
self._com.write(packet)
resp = self._com.read(2)
if len(resp) == 2:
out = ord(resp[0]) * 256 + ord(resp[1])
else:
raise ValueError('Did not get two bytes back from BP')
return out
except serial.SerialException:
log.error("Problem connecting to serial device.")
return -1
driver = MyDriver(LEDTYPE.GENERIC, args.width*args.height, hardwareID="16C0:0483", dev="/dev/ttyACM0")
assert driver.getNumPixels() == args.width*args.height, 'Drive is not set up for a matrix of size %dx%d' % (
args.width, args.height
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment