<reponame>DiamondLightSource/rpi-config
import sys    
import os
import time
from gda.factory import Finder
from gda.configuration.properties import LocalProperties
from gdascripts.messages import handle_messages
from gda.jython import InterfaceProvider
from gda.device.scannable import ScannableBase
#Raspberry Pi Specific
import rpiComms
import rpiScannable
import arduinoScannable
from rpiComms import initaliseCommunicator
import arduinoMotor
import rpiCameraScannable
#End of Raspberry Pi Specific
        
def isLive():
    mode = LocalProperties.get("gda.mode")
    return mode =="live"

try:
    from gda.device import Scannable
    from gda.jython.commands.GeneralCommands import ls_names, vararg_alias
    
    def ls_scannables():
        ls_names(Scannable)
    
    alias("ls_scannables")


    from epics_scripts.pv_scannable_utils import createPVScannable, caput, caget
    alias("createPVScannable")
    alias("caput")
    alias("caget")
    
    from gda.scan.RepeatScan import create_repscan, repscan
    vararg_alias("repscan")

    #setup tools to create metadata in Nexus files
    from gdascripts.metadata.metadata_commands import setTitle, meta_add, meta_ll, meta_ls, meta_rm
    alias("setTitle")
    alias("meta_add")
    alias("meta_ll")
    alias("meta_ls")
    alias("meta_rm")
    from gda.data.scan.datawriter import NexusDataWriter
    LocalProperties.set(NexusDataWriter.GDA_NEXUS_METADATAPROVIDER_NAME,"metashop")
    
    #create time scannables
    from gdascripts.pd.time_pds import waittimeClass2, showtimeClass, showincrementaltimeClass, actualTimeClass
    waittime=waittimeClass2('waittime')
    showtime=showtimeClass('showtime')
    inctime=showincrementaltimeClass('inctime')
    actualTime=actualTimeClass("actualTime")
    
    #===================================================
    #Raspberry Pi Specific Objects
    #===================================================
    #RPi Communication Interface
    rpiComms.initaliseCommunicator("127.0.0.1") #enter the Pi's IP address, 127.0.0.1 (localhost) should work

    #PiCamera Interface
    PiCamera = rpiCameraScannable.rpiCameraScannable("picamera") 
   
    #GPIO Devices
    led1=rpiScannable.rpiScannable("LED1", 29, "output")
    button1=rpiScannable.rpiScannable("BUTTON1", 28, "input")
    
    #Arduino Devices
    UNOpwm1 = arduinoScannable.arduinoScannable("UNOpwm1", 3, "arduino-01","p")
    UNObutton1 = arduinoScannable.arduinoScannable("UNObutton1", 12, "arduino-01", "i")
    UNOanalog1 = arduinoScannable.arduinoScannable("UNOanalog1", 2, "arduino-01", "a")
    
    UNOmotor1a = arduinoScannable.arduinoScannable("UNOmotor1a", 8, "arduino-01", "o")
    UNOmotor1b = arduinoScannable.arduinoScannable("UNOmotor1b", 9, "arduino-01", "o")
    UNOmotor1c = arduinoScannable.arduinoScannable("UNOmotor1c", 10, "arduino-01", "o")
    UNOmotor1d = arduinoScannable.arduinoScannable("UNOmotor1d", 11, "arduino-01", "o")
    UNOmotor1 = arduinoMotor.arduinoMotor("UNOmotor1", 4096, UNOmotor1a, UNOmotor1b, UNOmotor1c, UNOmotor1d)

    #===================================================
    #End of Raspberry Pi Specific Objects
    #===================================================

    #run user editable startup script 
    if isLive():
        run("localStationUser.py")

except:
    exceptionType, exception, traceback = sys.exc_info()
    handle_messages.log(None, "Error in localStation", exceptionType, exception, traceback, False)


