mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
light: modify so C++ wraps C code
This also provides some more functionality. get_raw() has been deprecated in favor of using getNormalized(). Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@ -34,10 +34,11 @@ main(int argc, char **argv)
|
||||
// Create the light sensor object using AIO pin 0
|
||||
upm::Light* light = new upm::Light(0);
|
||||
|
||||
// Read the input and print both the raw value and a rough lux value,
|
||||
// waiting one second between readings
|
||||
// Read the input and print both the normalized ADC value and a
|
||||
// rough lux value, waiting one second between readings
|
||||
while( 1 ) {
|
||||
std::cout << light->name() << " raw value is " << light->raw_value() <<
|
||||
std::cout << light->name() << " normalized value is "
|
||||
<< light->getNormalized() <<
|
||||
", which is roughly " << light->value() << " lux" << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -25,13 +25,13 @@
|
||||
public class LightSample {
|
||||
public static void main(String args[]) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_light.Light gl = new upm_light.Light(2);
|
||||
upm_light.Light gl = new upm_light.Light(0);
|
||||
|
||||
while (true) {
|
||||
float raw_value = gl.raw_value();
|
||||
float raw_value = gl.getNormalized();
|
||||
float value = gl.value();
|
||||
|
||||
System.out.println("raw value: " + raw_value);
|
||||
System.out.println("normalized: " + raw_value);
|
||||
System.out.println("value: " + value);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
@ -28,10 +28,10 @@ var sensor = require('jsupm_light');
|
||||
// Create the light sensor object using AIO pin 0
|
||||
var light = new sensor.Light(0);
|
||||
|
||||
// Read the input and print both the raw value and a rough lux value,
|
||||
// waiting one second between readings
|
||||
// Read the input and print both the normalized ADC value and a rough
|
||||
// lux value, waiting one second between readings
|
||||
function readLightSensorValue() {
|
||||
console.log(light.name() + " raw value is " + light.raw_value() +
|
||||
console.log(light.name() + " normalized value is " + light.getNormalized() +
|
||||
", which is roughly " + light.value() + " lux");
|
||||
}
|
||||
setInterval(readLightSensorValue, 1000);
|
||||
|
@ -1,4 +1,4 @@
|
||||
from __future__ import print_function
|
||||
#!/usr/bin/python
|
||||
# Author: Sarah Knepper <sarah.knepper@intel.com>
|
||||
# Copyright (c) 2014 Intel Corporation.
|
||||
#
|
||||
@ -21,22 +21,23 @@ from __future__ import print_function
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time
|
||||
from upm import pyupm_light as light
|
||||
from upm import pyupm_light as lightObj
|
||||
|
||||
def main():
|
||||
# Create the light sensor object using AIO pin 0
|
||||
light = light.Light(0)
|
||||
sensor = lightObj.Light(0)
|
||||
|
||||
# Read the input and print both the raw value and a rough lux value,
|
||||
# waiting one second between readings
|
||||
# Read the input and print both the normalized ADC value and a
|
||||
# rough lux value, waiting one second between readings
|
||||
while 1:
|
||||
print(light.name() + " raw value is %d" % light.raw_value() + \
|
||||
", which is roughly %d" % light.value() + " lux");
|
||||
print(sensor.name() + " normalized value is %f" % sensor.getNormalized()
|
||||
+ ", which is roughly %d" % sensor.value() + " lux");
|
||||
time.sleep(1)
|
||||
|
||||
# Delete the light sensor object
|
||||
del light
|
||||
del lightObj
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user