Skip to content

Commit 711778f

Browse files
committed
2 parents de2b761 + 975fa43 commit 711778f

File tree

11 files changed

+65
-25
lines changed

11 files changed

+65
-25
lines changed

lib/pycoproc/pycoproc.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information
77
# see the Pycom Licence v1.0 document supplied with this file, or
88
# available at https://www.pycom.io/opensource/licensing
99
#
1010

11+
# See https://docs.pycom.io for more information regarding library specifics
12+
1113
from machine import Pin
1214
from machine import I2C
1315
import time
@@ -26,6 +28,12 @@ class Pycoproc:
2628

2729
I2C_SLAVE_ADDR = const(8)
2830

31+
PYSENSE = const(1)
32+
PYTRACK = const(2)
33+
PYSCAN = const(3)
34+
35+
BOARD_TYPE_SET = (PYSENSE, PYTRACK, PYSCAN)
36+
2937
CMD_PEEK = const(0x0)
3038
CMD_POKE = const(0x01)
3139
CMD_MAGIC = const(0x02)
@@ -81,14 +89,18 @@ class Pycoproc:
8189

8290
EXP_RTC_PERIOD = const(7000)
8391

84-
def __init__(self, i2c=None, sda='P22', scl='P21'):
92+
def __init__(self, board_type, i2c=None, sda='P22', scl='P21'):
8593
if i2c is not None:
8694
self.i2c = i2c
8795
else:
88-
self.i2c = I2C(0, mode=I2C.MASTER, pins=(sda, scl), baudrate=100000)
96+
self.i2c = I2C(0, mode=I2C.MASTER, pins=(sda, scl))
97+
98+
if board_type not in self.BOARD_TYPE_SET:
99+
raise Exception('Board type not in the set {}'.format(self.BOARD_TYPE_SET))
89100

90101
self.sda = sda
91102
self.scl = scl
103+
self.board_type = board_type
92104
self.clk_cal_factor = 1
93105
self.reg = bytearray(6)
94106
self.wake_int = False
@@ -202,11 +214,14 @@ def setup_sleep(self, time_s):
202214
self._write(bytes([CMD_SETUP_SLEEP, time_s & 0xFF, (time_s >> 8) & 0xFF, (time_s >> 16) & 0xFF]))
203215

204216
def go_to_sleep(self, gps=True):
205-
# enable or disable back-up power to the GPS receiver
206-
if gps:
217+
# if we have a Pytrack then enable or disable back-up power to the GPS receiver
218+
if self.board_type == self.PYTRACK and gps:
219+
# disable GPS only if Pytrack
207220
self.set_bits_in_memory(PORTC_ADDR, 1 << 7)
208221
else:
222+
# Pysense or Pyscan or no GPS
209223
self.mask_bits_in_memory(PORTC_ADDR, ~(1 << 7))
224+
210225
# disable the ADC
211226
self.poke_memory(ADCON0_ADDR, 0)
212227

@@ -245,7 +260,7 @@ def calibrate_rtc(self):
245260
self.i2c.deinit()
246261
Pin('P21', mode=Pin.IN)
247262
pulses = pycom.pulses_get('P21', 100)
248-
self.i2c.init(mode=I2C.MASTER, pins=(self.sda, self.scl), baudrate=100000)
263+
self.i2c.init(mode=I2C.MASTER, pins=(self.sda, self.scl))
249264
idx = 0
250265
for i in range(len(pulses)):
251266
if pulses[i][1] > EXP_RTC_PERIOD:

pymesh/pymesh_frozen/lib/loramesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def neighbors_update(self):
300300
# pass
301301
# add own info in dict
302302
#self.neigh_dict[self.MAC] = (0, self.rloc16, self.state, 0)
303-
print("Neighbors: %s"%(self.router_data.to_string()))
303+
print_debug(5, "Neighbors: %s"%(self.router_data.to_string()))
304304
return
305305

306306
def leader_add_own_neigh(self):

