-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ambientlight: Add ambient light API simulator #7
Conversation
Thx @MatonAnthony ... looks good just a remark regarding the value maybe there is no semantic needed at the driver level... value could just be a number to align: this should be also fixed in geolocation's simulator @Vinnl What are you opinions on it ? |
Next step is to integrate it to lib/ambientlight/index.js and use it by default see: Feel free to refactor your file if you want to align to the actual driver... |
lib/ambientlight/index.js
Outdated
@@ -19,6 +19,7 @@ | |||
|
|||
var console = require('console'); | |||
var BH1750 = require('bh1750'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thuis could be sourounded by a try to load on your macos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good could be improved now or later
try to run it
using
node lib/ambiantlight
lib/ambientlight/index.js
Outdated
@@ -77,6 +78,9 @@ AmbientLight.prototype.start = function start() { | |||
this.state = 'activating'; | |||
if (!this.sensor) { | |||
try { | |||
if (this.options.controller === undefined) { | |||
this.sensor = new Simulator(); | |||
} | |||
if (this.options.controller === 'bh1750') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else ..
lib/ambientlight/index.js
Outdated
@@ -42,7 +46,7 @@ function AmbientLight(options) { | |||
|
|||
this.options = options || {}; | |||
this.options.frequency = this.options.frequency || 1; | |||
this.options.controller = this.options.controller || 'bh1750'; | |||
this.options.controller = this.options.controller; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|| 'simulator'
lib/ambientlight/index.js
Outdated
@@ -56,7 +60,7 @@ AmbientLight.prototype.update = function update() { | |||
return self.onerror(data); | |||
} else { | |||
self.timestamp = new Date(); | |||
self.illuminance = Number(data); | |||
self.illuminance = Number(data.illuminance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should remove illuminance from simulator and preserve the original line to keep compatibility with bh driver
@@ -24,7 +24,7 @@ function Simulator () { | |||
}; | |||
} | |||
|
|||
Simulator.prototype.read = function (callback) { | |||
Simulator.prototype.readLight = function (callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok you aligned to sensor good maybe sensor should use read, but upstream is not very reactive
please squash this change in similator.js change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to rebase everything into a single commit once it's ready for merge to have a clear commit easy to revert.
package.json
Outdated
"keywords": [ | ||
"ambiant", | ||
"ambiantlight", | ||
"generic", | ||
"i2c", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this keyword can be kept as it can be supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok it's improving, have you tested it on macos ?
Yes, I tested it on macos. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now It looks good,
maybe the temp driver should not be optional as simulator is not yet done...
now you can try to squash some commits to hide intermediary works
06dcc38
to
1e60392
Compare
Add the simulator driver for ambientlight API. - Write a simulator driver for ambientlight - Use it as a default driver if no driver is specified Issue-Id: rzr#5 Add simulators Environment: Darwin 18.2.0 Node 10.15.1 Node 9.5.0 Signed-off-by: Anthony Maton <me@anthony-maton.me>
1e60392
to
32c0ed8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all good, same should be done for temperature
then I will release a npm
Add an Ambient Light API simulator. (see #5)
Signed-off-by: Anthony Maton me@anthony-maton.me