-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpytimex_test.py
66 lines (47 loc) · 1.34 KB
/
pytimex_test.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
# Tests out the library and blasts some data
import sys
import pytimex
def listhex(pkg):
return ', '.join(["0x{:02x}".format(b) for b in pkg])
# Setup data to be sent
d = pytimex.TimexData()
# Try all the features!
a = d.addNewAppointment(5, 31, 0x27, "meet a guy? ")
d.addNewTodo(3, "buy coffee")
d.addNewTodo(12, "code stuff") # Priority C
d.addNewPhoneNumber("5P4C3", "e.t. home")
d.addNewPhoneNumber("0722339677", "some guy")
d.addNewAnniversary(6, 6, "national day")
# You can modify the objects from above later:
a.label = "funny meeting"
# Setup two timezones
d.setTimezone(1, +2, 24, "cet")
d.setTimezone(2, 0, 24, "utc")
d.sendTime = True
# Add some alarms.
# You can overwrite them individually, but currently I have no way of specifying
# alarm ID here.
d.addNewAlarm(7,0,0,0,"wake up@",True)
d.addNewAlarm(hour=10, minute=15, month=0, day=30, label="monthly meeting", audible=True)
# Get data to be transferred
data = bytes(d)
# Show data, for debugging
print("Data to be blasted:")
print(listhex(data))
print("")
try:
port = sys.argv[1]
except:
port = "/dev/ttyACM0"
# Initialize blaster
b = pytimex.Blaster(port)
if not b.identify():
print("Could not verify adapter :(")
sys.exit(-1)
print("Sending data...")
# Send synchronization bytes (0x55 and 0xAA)
b.send_sync()
# Blast data
for databyte in data:
b.blast(databyte)
print("Done!")