Skip to content
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

Add and implement new set_rgb packet type #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions arduino/kegboard/kegboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#define KBM_SET_OUTPUT_TAG_OUTPUT_ID 0x01
#define KBM_SET_OUTPUT_TAG_OUTPUT_MODE 0x02

#define KBM_SET_RGB 0x85
#define KBM_SET_RGB_TAG_RED 0x01
#define KBM_SET_RGB_TAG_GREEN 0x02
#define KBM_SET_RGB_TAG_BLUE 0x03

#define OUTPUT_DISABLED 0
#define OUTPUT_ENABLED 1

Expand Down
30 changes: 30 additions & 0 deletions arduino/kegboard/kegboard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ void setup()
gLastWiegandInterruptMillis = 0;
#endif

#if KB_ENABLE_RGB_PWM
pinMode(KB_PIN_RGB_PWM_R, OUTPUT);
pinMode(KB_PIN_RGB_PWM_G, OUTPUT);
pinMode(KB_PIN_RGB_PWM_B, OUTPUT);
#endif

writeHelloPacket();
}

Expand Down Expand Up @@ -883,6 +889,14 @@ void setRelayOutput(uint8_t id, uint8_t mode) {
writeRelayPacket(id);
}

#if KB_ENABLE_RGB_PWM
void setRGBOutput(uint8_t red, uint8_t green, uint8_t blue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guard with #if KB_ENABLE_RGB_PWM, so that the code is elided when the option is disabled.

analogWrite(KB_PIN_RGB_PWM_R, red);
analogWrite(KB_PIN_RGB_PWM_G, green);
analogWrite(KB_PIN_RGB_PWM_B, blue);
}
#endif

void handleInputPacket() {
if (!gPacketStat.have_packet) {
return;
Expand Down Expand Up @@ -910,6 +924,22 @@ void handleInputPacket() {
}
break;
}

#if KB_ENABLE_RGB_PWM
case KBM_SET_RGB: {
uint8_t red, green, blue;

if (!gInputPacket.ReadTag(KBM_SET_RGB_TAG_RED, &red)
|| !gInputPacket.ReadTag(KBM_SET_RGB_TAG_GREEN, &green)
|| !gInputPacket.ReadTag(KBM_SET_RGB_TAG_BLUE, &blue)) {
break;
}

setRGBOutput(red, green, blue);

break;
}
#endif
}
resetInputPacket();
}
Expand Down
11 changes: 10 additions & 1 deletion arduino/kegboard/kegboard_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
// Note: Must set KB_ENABLE_ID12_RFID to 0 if enabling this.
#define KB_ENABLE_WIEGAND_RFID 0

// Enable analog RGB LED control. Must define 3 PWM pins separately,
// as KB_PIN_RGB_PWM_{A,B,C}. Generally only larger boards like Arduino
// Mega have available pins for this.
#define KB_ENABLE_RGB_PWM 0

// Enable software debounce? EXPERIMENTAL. Enabling this feature may negatively
// affect pour accuracy. In particular, a delay is added to each flow meter
// ISR, disabling all other interrupts during this time.
Expand Down Expand Up @@ -101,14 +106,18 @@
#define KB_PIN_WIEGAND_RFID_DATA1 A5

// Atmega1280 (aka Arduino mega) section
#ifdef __AVR_ATmega1280__
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define KB_ATMEGA_1280 1
#define KB_NUM_METERS 6

#define KB_PIN_METER_C 21
#define KB_PIN_METER_D 20
#define KB_PIN_METER_E 19
#define KB_PIN_METER_F 18

#define KB_PIN_RGB_PWM_R 44
#define KB_PIN_RGB_PWM_G 45
#define KB_PIN_RGB_PWM_B 46
#else
#define KB_NUM_METERS 2
#endif
Expand Down
14 changes: 14 additions & 0 deletions docs/source/serial-protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ This command is sent to the board to enable or disable a device output.
| 0x02 | output_mode | output_t | Mode to set the output. |
+---------+-----------------+----------+---------------------------------------+

``set_rgb`` command (0x85)
------------------------------------

This command is sent to the board to set the color of any RGB LEDs attached.

+---------+-----------------+----------+---------------------------------------+
| Tag ID | Name | Type | Description |
+=========+=================+==========+=======================================+
| 0x01 | red | uint8_t | Red value (0-255). |
+---------+-----------------+----------+---------------------------------------+
| 0x02 | green | uint8_t | Green value (0-255). |
+---------+-----------------+----------+---------------------------------------+
| 0x03 | blue | uint8_t | Blue value (0-255). |
+---------+-----------------+----------+---------------------------------------+


Protocol Revision History
Expand Down
5 changes: 5 additions & 0 deletions python/kegbot/kegboard/kegboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ class SetOutputCommand(Message):
output_id = Uint8Field(0x01)
output_mode = OutputField(0x02)

class SetRGBCommand(Message):
MESSAGE_ID = 0x85
red = Uint8Field(0x01)
green = Uint8Field(0x02)
blue = Uint8Field(0x03)

MESSAGE_ID_TO_CLASS = {}
for cls in Message.__subclasses__():
Expand Down