-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi_device.py
40 lines (31 loc) · 997 Bytes
/
pi_device.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
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 16 13:32:08 2020
@author: ingvord
"""
import os
import time
from gcsdevice import GCSDevice
kModeIsProduction = os.getenv('MODE', default='simulation') == 'production'
if kModeIsProduction:
from pipython.pidevice.gcscommands import GCSCommands
from pipython.pidevice.gcsmessages import GCSMessages
from pipython.pidevice.interfaces.pisocket import PISocket
def create_pi_device(host, port=50000):
if host is None:
raise Exception('host must not be None!')
if kModeIsProduction:
gateway = PISocket(host, port)
messages = GCSMessages(gateway)
pi_device = GCSCommands(messages)
connected = False
while not connected:
time.sleep(0.01)
connected = messages.connected
ready = False
while not ready:
time.sleep(0.01)
ready = pi_device.IsControllerReady()
return pi_device
else:
return GCSDevice()