-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·134 lines (88 loc) · 3.53 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
from __future__ import print_function
import stretchSenseLibrary
"""
- Website : https://www.stretchsense.com
- Important : This StretchSense Library has been designed to enable the connection of one or more "StretchSense Sensor" and "StretchSense IC Boards" to your Raspberry Pi
- Author : Louis Germain
- Copyright : 2017 StretchSense
- Date : 26/07/2017
- Version : 1.0.0
"""
stretchsenseObject = stretchSenseLibrary.StretchSenseAPI()
BLE_MODE = 0x00
SPI_MODE = 0x01
def mainBle():
#print("mainBle()")
"""
BLE main example.
Those following lines are used to connect every StretchSense devices around and then stream
their values into a terminal in a .csv format.
Make sure that timeBreak is superior to 0, and the program will run for the processor time you gave him.
Make sure that the correct BLE_MODE is selected at the end of the file.
To run the mainBle() function open a terminal, go to the folder where main.py file is
located.
And enter the following command line :
$ sudo python3 main.py
"""
def updateValue():
print("updateValues()")
timePassed = stretchSenseLibrary.time.clock()
timeBreak = 5 # Choose the processor time to finish the program
if timePassed < timeBreak:
stretchsenseObject.ble_waitNotifications()
stretchsenseObject.ble_listToCsv()
stretchSenseLibrary.time.sleep(0.1)
else:
t.stop()
pass
timeToScan = 3
stretchsenseObject.ble_scanning(timeToScan)
stretchsenseObject.ble_printAllPeripheralsAvailable()
stretchsenseObject.ble_connectAllPeripheral()
stretchsenseObject.waitNotifications()
stretchsenseObject.ble_listToCsv()
numberOfPeripheralConnected = len(stretchsenseObject.ble_getListPeripheralIsConnected())
if numberOfPeripheralConnected > 0:
t = stretchSenseLibrary.RepeatedTimer(0.01, lambda: updateValue())
else:
pass
def mainSpi():
#print("mainSpi()")
"""
SPI main example.
Those following lines are used to stream the values of a 16FGV1.0 device from StretchSense,
connected to the SPI0 port of a Raspberry Pi .
Make sure that timeBreak is superior than 0, and the program will run for the processor time you gave him.
Make sure that the correct SPI_MODE is selected at the end of the file.
To run the mainSpi() function open a terminal, go to the folder where main.py file is
located.
And enter the following command line :
$ sudo python3 main.py
"""
def updateValueSpi():
#print("updateValueSpi()")
timePassed = stretchSenseLibrary.time.clock()
timeBreak = 5 # Choose the processor time to finish the program
if timePassed < timeBreak:
stretchsenseObject.spi_continuousModeCapacitance()
stretchsenseObject.spi_listToCsv()
stretchSenseLibrary.time.sleep(0.1)
else:
stretchsenseObject.spi_close()
t.stop()
pass
stretchsenseObject.spi_setup()
numberOfSpiPeripheralConnected = len(stretchsenseObject.spi_getListPeripheral())
if numberOfSpiPeripheralConnected > 0:
t = stretchSenseLibrary.RepeatedTimer(0.01, lambda: updateValueSpi())
else:
pass
if __name__ == "__main__":
mode = SPI_MODE
if mode == SPI_MODE:
mainSpi()
elif mode == BLE_MODE:
mainBle()
else:
pass