Skip to content

Commit

Permalink
ColorListMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
McZonk committed Sep 16, 2012
1 parent 9b6b102 commit 8725947
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ColorListMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "Message.h"

#include "HSBColor.h"

namespace RGBStrip {

class ColorListMessage : public Message {
public:
static const uint8_t Type = 0x03;

struct Key{
HSBColor color __attribute__((packed));
uint16_t index __attribute__((packed));
};

static uint16_t size(uint16_t count) {
return sizeof(ColorListMessage) + sizeof(Key) * count;
}

public:
uint16_t offset;
uint16_t count;

Key keys[0];

void fillHeader(uint16_t count) {
header.identifier = Identifier;
header.type = Type;
header.length = size(count);
}
};

}
2 changes: 2 additions & 0 deletions REDLEDClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
50D6C3C5160524A6005E7263 /* Message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Message.h; sourceTree = "<group>"; };
50D6C3C916052803005E7263 /* ColorMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorMessage.h; sourceTree = "<group>"; };
50D6C3CA16052925005E7263 /* ColorArrayMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorArrayMessage.h; sourceTree = "<group>"; };
50D6C3D31605D09F005E7263 /* ColorListMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorListMessage.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -83,6 +84,7 @@
50D6C3C5160524A6005E7263 /* Message.h */,
50D6C3C916052803005E7263 /* ColorMessage.h */,
50D6C3CA16052925005E7263 /* ColorArrayMessage.h */,
50D6C3D31605D09F005E7263 /* ColorListMessage.h */,
);
name = Shared;
sourceTree = "<group>";
Expand Down
36 changes: 36 additions & 0 deletions REDLEDClient/RGBSCViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#import "ColorMessage.h"
#import "ColorArrayMessage.h"
#import "ColorListMessage.h"


@interface RGBSCViewController () <NSNetServiceDelegate>

Expand Down Expand Up @@ -113,6 +115,40 @@ - (void)bindToNetService:(NSNetService*)netService
message.colors[index] = HSBColor((uint16_t)(rand() % 1536), (uint8_t)(rand() % 255), (uint8_t)(rand() % 256));
}

NSLog(@"%@ success:%d", data, [self.socket sendData:data]);
#elif 1
// Test list

NSMutableData* data = [NSMutableData dataWithLength:RGBStrip::ColorListMessage::size(7)];

RGBStrip::ColorListMessage& message = *(RGBStrip::ColorListMessage*)data.mutableBytes;

message.fillHeader(7);

message.offset = 0;
message.count = 56;

message.keys[0].index = 0;
message.keys[0].color = HSBColor((uint16_t) 0, (uint8_t)255, (uint8_t)255);

message.keys[1].index = 8;
message.keys[1].color = HSBColor((uint16_t) 256, (uint8_t)255, (uint8_t)255);

message.keys[2].index = 16;
message.keys[2].color = HSBColor((uint16_t) 512, (uint8_t)255, (uint8_t)255);

message.keys[3].index = 32;
message.keys[3].color = HSBColor((uint16_t) 768, (uint8_t)255, (uint8_t)255);

message.keys[4].index = 40;
message.keys[4].color = HSBColor((uint16_t)1024, (uint8_t)255, (uint8_t)255);

message.keys[5].index = 48;
message.keys[5].color = HSBColor((uint16_t)1280, (uint8_t)255, (uint8_t)255);

message.keys[6].index = 55;
message.keys[6].color = HSBColor((uint16_t)1536 - 32, (uint8_t)255, (uint8_t)255);

NSLog(@"%@ success:%d", data, [self.socket sendData:data]);
#endif
}
Expand Down

0 comments on commit 8725947

Please sign in to comment.