Skip to content

Commit

Permalink
RGBLamp: Rename level to brightness
Browse files Browse the repository at this point in the history
Aligned to Spec:
https://iot.mozilla.org/wot/#example-2-a-more-complex-thing-description-with-semantic-annotations

Fixed minor build issues too.

Change-Id: I43b9fbc609a226ecb00729c32847670b8f91a5da
Relate-to: WebThingsIO/webthing-node#108
Signed-off-by: Philippe Coval <p.coval@samsung.com>
  • Loading branch information
rzr committed Jul 11, 2019
1 parent 13a0929 commit b3b343e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions examples/RGBLamp/RGBLamp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const char* deviceTypes[] = {"Light", "OnOffSwitch", "ColorControl", nullptr};
ThingDevice device("dimmable-color-light", "Dimmable Color Light", deviceTypes);

ThingProperty deviceOn("on", "Whether the led is turned on", BOOLEAN, "OnOffProperty");
ThingProperty deviceLevel("level", "The level of light from 0-100", NUMBER, "BrightnessProperty");
ThingProperty deviceBrightness("brightness", "The level of light from 0-100", NUMBER, "BrightnessProperty");
ThingProperty deviceColor("color", "The color of light in RGB", STRING, "ColorProperty");

bool lastOn = false;
Expand Down Expand Up @@ -88,10 +88,10 @@ void setup(void) {
adapter = new WebThingAdapter("rgb-lamp", WiFi.localIP());

device.addProperty(&deviceOn);
ThingPropertyValue levelValue;
levelValue.number = 100; // default brightness TODO
deviceLevel.setValue(levelValue);
device.addProperty(&deviceLevel);
ThingPropertyValue brightnessValue;
brightnessValue.number = 100; // default brightness TODO
deviceBrightness.setValue(brightnessValue);
device.addProperty(&deviceBrightness);

//optional properties
//deviceColor.propertyEnum = valEnum;
Expand All @@ -110,13 +110,14 @@ void setup(void) {
Serial.print(WiFi.localIP());
Serial.print("/things/");
Serial.println(device.id);

#ifdef analogWriteRange
analogWriteRange(255);
#endif
}

void update(String* color, int const level) {
void update(String* color, int const brightness) {
if (!color) return;
float dim = level/100.;
float dim = brightness/100.;
int red,green,blue;
if (color && (color->length() == 7) && color->charAt(0) == '#') {
const char* hex = 1+(color->c_str()); // skip leading '#'
Expand All @@ -135,15 +136,15 @@ void loop(void) {
adapter->update();

bool on = deviceOn.getValue().boolean;
int level = deviceLevel.getValue().number;
update(&lastColor, on ? level : 0);
int brightness = deviceBrightness.getValue().number;
update(&lastColor, on ? brightness : 0);

if (on != lastOn) {
Serial.print(device.id);
Serial.print(": on: ");
Serial.print(on);
Serial.print(", level: ");
Serial.print(level);
Serial.print(", brightness: ");
Serial.print(brightness);
Serial.print(", color: ");
Serial.println(lastColor);
}
Expand Down

0 comments on commit b3b343e

Please sign in to comment.