Skip to content

Commit

Permalink
Updated orbIds config setting and sample config.
Browse files Browse the repository at this point in the history
  • Loading branch information
RickDB authored and RickDB committed Mar 15, 2016
1 parent 31713a4 commit 350db40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
12 changes: 7 additions & 5 deletions doc/datasheets/AtmoOrb_sample_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
/// * [device type specific configuration]
/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).
///
/// * 'Specific of Philips Hue:
/// * 'username' : The name of user registred on the Philips Hue Bridge
/// * 'switchOffOnBlack': Define if Hue light switch off when black is detected
/// * 'transitiontime' : Set the time of transition between color of Hue light
/// * 'Specific for AtmoOrb:
/// * 'transitiontime' : Set the time of transition between color of Orb (not implemented)
/// * 'port' : Multicast UDP port
/// * 'numLeds' : Number of leds in Orb
/// * 'orbIds' : The Orb ids to use
/// * 'switchOffOnBlack': Define if Orb is to switch off when black is detected
"device" :
{
"name" : "MyPi",
Expand All @@ -22,7 +24,7 @@
"transitiontime" : 0,
"port" : 49692,
"numLeds" : 24,
"orbIds" : [1],
"orbIds" : "1",
"switchOffOnBlack" : true,
"colorOrder" : "rgb"
},
Expand Down
24 changes: 19 additions & 5 deletions libsrc/leddevice/LedDeviceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,27 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
const int port = deviceConfig.get("port", 1).asInt();
const int numLeds = deviceConfig.get("numLeds", 1).asInt();

const std::string orbId = deviceConfig["orbIds"].asString();
std::vector<unsigned int> orbIds;
for (Json::Value::ArrayIndex i = 0; i < deviceConfig["orbIds"].size(); i++) {
orbIds.push_back(deviceConfig["orbIds"][i].asInt());
}

device = new LedDeviceAtmoOrb(output, switchOffOnBlack, transitiontime, port, numLeds, orbIds);
// If we find multiple Orb ids separate them and add to list
const std::string separator (",");
if (orbId.find(separator) != std::string::npos) {
std::stringstream ss(orbId);
std::vector<int> output;
unsigned int i;
while (ss >> i) {
orbIds.push_back(i);
if (ss.peek() == ',' || ss.peek() == ' ')
ss.ignore();
}
}
else
{
orbIds.push_back(atoi(orbId.c_str()));
}

device = new LedDeviceAtmoOrb(output, switchOffOnBlack, transitiontime, port, numLeds, orbIds);
}
else if (type == "test")
{
Expand Down

0 comments on commit 350db40

Please sign in to comment.