pyscan/lib/pyscan.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright (c) 2020, Pycom Limited.
4+
#
5+
# This software is licensed under the GNU GPL version 3 or any
6+
# later version, with permitted additional terms. For more information
7+
# see the Pycom Licence v1.0 document supplied with this file, or
8+
# available at https://www.pycom.io/opensource/licensing
9+
#
10+
111
from pycoproc import Pycoproc
212

3-
__version__ = '1.0.0'
13+
__version__ = '1.0.1'
414

515
class Pyscan(Pycoproc):
616

717
def __init__(self, i2c=None, sda='P22', scl='P21'):
8-
Pycoproc.__init__(self, i2c, sda, scl)
18+
Pycoproc.__init__(self, Pycoproc.PYSCAN, i2c, sda, scl)

pysense/lib/LIS2HH12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information

pysense/lib/LTR329ALS01.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information

pysense/lib/MPL3115A2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information

pysense/lib/pysense.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information
77
# see the Pycom Licence v1.0 document supplied with this file, or
88
# available at https://www.pycom.io/opensource/licensing
99
#
1010

11+
# See https://docs.pycom.io for more information regarding library specifics
12+
1113
from pycoproc import Pycoproc
1214

13-
__version__ = '1.4.0'
15+
__version__ = '1.4.1'
1416

1517
class Pysense(Pycoproc):
1618

1719
def __init__(self, i2c=None, sda='P22', scl='P21'):
18-
Pycoproc.__init__(self, i2c, sda, scl)
20+
Pycoproc.__init__(self, Pycoproc.PYSENSE, i2c, sda, scl)

pysense/main.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information
@@ -10,32 +10,45 @@
1010

1111
# See https://docs.pycom.io for more information regarding library specifics
1212

13+
import time
14+
import pycom
1315
from pysense import Pysense
16+
import machine
17+
1418
from LIS2HH12 import LIS2HH12
1519
from SI7006A20 import SI7006A20
1620
from LTR329ALS01 import LTR329ALS01
1721
from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE
1822

23+
pycom.heartbeat(False)
24+
pycom.rgbled(0x0A0A08) # white
25+
1926
py = Pysense()
20-
mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
21-
si = SI7006A20(py)
22-
lt = LTR329ALS01(py)
23-
li = LIS2HH12(py)
2427

28+
mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
2529
print("MPL3115A2 temperature: " + str(mp.temperature()))
2630
print("Altitude: " + str(mp.altitude()))
2731
mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
2832
print("Pressure: " + str(mpp.pressure()))
2933

34+
35+
si = SI7006A20(py)
3036
print("Temperature: " + str(si.temperature())+ " deg C and Relative Humidity: " + str(si.humidity()) + " %RH")
3137
print("Dew point: "+ str(si.dew_point()) + " deg C")
3238
t_ambient = 24.4
3339
print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH")
3440

41+
42+
lt = LTR329ALS01(py)
3543
print("Light (channel Blue lux, channel Red lux): " + str(lt.light()))
3644

45+
li = LIS2HH12(py)
3746
print("Acceleration: " + str(li.acceleration()))
3847
print("Roll: " + str(li.roll()))
3948
print("Pitch: " + str(li.pitch()))
4049

4150
print("Battery voltage: " + str(py.read_battery_voltage()))
51+
52+
time.sleep(3)
53+
py.setup_sleep(10)
54+
py.go_to_sleep()

pytrack/lib/LIS2HH12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information

pytrack/lib/pytrack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright (c) 2019, Pycom Limited.
3+
# Copyright (c) 2020, Pycom Limited.
44
#
55
# This software is licensed under the GNU GPL version 3 or any
66
# later version, with permitted additional terms. For more information
@@ -10,9 +10,9 @@
1010

1111
from pycoproc import Pycoproc
1212

13-
__version__ = '1.4.0'
13+
__version__ = '1.4.1'
1414

1515
class Pytrack(Pycoproc):
1616

1717
def __init__(self, i2c=None, sda='P22', scl='P21'):
18-
Pycoproc.__init__(self, i2c, sda, scl)
18+
Pycoproc.__init__(self, Pycoproc.PYTRACK, i2c, sda, scl)

0 commit comments

Comments
 (0)