-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino4impress_uno.py
executable file
·58 lines (46 loc) · 1.65 KB
/
arduino4impress_uno.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
#!/usr/bin/env python
"""
This ugly beast reads values in the 0-99 range from a serial port and
shows a slide of an running OpenOffice/LibreOffice presentation accordingly.
Copyright: 2012, Davide Alberani <da@erlug.linux.it>
License: GPLv3
"""
import uno
import time
import serial
SP_DEV = '/dev/ttyACM0'
SP_BAUD = 9600
SLEEP_TIME = 1
# Please run OpenOffice with something like:
# soffice --impress --accept="socket,host=localhost,port=2002;urp;" impress_file.odp
UNO_URL_RESOLVER = "com.sun.star.bridge.UnoUrlResolver"
COMPONENT_CONTEXT = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
DESKTOP = "com.sun.star.frame.Desktop"
def run():
"""Born to rune!"""
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext(UNO_URL_RESOLVER,
local)
context = resolver.resolve(COMPONENT_CONTEXT)
desktop = context.ServiceManager.createInstanceWithContext(DESKTOP,
context)
document = desktop.getCurrentComponent()
presentation = document.Presentation
controller = presentation.getController()
currentSlideIdx = controller.getCurrentSlideIndex()
pages = controller.getCount()
ser = serial.Serial(SP_DEV, SP_BAUD)
while True:
time.sleep(SLEEP_TIME)
potValue = ser.readline().strip()
try:
potValue = int(potValue)
except (ValueError, TypeError):
continue
nextSlideIdx = int(round(potValue * (pages - 1) / 99.))
if nextSlideIdx == currentSlideIdx:
continue
controller.gotoSlideIndex(nextSlideIdx)
currentSlideIdx = nextSlideIdx
if __name__ == '__main__':
run()