diff --git a/arduino/HalMultiSensor/SensorBH1750.cpp b/arduino/HalMultiSensor/SensorBH1750.cpp index aef3302b..95b43a19 100755 --- a/arduino/HalMultiSensor/SensorBH1750.cpp +++ b/arduino/HalMultiSensor/SensorBH1750.cpp @@ -51,7 +51,7 @@ based on Christopher Laws, March, 2013 code. void SensorBH1750::setup() { Wire.begin(); - configure(BH1750_ONE_TIME_HIGH_RES_MODE); + //configure(BH1750_ONE_TIME_HIGH_RES_MODE); } @@ -78,15 +78,15 @@ void SensorBH1750::configure(uint8_t mode) { void SensorBH1750::read(LightData& data) { - uint16_t level; + configure(BH1750_ONE_TIME_HIGH_RES_MODE); - Wire.beginTransmission(BH1750_I2CADDR); - Wire.requestFrom(BH1750_I2CADDR, 2); - level = Wire.read(); - level <<= 8; - level |= Wire.read(); - Wire.endTransmission(); + Wire.beginTransmission(BH1750_I2CADDR); + Wire.requestFrom(BH1750_I2CADDR, 2); + uint16_t level = Wire.read(); + level <<= 8; + level |= Wire.read(); + Wire.endTransmission(); - data.lumen = level/1.2; // convert to lux + data.lumen = level/1.2; // convert to lux } diff --git a/resource/web/event_overview.tmpl b/resource/web/event_overview.tmpl index 8710d26c..e8a72e92 100755 --- a/resource/web/event_overview.tmpl +++ b/resource/web/event_overview.tmpl @@ -16,7 +16,7 @@ {{#events}} {{.getName()}} - {{.getDeviceData().getClass().getSimpleName()}} + {{.getDeviceConfig().getClass().getSimpleName()}} {{.getDeviceData()}} {{.getDeviceData().getTimestamp()}} diff --git a/resource/web/sensor_overview.tmpl b/resource/web/sensor_overview.tmpl index e0ab9a52..3d05e9af 100755 --- a/resource/web/sensor_overview.tmpl +++ b/resource/web/sensor_overview.tmpl @@ -15,7 +15,7 @@ {{#sensors}} {{.getName()}} - {{.getDeviceData().getClass().getSimpleName()}} + {{.getDeviceConfig().getClass().getSimpleName()}} {{.getDeviceData()}} {{.getDeviceData().getTimestamp()}} diff --git a/src/se/hal/struct/AbstractDevice.java b/src/se/hal/struct/AbstractDevice.java index 475a789a..842c64d4 100755 --- a/src/se/hal/struct/AbstractDevice.java +++ b/src/se/hal/struct/AbstractDevice.java @@ -59,6 +59,7 @@ public abstract class AbstractDevice extends DBBean { deviceConfig = (T) c.newInstance(); applyConfig(); + deviceData = getLatestDeviceData(HalContext.getDB()); } catch (Exception e) { logger.log(Level.SEVERE, "Unable instantiate DeviceConfig: "+type, e); } @@ -95,7 +96,7 @@ public abstract class AbstractDevice extends DBBean { /** * Will update the config String that will be stored in DB. */ - protected void updateConfigString() { + private void updateConfigString() { Configurator configurator = getDeviceConfigurator(); this.config = JSONWriter.toString(configurator.getValuesAsNode()); } @@ -103,7 +104,7 @@ public abstract class AbstractDevice extends DBBean { * This method will configure the current DeviceData with the * configuration from the config String. */ - protected void applyConfig(){ + private void applyConfig(){ if (config != null && !config.isEmpty()) { Configurator configurator = getDeviceConfigurator(); configurator.setValues(JSONParser.read(config)); @@ -153,9 +154,8 @@ public abstract class AbstractDevice extends DBBean { */ public void setType(String type) { if (this.type == null || !this.type.equals(type)) { + setDeviceConfig(null); // reset this.type = type; - this.config = null; - this.deviceConfig = null; // invalidate current sensor data object } }