Skip to content

Commit

Permalink
Merge pull request sowbug#53 from samccone/sjs/color_packets
Browse files Browse the repository at this point in the history
Add the ability to control per LED color via the protocol
  • Loading branch information
reillyeon authored Mar 24, 2018
2 parents d63bb0c + 7e52e0e commit 192ad7a
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 180 deletions.
20 changes: 15 additions & 5 deletions commandline/wlctl
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ if len(args) == 0:

if len(args) == 1:
command = WL_REQUEST_COLOR
bytes = binascii.unhexlify(('000000' + args[0])[-6:])
bytes = binascii.unhexlify(args[0])

if len(bytes) < 4:
raise ValueError(('4 bytes required only got ', len(bytes), bytes))

result = dev.ctrl_transfer(0x40, command, 0, 0, bytes)

if result != len(bytes):
raise IOError('Error', result)
else:
Expand All @@ -297,15 +302,20 @@ else:

msec = int(options.msec)
for arg in args:
bytes = binascii.unhexlify(('000000' + arg)[-6:])
bytes = binascii.unhexlify(arg)

if len(bytes) < 4:
raise ValueError("4 bytes required only got %s", len(bytes))

result = dev.ctrl_transfer(0x40, WL_REQUEST_COLOR, 0, 0, bytes)
if result != len(bytes):
raise IOError('Error: expected %d but got %d' % (len(bytes), result))

bytes = bytearray([(msec >> 8) & 0xff, msec & 0xff])
result = dev.ctrl_transfer(0x40, WL_REQUEST_PAUSE, 0, 0, bytes)
if result != len(bytes):
raise IOError('Error', result)

result = dev.ctrl_transfer(0x40, WL_REQUEST_PLAY, 0, 0, None)
if result != 0:
raise IOError('Error', result)
result = dev.ctrl_transfer(0x40, WL_REQUEST_PLAY, 0, 0, None)
if result != 0:
raise IOError('Error', result)
2 changes: 1 addition & 1 deletion firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ F_CPU = 16500000 # in Hz

LED_COUNT ?= 2
# used in usbconfig.h
DEVICE_VERSION_MAJOR = 1
DEVICE_VERSION_MAJOR = 2
DEVICE_VERSION_MINOR = 0

USE_CANDLE = 0
Expand Down
29 changes: 19 additions & 10 deletions firmware/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "candle.h"
#include "eeprom.h"
#include "led_control.h"
#include "requests.h" // The custom request numbers we use
#include "requests.h" // The custom request numbers we use
#include "sequencer.h"
#include "webusb.h"

Expand All @@ -17,7 +17,8 @@
#define TICKS_PER_SECOND (60)
#define CLOCK_DIVISOR (8192)

void AppInit(App *ctx) {
void AppInit(App *ctx)
{
LEDsOff();

// Set the timer we use for our animation frames: CK / 8192 (CLOCK_DIVISOR)
Expand All @@ -27,10 +28,13 @@ void AppInit(App *ctx) {
TCCR1 = _BV(CS13) | _BV(CS12) | _BV(CS11);
OCR1A = (F_CPU / CLOCK_DIVISOR) / TICKS_PER_SECOND;

if (IsEEPROMValid()) {
if (IsEEPROMValid())
{
ReadEEPROM();
Load(); // Read sequencer
} else {
Load(); // Read sequencer
}
else
{
GenerateEEPROMData();
SetUpNewEEPROM();
Save();
Expand All @@ -42,19 +46,23 @@ void AppInit(App *ctx) {

uint8_t app_watchdog_led_intensity = 32;
int8_t app_watchdog_led_intensity_delta = 4;
void AppRun(App *ctx) {
void AppRun(App *ctx)
{
// If Timer 1 matched the output-compare register A, then clear it
// and do an animation frame.
if (TIFR & _BV(OCF1A)) {
if (TIFR & _BV(OCF1A))
{
TIFR |= _BV(OCF1A);
uint16_t msec_elapsed = TCNT1 * CLOCK_DIVISOR / 1000;
TCNT1 = 0;

if (CountDownAppWatchdog(msec_elapsed)) {
if (CountDownAppWatchdog(msec_elapsed))
{
SetProgramMode(WATCHDOG_EXPIRATION);
}

switch (GetProgramMode()) {
switch (GetProgramMode())
{
case AD_HOC:
case SEQUENCER:
// Sequencer needs to run during AD_HOC because of transitions.
Expand All @@ -69,7 +77,8 @@ void AppRun(App *ctx) {
SetLEDs(SELECT_ALL_LEDS, app_watchdog_led_intensity, 0, 0);
app_watchdog_led_intensity += app_watchdog_led_intensity_delta;
if (app_watchdog_led_intensity > 96 ||
app_watchdog_led_intensity < 8) {
app_watchdog_led_intensity < 8)
{
app_watchdog_led_intensity_delta = -app_watchdog_led_intensity_delta;
}
break;
Expand Down
Loading

0 comments on commit 192ad7a

Please sign in to comment.