Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
rjcorwin committed Jun 12, 2015
0 parents commit eadd315
Show file tree
Hide file tree
Showing 122 changed files with 33,792 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "yoctolib_python"]
path = yoctolib_python
url = https://github.com/yoctopuce/yoctolib_python.git
11 changes: 11 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# CLI for Yoctopuce's USB Temperature Sensor

Plug in your temperature sensor and then run `./pull` on the command line.

```
> ./pull
46.5
```



28 changes: 28 additions & 0 deletions pull
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys
# add .../Sources to the PYTHONPATH
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),"yoctolib_python","Sources"))
from yocto_api import *
from yocto_temperature import *


def die(msg):
sys.exit(msg+' (check USB cable)')

errmsg=YRefParam()

target='any'

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)

# retreive any temperature sensor
sensor = YTemperature.FirstTemperature()
if sensor is None :
die('No module connected')


if not(sensor.isOnline()):die('device not connected')
print(sensor.get_currentValue())
3,092 changes: 3,092 additions & 0 deletions yoctolib_python/Documentation/yoctolib-python-EN.html

Large diffs are not rendered by default.

Binary file not shown.
3,092 changes: 3,092 additions & 0 deletions yoctolib_python/Documentation/yoctolib-python-FR.html

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("..","..","Sources"))
from yocto_api import *
from yocto_genericsensor import *

def usage():
scriptname = os.path.basename(sys.argv[0])
print("Usage:")
print(scriptname+' <serial_number>')
print(scriptname+' <logical_name>')
print(scriptname+' any ')
sys.exit()

def die(msg):
sys.exit(msg+' (check USB cable)')

errmsg=YRefParam()

if len(sys.argv)<2 : usage()

target=sys.argv[1]

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)

if target=='any':
# retreive any genericSensor sensor
sensor = YGenericSensor.FirstGenericSensor()
if sensor is None :
die('No module connected')
else:
sensor= YGenericSensor.FindGenericSensor(target + '.genericSensor1')

if not(sensor.isOnline()):die('device not connected')

# retreive module serial
serial=sensor.get_module().get_serialNumber()


# retreive both channels
channel1 = YGenericSensor.FindGenericSensor(serial + '.genericSensor1')
channel2 = YGenericSensor.FindGenericSensor(serial + '.genericSensor2')


while channel1.isOnline() and channel2.isOnline():
print("channel 1: %f %s" % (channel1.get_currentValue(), channel1.get_unit()))
print("channel 2: %f %s" % (channel2.get_currentValue(), channel2.get_unit()))
print( " (Ctrl-C to stop)")
YAPI.Sleep(1000)
66 changes: 66 additions & 0 deletions yoctolib_python/Examples/Doc-GettingStarted-Yocto-3D/helloworld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("..","..","Sources"))
from yocto_api import *
from yocto_tilt import *
from yocto_compass import *
from yocto_gyro import *
from yocto_accelerometer import *

def usage():
scriptname = os.path.basename(sys.argv[0])
print("Usage:")
print(scriptname+' <serial_number>')
print(scriptname+' <logical_name>')
print(scriptname+' any ')
sys.exit()

def die(msg):
sys.exit(msg+' (check USB cable)')

errmsg=YRefParam()

if len(sys.argv)<2 : usage()

target=sys.argv[1]

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)

if target=='any':
# retreive any tilt sensor
anytilt = YTilt.FirstTilt()
if anytilt is None :
die('No module connected (check USB cable)')
m = anytilt.get_module()
target = m.get_serialNumber()
else:
anytilt = YTilt.FindTilt(target + ".tilt1")
if not (anytilt.isOnline()):
die('Module not connected (check identification and USB cable)')

serial = anytilt.get_module().get_serialNumber()
tilt1 = YTilt.FindTilt(serial + ".tilt1")
tilt2 = YTilt.FindTilt(serial + ".tilt2")
compass = YCompass.FindCompass(serial + ".compass")
accelerometer = YAccelerometer.FindAccelerometer(serial+".accelerometer")
gyro = YGyro.FindGyro(serial + ".gyro")

count =0

while (True):
if not(tilt1.isOnline()):
die("Module not connected (check identification and USB cable)")

if (count % 10 == 0): print("tilt1 tilt2 compass acc gyro")

