I'm new in JS and async... so I need help :) I need to return value after serial communication. reading serial apparently need to be function, so I dont know how to make it blocking, or return value from it... console log shows value, but value is not returned...(probably because its executed before serial). please help. Here is part of code:
var LightController = {
getBrightness: function() { //get brightness
port.write(askcommand);
port.on('data', function (data) {
st = data.slice(-4, -3);
this.brightness = st.readInt8(0);
console.log(this.brightness)
});
return this.brightness;
},
lightAccessory
.getService(Service.Lightbulb)
.addCharacteristic(Characteristic.Brightness)
.on('get', function(callback) {
callback(null, LightController.getBrightness());
});