Jul-14-2017, 04:23 AM
Hi yall, I've run into a weird issue with my project that I'm stuck on. Firstly, the git repo with all the code is here:
github.com/RGKaizen/rainbow-cloud
A little bit about the project, I have a FadeCandy connected via usb to a raspberry pi running Rasbian. fcserver runs on the Pi to talk to some LEDs (NeoPixel strips). webserver.py in my repo creates a HTTP wrapper around fcserver so I can post json to the raspberry pi to turn on LEDs.
Now in webserver.py I have 4 functions:
Given these functions and their behavior, I'm fairly confident that the _Client.put_pixels() function does behavior correctly, but it doesn't seem to do so consistently.
Is the problem some weird bug in that function nonetheless? Is there something python related that I'm just not seeing here.
I'd appreciate any advice you can offer and I'm happy to answer any questions.
github.com/RGKaizen/rainbow-cloud
A little bit about the project, I have a FadeCandy connected via usb to a raspberry pi running Rasbian. fcserver runs on the Pi to talk to some LEDs (NeoPixel strips). webserver.py in my repo creates a HTTP wrapper around fcserver so I can post json to the raspberry pi to turn on LEDs.
Now in webserver.py I have 4 functions:
@_App.route('/Rainbow', methods=['POST']) def handle_rainbow(): try: data = request.get_json(force=True) pixels = data["pixels"] for p in pixels: _PixelState[p["channel"]][p["pos"]] = (p["red"], p["green"], p["blue"]) for c in range(_ChannelCount): if(_Client.put_pixels(_PixelState[c], channel=c)): print('\tsuccess {}\n').format(c) return '\tfail\n' except Exception: return '\tInvalidInput\n' @_App.route('/OnBoth', methods=['GET']) def onBoth(): pixels_out = [] for ii in range(_LedCount): red = 256 green = 0 blue = 0 pixels_out.append((red, green, blue)) _Client.put_pixels(pixels_out, channel=0) for ii in range(_LedCount): red = 0 green = 256 blue = 0 pixels_out.append((red, green, blue)) _Client.put_pixels(pixels_out, channel=1) return 'okay' @_App.route('/OnA', methods=['GET']) def onA(): pixels_out = [] for ii in range(_LedCount): red = 256 green = 0 blue = 0 pixels_out.append((red, green, blue)) _Client.put_pixels(pixels_out, channel=0) return 'okay' @_App.route('/OnB', methods=['GET']) def onB(): pixels_out = [] for ii in range(_LedCount): red = 0 green = 256 blue = 0 pixels_out.append((red, green, blue)) _Client.put_pixels(pixels_out, channel=1) return 'okay' @_App.route('/Off', methods=['GET']) def off(): pixels_out = [] for c in range(_ChannelCount): for ii in range(_LedCount): red = 0 green = 0 blue = 0 pixels_out.append((red, green, blue)) _Client.put_pixels(pixels_out, channel=c) return 'okay'Here's where it gets interesting. OnA turns the first strip to red correctly, Off turns them both off correctly. OnBoth turns 1 red and 1 green correctly. However OnB does nothing (but returns okay meaning no apparent issue was found), and the main function handle_rainbow correctly renders effects on channel 0 (the first strip), but not on the second strip.
Given these functions and their behavior, I'm fairly confident that the _Client.put_pixels() function does behavior correctly, but it doesn't seem to do so consistently.
Is the problem some weird bug in that function nonetheless? Is there something python related that I'm just not seeing here.
I'd appreciate any advice you can offer and I'm happy to answer any questions.