import sys    
import os
import time
from gda.factory import Finder
from gda.configuration.properties import LocalProperties
from gdascripts.messages import handle_messages
from gda.jython import InterfaceProvider
from gda.device.scannable import ScannableBase
#Raspberry Pi Specific
import rpiComms
import rpiScannable
import arduinoScannable
from rpiComms import initaliseCommunicator
import arduinoMotor
import rpiCameraScannable
#End of Raspberry Pi Specific
        
def isLive():
    mode = LocalProperties.get("gda.mode")
    return mode =="live"

try:
    from gda.device import Scannable
    from gda.jython.commands.GeneralCommands import ls_names, vararg_alias
    
    def ls_scannables():
        ls_names(Scannable)
    
    alias("ls_scannables")


    from epics_scripts.pv_scannable_utils import createPVScannable, caput, caget
    alias("createPVScannable")
    alias("caput")
    alias("caget")
    
    from gda.scan.RepeatScan import create_repscan, repscan
    vararg_alias("repscan")

    #setup tools to create metadata in Nexus files
    from gdascripts.metadata.metadata_commands import setTitle, meta_add, meta_ll, meta_ls, meta_rm
    alias("setTitle")
    alias("meta_add")
    alias("meta_ll")
    alias("meta_ls")
    alias("meta_rm")
    from gda.data.scan.datawriter import NexusDataWriter
    LocalProperties.set(NexusDataWriter.GDA_NEXUS_METADATAPROVIDER_NAME,"metashop")
    
    #create time scannables
    from gdascripts.pd.time_pds import waittimeClass2, showtimeClass, showincrementaltimeClass, actualTimeClass
    waittime=waittimeClass2('waittime')
    showtime=showtimeClass('showtime')
    inctime=showincrementaltimeClass('inctime')
    actualTime=actualTimeClass("actualTime")
    
    #===================================================
    #Raspberry Pi Specific Objects
    #===================================================
    #RPi Communication Interface
    rpiComms.initaliseCommunicator("127.0.0.1") #enter the Pi's IP address, 127.0.0.1 (localhost) should work

    #PiCamera Interface
    PiCamera = rpiCameraScannable.rpiCameraScannable("picamera") 
   
    #GPIO Devices
    led1=rpiScannable.rpiScannable("LED1", 29, "output")
    button1=rpiScannable.rpiScannable("BUTTON1", 28, "input")
    
    #Arduino Devices
    UNOpwm1 = arduinoScannable.arduinoScannable("UNOpwm1", 3, "arduino-01","p")
    UNObutton1 = arduinoScannable.arduinoScannable("UNObutton1", 12, "arduino-01", "i")
    UNOanalog1 = arduinoScannable.arduinoScannable("UNOanalog1", 2, "arduino-01", "a")
    
    UNOmotor1a = arduinoScannable.arduinoScannable("UNOmotor1a", 8, "arduino-01", "o")
    UNOmotor1b = arduinoScannable.arduinoScannable("UNOmotor1b", 9, "arduino-01", "o")
    UNOmotor1c = arduinoScannable.arduinoScannable("UNOmotor1c", 10, "arduino-01", "o")
    UNOmotor1d = arduinoScannable.arduinoScannable("UNOmotor1d", 11, "arduino-01", "o")
    UNOmotor1 = arduinoMotor.arduinoMotor("UNOmotor1", 4096, UNOmotor1a, UNOmotor1b, UNOmotor1c, UNOmotor1d)

    #===================================================
    #End of Raspberry Pi Specific Objects
    #===================================================

    #run user editable startup script 
    if isLive():
        run("localStationUser.py")

except:
    exceptionType, exception, traceback = sys.exc_info()
    handle_messages.log(None, "Error in localStation", exceptionType, exception, traceback, False)
#Raspberry Pi Specific #End of Raspberry Pi Specific #setup tools to create metadata in Nexus files #create time scannables #=================================================== #Raspberry Pi Specific Objects #=================================================== #RPi Communication Interface #enter the Pi's IP address, 127.0.0.1 (localhost) should work #PiCamera Interface #GPIO Devices #Arduino Devices #=================================================== #End of Raspberry Pi Specific Objects #=================================================== #run user editable startup script