diff --git a/ColorListMessage.h b/ColorListMessage.h new file mode 100644 index 0000000..3eeb108 --- /dev/null +++ b/ColorListMessage.h @@ -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); + } + }; + +} diff --git a/REDLEDClient.xcodeproj/project.pbxproj b/REDLEDClient.xcodeproj/project.pbxproj index 4ac7ed8..1e3e62d 100644 --- a/REDLEDClient.xcodeproj/project.pbxproj +++ b/REDLEDClient.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ 50D6C3C5160524A6005E7263 /* Message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Message.h; sourceTree = ""; }; 50D6C3C916052803005E7263 /* ColorMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorMessage.h; sourceTree = ""; }; 50D6C3CA16052925005E7263 /* ColorArrayMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorArrayMessage.h; sourceTree = ""; }; + 50D6C3D31605D09F005E7263 /* ColorListMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorListMessage.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -83,6 +84,7 @@ 50D6C3C5160524A6005E7263 /* Message.h */, 50D6C3C916052803005E7263 /* ColorMessage.h */, 50D6C3CA16052925005E7263 /* ColorArrayMessage.h */, + 50D6C3D31605D09F005E7263 /* ColorListMessage.h */, ); name = Shared; sourceTree = ""; diff --git a/REDLEDClient/RGBSCViewController.mm b/REDLEDClient/RGBSCViewController.mm index ece0729..a80d451 100644 --- a/REDLEDClient/RGBSCViewController.mm +++ b/REDLEDClient/RGBSCViewController.mm @@ -12,6 +12,8 @@ #import "ColorMessage.h" #import "ColorArrayMessage.h" +#import "ColorListMessage.h" + @interface RGBSCViewController () @@ -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 }