print( "%-7.1f "%tilt1.get_currentValue() + \
"%-7.1f "%tilt2.get_currentValue() + \
"%-7.1f "%compass.get_currentValue() + \
"%-7.1f "%accelerometer.get_currentValue() + \
"%-7.1f"%gyro.get_currentValue())
count=count+1
YAPI.Sleep(250, errmsg)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("..","..","Sources"))
from yocto_api import *
from yocto_genericsensor import *

def usage():
scriptname = os.path.basename(sys.argv[0])
print("Usage:")
print(scriptname+' <serial_number>')
print(scriptname+' <logical_name>')
print(scriptname+' any ')
sys.exit()

def die(msg):
sys.exit(msg+' (check USB cable)')

errmsg=YRefParam()

if len(sys.argv)<2 : usage()

target=sys.argv[1]

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)

if target=='any':
# retreive any genericSensor sensor
sensor = YGenericSensor.FirstGenericSensor()
if sensor is None :
die('No module connected')
else:
sensor= YGenericSensor.FindGenericSensor(target + '.genericSensor1')

if not(sensor.isOnline()):die('device not connected')

# retreive module serial
serial=sensor.get_module().get_serialNumber()


# retreive both channels
channel1 = YGenericSensor.FindGenericSensor(serial + '.genericSensor1')
channel2 = YGenericSensor.FindGenericSensor(serial + '.genericSensor2')


while channel1.isOnline() and channel1.isOnline():
print("channel 1: %f %s" % (channel1.get_currentValue(), channel1.get_unit()))
print("channel 2: %f %s" % (channel2.get_currentValue(), channel2.get_unit()))
print( " (Ctrl-C to stop)")
YAPI.Sleep(1000)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("..","..","Sources"))
from yocto_api import *
from yocto_altitude import *
from yocto_temperature import *
from yocto_pressure import *

def usage():
scriptname = os.path.basename(sys.argv[0])
print("Usage:")
print(scriptname+' <serial_number>')
print(scriptname+' <logical_name>')
print(scriptname+' any ')
sys.exit()

def die(msg):
sys.exit(msg+' (check USB cable)')

errmsg=YRefParam()

if len(sys.argv)<2 : usage()

target=sys.argv[1]

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)

if target=='any':
# retreive any altitude sensor
sensor = YAltitude.FirstAltitude()
if sensor is None :
die('No module connected')
m = sensor.get_module()
target = m.get_serialNumber()

else:
m = YModule.FindModule(target)

if not m.isOnline() : die('device not connected')

altSensor = YAltitude.FindAltitude(target+'.altitude')
pressSensor = YPressure.FindPressure(target+'.pressure')
tempSensor = YTemperature.FindTemperature(target+'.temperature')


while True:
print("%4.1f" % altSensor.get_currentValue()+"m (QNH="\
+ "%4.1f" % altSensor.get_qnh()+"hPa)"\
+ "%4.1f" % pressSensor.get_currentValue()+"hPa "\
+ "%2.0f" % tempSensor.get_currentValue()+"deg C "\
+ (Ctrl-c to stop) ")
YAPI.Sleep(1000)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("..","..","Sources"))
from yocto_api import *
from yocto_current import *


def usage():
scriptname = os.path.basename(sys.argv[0])
print("Usage:")
print(scriptname+' <serial_number>')
print(scriptname+' <logical_name>')
print(scriptname+' any ')
sys.exit()

def die(msg):
sys.exit(msg+' (check USB cable)')

errmsg=YRefParam()

if len(sys.argv)<2 : usage()

target=sys.argv[1]

# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)


if target=='any':
# retreive any voltage sensor (can be AC or DC)
sensor = YCurrent.FirstCurrent()
if sensor is None :
die('No module connected')
else:
sensor= YCurrent.FindCurrent(target + '.current1')

# we need to retreive both DC and AC voltage from the device.
if sensor.isOnline():
m = sensor.get_module()
sensorDC = YCurrent.FindCurrent(m.get_serialNumber() + '.current1')
sensorAC = YCurrent.FindCurrent(m.get_serialNumber() + '.current2')
else:
die('Module not connected')

# let's poll
while True:
if not m.isOnline() : die('Module not connected')
print('DC: ' + str(sensorDC.get_currentValue()) + ' mA ' + \
'AC: ' + str(sensorAC.get_currentValue()) + ' mA ')
print(' (press Ctrl-C to exit)')
YAPI.Sleep(1000, errmsg)
Loading

0 comments on commit eadd315

Please sign in to comment.