hyperion.ng/libsrc/leddevice/LedDevicePiBlaster.h

63 lines
1.4 KiB
C
Raw Normal View History

#pragma once
// STL includes
#include <cstdio>
Piblaster fix (#614) * Removed -HUP so the default -TERM signal is sent instead. - hyperiond only listens for TERM and INT. HUP is often used to get an exe to reread its config Changed pgrep to add '-x' so it wont partial match on the exe name. - I have multiple instances with multiple hyperiond-instance1 names - this ensures the service script only kills the right process * reversing errant change to hyperion.systemd.sh * Experimental changes to piblaster code to work how i think it should It is now assumed that the PWM pins in groups of 3 correspond to RGB channels of the led. "assignment" : "rgbrgbrgb", Would result in: //Channel number GPIO number Led channel // 0 4 0 red // 1 17 0 green // 2 18 0 blue // 4 27 1 red // 5 21 1 green // 6 22 1 blue // 7 23 2 red // 8 24 2 green // 9 25 2 blue * Ammend pwm channel mapping comments to match the code * 1st cut of the new more flexible piblaster pin mapping support it works but is still rough * removed old "assignment" handling - prints an error messaage if found and terminates fixed the switchoff method * removing iPins hard coded list of valid GPIO pins * removed iPins array for switchOff function * code cleanups input validation * Handle catching (and ignoring) SIGPIPE. You can now kill and restart pi-blaster daemon and hyperiond will gracefully recover * added a binary for testing * Added sample config and my modified pi-blaster version to support more GPIOs * moved hyperiond * removed testing binaries move sample configuration to the configs directory * re enabled device config display * removed sample configuration Former-commit-id: 95e4d4ea2fb7cb5439e8cd597883a638da61a574
2016-04-29 16:00:33 +02:00
// jsoncpp includes
#include <json/json.h>
// Hyperion-Leddevice includes
#include <leddevice/LedDevice.h>
class LedDevicePiBlaster : public LedDevice
{
public:
///
/// Constructs the PiBlaster device which writes to the indicated device and for the assigned
/// channels
/// @param deviceName The name of the output device
Piblaster fix (#614) * Removed -HUP so the default -TERM signal is sent instead. - hyperiond only listens for TERM and INT. HUP is often used to get an exe to reread its config Changed pgrep to add '-x' so it wont partial match on the exe name. - I have multiple instances with multiple hyperiond-instance1 names - this ensures the service script only kills the right process * reversing errant change to hyperion.systemd.sh * Experimental changes to piblaster code to work how i think it should It is now assumed that the PWM pins in groups of 3 correspond to RGB channels of the led. "assignment" : "rgbrgbrgb", Would result in: //Channel number GPIO number Led channel // 0 4 0 red // 1 17 0 green // 2 18 0 blue // 4 27 1 red // 5 21 1 green // 6 22 1 blue // 7 23 2 red // 8 24 2 green // 9 25 2 blue * Ammend pwm channel mapping comments to match the code * 1st cut of the new more flexible piblaster pin mapping support it works but is still rough * removed old "assignment" handling - prints an error messaage if found and terminates fixed the switchoff method * removing iPins hard coded list of valid GPIO pins * removed iPins array for switchOff function * code cleanups input validation * Handle catching (and ignoring) SIGPIPE. You can now kill and restart pi-blaster daemon and hyperiond will gracefully recover * added a binary for testing * Added sample config and my modified pi-blaster version to support more GPIOs * moved hyperiond * removed testing binaries move sample configuration to the configs directory * re enabled device config display * removed sample configuration Former-commit-id: 95e4d4ea2fb7cb5439e8cd597883a638da61a574
2016-04-29 16:00:33 +02:00
/// @param gpioMapping The RGB-Channel assignment json object
///
Piblaster fix (#614) * Removed -HUP so the default -TERM signal is sent instead. - hyperiond only listens for TERM and INT. HUP is often used to get an exe to reread its config Changed pgrep to add '-x' so it wont partial match on the exe name. - I have multiple instances with multiple hyperiond-instance1 names - this ensures the service script only kills the right process * reversing errant change to hyperion.systemd.sh * Experimental changes to piblaster code to work how i think it should It is now assumed that the PWM pins in groups of 3 correspond to RGB channels of the led. "assignment" : "rgbrgbrgb", Would result in: //Channel number GPIO number Led channel // 0 4 0 red // 1 17 0 green // 2 18 0 blue // 4 27 1 red // 5 21 1 green // 6 22 1 blue // 7 23 2 red // 8 24 2 green // 9 25 2 blue * Ammend pwm channel mapping comments to match the code * 1st cut of the new more flexible piblaster pin mapping support it works but is still rough * removed old "assignment" handling - prints an error messaage if found and terminates fixed the switchoff method * removing iPins hard coded list of valid GPIO pins * removed iPins array for switchOff function * code cleanups input validation * Handle catching (and ignoring) SIGPIPE. You can now kill and restart pi-blaster daemon and hyperiond will gracefully recover * added a binary for testing * Added sample config and my modified pi-blaster version to support more GPIOs * moved hyperiond * removed testing binaries move sample configuration to the configs directory * re enabled device config display * removed sample configuration Former-commit-id: 95e4d4ea2fb7cb5439e8cd597883a638da61a574
2016-04-29 16:00:33 +02:00
LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping);
virtual ~LedDevicePiBlaster();
///
/// Attempts to open the piblaster-device. This will only succeed if the device is not yet open
/// and the device is available.
///
/// @param report If true errors are writen to the standard error else silent
/// @return Zero on succes else negative
///
int open(bool report = true);
///
/// Writes the colors to the PiBlaster device
///
/// @param ledValues The color value for each led
///
/// @return Zero on success else negative
///
int write(const std::vector<ColorRgb> &ledValues);
///
/// Switches off the leds
///
/// @return Zero on success else negative
///
int switchOff();
private:
/// The name of the output device (very likely '/dev/pi-blaster')
const std::string _deviceName;
Piblaster fix (#614) * Removed -HUP so the default -TERM signal is sent instead. - hyperiond only listens for TERM and INT. HUP is often used to get an exe to reread its config Changed pgrep to add '-x' so it wont partial match on the exe name. - I have multiple instances with multiple hyperiond-instance1 names - this ensures the service script only kills the right process * reversing errant change to hyperion.systemd.sh * Experimental changes to piblaster code to work how i think it should It is now assumed that the PWM pins in groups of 3 correspond to RGB channels of the led. "assignment" : "rgbrgbrgb", Would result in: //Channel number GPIO number Led channel // 0 4 0 red // 1 17 0 green // 2 18 0 blue // 4 27 1 red // 5 21 1 green // 6 22 1 blue // 7 23 2 red // 8 24 2 green // 9 25 2 blue * Ammend pwm channel mapping comments to match the code * 1st cut of the new more flexible piblaster pin mapping support it works but is still rough * removed old "assignment" handling - prints an error messaage if found and terminates fixed the switchoff method * removing iPins hard coded list of valid GPIO pins * removed iPins array for switchOff function * code cleanups input validation * Handle catching (and ignoring) SIGPIPE. You can now kill and restart pi-blaster daemon and hyperiond will gracefully recover * added a binary for testing * Added sample config and my modified pi-blaster version to support more GPIOs * moved hyperiond * removed testing binaries move sample configuration to the configs directory * re enabled device config display * removed sample configuration Former-commit-id: 95e4d4ea2fb7cb5439e8cd597883a638da61a574
2016-04-29 16:00:33 +02:00
int _gpio_to_led[64];
char _gpio_to_color[64];
/// File-Pointer to the PiBlaster device
FILE * _fid;
};