From 7adb339deac67b67c796fac7838fe3293e0131b1 Mon Sep 17 00:00:00 2001 From: RickDB Date: Tue, 15 Mar 2016 18:37:55 +0100 Subject: [PATCH] Updated orbIds config setting and sample config. Former-commit-id: 350db40b53d04efbb43dc8c87c88bf2eb378fa6b --- doc/datasheets/AtmoOrb_sample_config.json | 12 +++++++----- libsrc/leddevice/LedDeviceFactory.cpp | 24 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/doc/datasheets/AtmoOrb_sample_config.json b/doc/datasheets/AtmoOrb_sample_config.json index 51e330a4..1c81790a 100644 --- a/doc/datasheets/AtmoOrb_sample_config.json +++ b/doc/datasheets/AtmoOrb_sample_config.json @@ -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", @@ -22,7 +24,7 @@ "transitiontime" : 0, "port" : 49692, "numLeds" : 24, - "orbIds" : [1], + "orbIds" : "1", "switchOffOnBlack" : true, "colorOrder" : "rgb" }, diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 8d39ea30..49b197f6 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -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 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 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") {