Best Python code snippet using pyatom_python
main.py
Source:main.py  
1import kivy2#kivy.require('1.0.6')3from kivy.app import App4from kivy.uix.button import Button5from kivy.uix.togglebutton import ToggleButton6from kivy.uix.gridlayout import GridLayout7from kivy.uix.boxlayout import BoxLayout8from kivy.uix.image import Image9from kivy.uix.slider import Slider10from kivy.uix.switch import Switch11from kivy.clock import Clock12from kivy.graphics import Color, Rectangle13from kivy.uix.widget import Widget14from kivy.graphics import Color, Line15from kivy.uix.floatlayout import FloatLayout16from kivy.uix.anchorlayout import AnchorLayout17from math import cos, sin, pi18from kivy.clock import Clock19from kivy.lang import Builder20from kivy.properties import NumericProperty, StringProperty, BooleanProperty, ListProperty, ObjectProperty21from kivy.uix.label import Label22from kivy.logger import Logger23from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition, SlideTransition24from kivy.animation import Animation25from kivy.core.window import Window26from kivy.uix.scatter import Scatter27from kivy.uix.relativelayout import RelativeLayout28from kivy.uix.image import AsyncImage29from kivy.app import App30from kivy.lang import Builder31from kivy.metrics import dp32from kivy.properties import ObjectProperty33from kivy.uix.image import Image34from kivymd.button import MDIconButton35from kivymd.label import MDLabel36from kivymd.list import ILeftBody, ILeftBodyTouch, IRightBodyTouch37from kivymd.theming import ThemeManager38from kivymd.dialog import MDDialog39import kivymd.snackbar as Snackbar40import os41os.environ["KIVY_IMAGE"]="pil"42#from kivy.garden.mapview import MapView43#I know global variables are the devil....but they are so easy44#set to 1 to disable all GPIO, temp probe, and obd stuff45global developermode46developermode = 147global devtaps #used to keep track of taps on settings label - 5 will force devmode48devtaps = 049global version50version = "V2.3.0"51#10/20/201752#Created by Joel Zeller53# For PC dev work -----------------------54if developermode == 1:55    from kivy.config import Config56    Config.set('graphics', 'width', '800')57    Config.set('graphics', 'height', '480')58    from kivy.core.window import Window59    Window.size = (800, 480)60# ---------------------------------------61if developermode == 0:62    import RPi.GPIO as GPIO63    import obd64    import serial65global adxl34566import sys67import datetime68import time69import os70import subprocess71import glob72import math73import socket74import pickle75#IP address in System Diagnostics76cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"77def get_ip_address():78    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)79    s.connect(("8.8.8.8", 80))80    return s.getsockname()[0]81global ip82try:83    ip = get_ip_address()84except:85    ip = "No IP address found..."86#AutoBrightness on Boot #set to 1 if you have the newer RPi display and want autobrightness87                        #set to 0 if you do not or do not want autobrightness88                        #adjust to suit your needs :)89global autobrightness90autobrightness = 091if developermode == 0:92    if autobrightness == 1: #temporary method93        currenthour = int(time.strftime("%-H")) #hour as decimal (24hour)94        if currenthour < 7 or currenthour > 21: #earlier than 7am and later than 9pm -> dim screen on start95            print "dim"96            os.system("sudo echo 15 > /sys/class/backlight/rpi_backlight/brightness")  # sets screen brightness to ~ 10%97        if currenthour >= 7 and currenthour <= 20: #later than 7am and before 8pm -> full bright on start98            print "bright"99            os.system("sudo echo 175 > /sys/class/backlight/rpi_backlight/brightness")  # sets screen brightness to ~ 100%100#_____________________________________________________________101#GPIO SETUP102#name GPIO pins103seekupPin = 13104seekdownPin = 19105auxPin = 16106amfmPin = 26107garagePin = 20108radarPin = 21109ledsPin = 5110driverwindowdownPin = 17  111driverwindowupPin = 15 112passwindowdownPin = 27 113passwindowupPin = 18 114HotKey1Pin = 12115HotKey2Pin = 6116if developermode == 0:117    GPIO.setmode(GPIO.BCM)118    GPIO.setwarnings(False)119    GPIO.setup(seekupPin, GPIO.OUT)120    GPIO.setup(seekdownPin, GPIO.OUT)121    GPIO.setup(auxPin, GPIO.OUT)122    GPIO.setup(amfmPin, GPIO.OUT)123    GPIO.setup(garagePin, GPIO.OUT)124    GPIO.setup(radarPin, GPIO.OUT)125    GPIO.setup(ledsPin, GPIO.OUT)126    GPIO.setup(driverwindowdownPin, GPIO.OUT)127    GPIO.setup(driverwindowupPin, GPIO.OUT)128    GPIO.setup(passwindowdownPin, GPIO.OUT)129    GPIO.setup(passwindowupPin, GPIO.OUT)130    GPIO.setup(HotKey1Pin, GPIO.IN)131    GPIO.setup(HotKey2Pin, GPIO.IN)132#initial state of GPIO133    GPIO.output(seekupPin, GPIO.HIGH)134    GPIO.output(seekdownPin, GPIO.HIGH)135    GPIO.output(auxPin, GPIO.HIGH)136    GPIO.output(amfmPin, GPIO.HIGH)137    GPIO.output(garagePin, GPIO.HIGH)138    GPIO.output(radarPin, GPIO.HIGH)139    GPIO.output(ledsPin, GPIO.LOW)140    GPIO.output(driverwindowdownPin, GPIO.HIGH)141    GPIO.output(driverwindowupPin, GPIO.HIGH)142    GPIO.output(passwindowdownPin, GPIO.HIGH)143    GPIO.output(passwindowupPin, GPIO.HIGH)144#_________________________________________________________________145#OBD STUFF146global OBDON #var for displaying obd gauges147OBDVAR = "NONE"148#0 - OFF149#1 - Digital Speed150#2 - Digital Tach151#3 - Graphic152#4 - Coolant Temp153#5 - Intake Temp154#6 - Engine Load155#7 - Throttle Pos156#8 - Intake Pressure157#_________________________________________________________________158#TEMP PROBE STUFF159global TempProbePresent #set to 1 if temp probe is connected, 0 if not160TempProbePresent = 1161global AccelPresent #set to 1 if adxl345 accelerometer is present162AccelPresent = 1163global accelxmaxpos164global accelxmaxneg165global accelymaxpos166global accelymaxneg167accelxmaxpos = 0168accelxmaxneg = 0169accelymaxpos = 0170accelymaxneg = 0171if developermode == 1:172    TempProbePresent = 0173    AccelPresent = 0174if AccelPresent == 1:175    try:176        from adxl345 import ADXL345177        adxl345 = ADXL345()178    except:179        print "Failed to initialize accelerometer."180        AccelPresent = 0181if TempProbePresent == 1:182    try:183        os.system('modprobe w1-gpio')184        os.system('modprobe w1-therm')185        base_dir = '/sys/bus/w1/devices/'186        device_folder = glob.glob(base_dir + '28*')[0]187        device_file = device_folder + '/w1_slave'188    except:189        print "Failed to initialize temperature sensor."190        TempProbePresent = 0191global temp_f #make this var global for use in messages192temp_f = 0193global TEMPON #var for displaying cabin temp widget194TEMPON = 0195global ACCELON196ACCELON = 0197if developermode == 0:198    os.system('pulseaudio --start') #start the pulseaudio daemon199global bluetoothdevicemac200bluetoothdevicemac = 'AC_37_43_D7_65_B4' #Enter your smartphones bluetooth mac address here so its audio can be controlled from the audio app201#iphone: F0_D1_A9_C9_86_3E202#HTCM8: 2C_8A_72_19_0F_F4203#HTC10: AC_37_43_D7_65_B4204global BLUETOOTHON205BLUETOOTHON = 1206global DISPLAYBTDATA207DISPLAYBTDATA = 0208global bluetoothdata209bluetoothdata = ['','','','','','','','','','','',''] #Default - only shown when bluetooth enabled210def read_temp_raw():211    f = open(device_file, 'r')212    lines = f.readlines()213    f.close()214    return lines215 216def read_temp():217    global temp_f218    lines = read_temp_raw()219    while lines[0].strip()[-3:] != 'YES':220        #time.sleep(0.2)221        lines = read_temp_raw()222    equals_pos = lines[1].find('t=')223    if equals_pos != -1:224        temp_string = lines[1][equals_pos+2:]225        temp_c_raw = float(temp_string) / 1000.0226        temp_f_raw = temp_c_raw * 9.0 / 5.0 + 32.0227        temp_f = "{0:.0f}".format(temp_f_raw) #only whole numbers228#_________________________________________________________________229#VARIABLES230#varibles from text file:231global theme232global wallpaper233global hotkey1string234global hotkey2string235global oildatemonth236global oildateday237global oildateyear238global oilmileage239global oilnotify240global speedlimit241global rpmredline242f = open('savedata.txt', 'r+') # read from text file243theme = f.readline()244theme = theme.rstrip() #to remove \n from string245wallpaper = int(f.readline())246hotkey1string = f.readline()247hotkey1string = hotkey1string.rstrip()248hotkey2string = f.readline()249hotkey2string = hotkey2string.rstrip()250oildatemonth = int(f.readline())251oildateday = int(f.readline())252oildateyear = int(f.readline())253oilmileage = int(f.readline())254oilnotify = int(f.readline())255speedlimit = int(f.readline())256rpmredline = int(f.readline())257f.close()258global SEEKUPON 259SEEKUPON = 0260global SEEKDOWNON 261SEEKDOWNON = 0262global AUXON 263AUXON = 0264global AMFMON 265AMFMON = 0266global GARAGEON 267GARAGEON = 0268global RADARON 269RADARON = 0270global LEDSON 271LEDSON = 0272global WINDOWSDOWNON 273WINDOWSDOWNON = 0274global WINDOWSUPON 275WINDOWSUPON = 0276# window debug vars277global DRIVERUPON278DRIVERUPON = 0279global DRIVERDOWNON280DRIVERDOWNON = 0281global PASSENGERUPON282PASSENGERUPON = 0283global PASSENGERDOWNON284PASSENGERDOWNON = 0285global clock286clock = 0287global analog288analog = 1289global message290message = 0291global swminute292swminute = 0293global swsecond294swsecond = 0295global swtenth296swtenth = 0297global swactive298swactive = 0299global swstring300swstring = 0301global testvar302testvar = 0303global testvar2304testvar2 = 0305global screenon306screenon = 1307global windowuptime #time it takes front windows to rise (secs)308windowuptime = 7309global windowdowntime #time it takes front windows to open (secs)310windowdowntime = 6311global clocktheme312clocktheme = 2313global launch_start_time314launch_start_time = 0315global animation_start_time316animation_start_time = 0317global time_second_mod318time_second_mod = 0319#OBD Global vars320global OBDconnection321OBDconnection = 0 #connection is off by default - will be turned on in obd page322global OBDpage323OBDpage = 0 #start obd page in gauge select324global cmd_RPM325global cmd_SPEED326global cmd_CoolantTemp327global cmd_IntakeTemp328global cmd_Load329global cmd_ThrottlePos330global cmd_IntakePressure331global maxRPM332maxRPM = 0333global devobd334devobd = 0335global incobd #amount to step in dev mode - obd pages336incobd = 1337global changeoil338changeoil = 0339if oilnotify == 1:340    if int(time.strftime("%Y")) > oildateyear:341        changeoil = 1342    if int(time.strftime("%m")) >= oildatemonth:343        if int(time.strftime("%Y")) > oildateyear:344            changeoil = 1345    if int(time.strftime("%d")) >= oildateday:346        if int(time.strftime("%m")) >= oildatemonth:347            if int(time.strftime("%Y")) >= oildateyear:348                changeoil = 1349#__________________________________________________________________350#HOTKEY STUFF351def HotKey1(channel):352    global hotkey1string353    global screenon354    global windowuptime355    global windowdowntime356    global WINDOWSUPON357    global WINDOWSDOWNON358    if hotkey1string == "Seek Up":359        if BLUETOOTHON == 0:360            Clock.schedule_once(seekup_callback)361            Clock.schedule_once(seekup_callback,.1)362        if BLUETOOTHON == 1:363            try:364                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_'+bluetoothdevicemac+'/player0 org.bluez.MediaPlayer1.Next')365            except:366                print "can't next"367    if hotkey1string == "Seek Down":368        if BLUETOOTHON == 0:369            Clock.schedule_once(seekdown_callback)370            Clock.schedule_once(seekdown_callback,.1)371        if BLUETOOTHON == 1:372            try:373                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_'+bluetoothdevicemac+'/player0 org.bluez.MediaPlayer1.Previous')374            except:375                print "can't prev"376    if hotkey1string == "Garage":377        Clock.schedule_once(garage_callback)378        Clock.schedule_once(garage_callback,.1)379    if hotkey1string == "Radar":380        Clock.schedule_once(radar_callback)381    if hotkey1string == "Cup Lights":382        Clock.schedule_once(leds_callback)383    if hotkey1string == "Windows Up":384        if WINDOWSDOWNON == 0: #only works when windows down isnt running385            Clock.schedule_once(windowsup_callback)386            Clock.schedule_once(windowsupOFF_callback, windowuptime)387            return388        if WINDOWSUPON == 1:389            Clock.schedule_once(windowsupOFF_callback) #if windows going up while pushed, will cancel and stop windows390    if hotkey1string == "Windows Down":391        if WINDOWSUPON == 0: #only works when windows up isnt running392            Clock.schedule_once(windowsdown_callback)393            Clock.schedule_once(windowsdownOFF_callback, windowdowntime)394            return395        if WINDOWSDOWNON == 1:396            Clock.schedule_once(windowsdownOFF_callback) #if windows going down while pushed, will cancel and stop windows397    if hotkey1string == "Screen Toggle":398        if screenon == 1:399            os.system("sudo echo 1 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen off400            screenon = 0401            return402        if screenon == 0:403            os.system("sudo echo 0 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen on404            screenon = 1405            return406    if hotkey1string == "None":407        return408    409def HotKey2(channel):410    global hotkey2string411    global screenon412    global windowuptime413    global windowdowntime414    global WINDOWSUPON415    global WINDOWSDOWNON416    if hotkey2string == "Seek Up":417        if BLUETOOTHON == 0:418            Clock.schedule_once(seekup_callback)419            Clock.schedule_once(seekup_callback, .1)420        if BLUETOOTHON == 1:421            try:422                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_' + bluetoothdevicemac + '/player0 org.bluez.MediaPlayer1.Next')423            except:424                print "can't next"425    if hotkey2string == "Seek Down":426        if BLUETOOTHON == 0:427            Clock.schedule_once(seekdown_callback)428            Clock.schedule_once(seekdown_callback, .1)429        if BLUETOOTHON == 1:430            try:431                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_' + bluetoothdevicemac + '/player0 org.bluez.MediaPlayer1.Previous')432            except:433                print "can't prev"434    if hotkey2string == "Garage":435        Clock.schedule_once(garage_callback)436        Clock.schedule_once(garage_callback,.1)437    if hotkey2string == "Radar":438        Clock.schedule_once(radar_callback)439    if hotkey2string == "Cup Lights":440        Clock.schedule_once(leds_callback)441    if hotkey2string == "Windows Up":442        if WINDOWSDOWNON == 0: #only works when windows down isnt running443            Clock.schedule_once(windowsup_callback)444            Clock.schedule_once(windowsupOFF_callback, windowuptime)445            return446        if WINDOWSUPON == 1:447            Clock.schedule_once(windowsupOFF_callback) #if windows going up while pushed, will cancel and stop windows448    if hotkey2string == "Windows Down":449        if WINDOWSUPON == 0: #only works when windows up isnt running450            Clock.schedule_once(windowsdown_callback)451            Clock.schedule_once(windowsdownOFF_callback, windowdowntime)452            return453        if WINDOWSDOWNON == 1:454            Clock.schedule_once(windowsdownOFF_callback) #if windows going down while pushed, will cancel and stop windows455    if hotkey2string == "Screen Toggle":456        if screenon == 1:457            os.system("sudo echo 1 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen off458            screenon = 0459            return460        if screenon == 0:461            os.system("sudo echo 0 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen on462            screenon = 1463            return464    if hotkey2string == "None":465        return466if developermode == 0:467    GPIO.add_event_detect(HotKey1Pin, GPIO.FALLING, callback=HotKey1, bouncetime=500)468    GPIO.add_event_detect(HotKey2Pin, GPIO.FALLING, callback=HotKey2, bouncetime=500)469#__________________________________________________________________470#DEFINE CLASSES471#ROOT CLASSES472class ROOT(FloatLayout):473    pass474class QUICKEYSLayout(FloatLayout):475    pass476        #MAIN SCREEN CLASSES477class MainScreen(Screen):478    pass479class AudioScreen(Screen):480    pass481class PerfScreen(Screen):482    pass483class AppsScreen(Screen):484    pass485class ControlsScreen(Screen):486    pass487class SettingsScreen(Screen):488    pass489class KillScreen(Screen):490    pass491        #APP SCREEN CLASSES492class PaintScreen(Screen):493    pass494class FilesScreen(Screen):495    pass496class LogoScreen(Screen):497    pass498class ClockChooserScreen(Screen):499    pass500class ClassicClockScreen(Screen):501    pass502class SportClockScreen(Screen):503    pass504class ExecutiveClockScreen(Screen):505    pass506class DayGaugeClockScreen(Screen):507    pass508class NightGaugeClockScreen(Screen):509    pass510class WormsClockScreen(Screen):511    pass512class InfoClockScreen(Screen):513    pass514class PhotoClockScreen(Screen):515    pass516class TestAppScreen(Screen):517    pass518class MaintenanceScreen(Screen):519    pass520class MaintenanceSetOilInfoScreen(Screen):521    pass522class GPSScreen(Screen):523    pass524class StopwatchScreen(Screen):525    pass526class DiagnosticsScreen(Screen):527    pass528class SystemDebugScreen(Screen):529    pass530class WindowDebugScreen(Screen):531    pass532class LaunchControlSetupScreen(Screen):533    pass534class LaunchControlScreen(Screen):535    pass536class PhotosScreen(Screen):537    pass538class GaugeSelectScreen(Screen):539    pass540class OBDTachsScreen(Screen):541    pass542class OBDSpeedosScreen(Screen):543    pass544class OBDDiagnosticsScreen(Screen):545    pass546class GaugeSelectScreen(Screen):547    pass548class GaugeSelectScreen(Screen):549    pass550class OBDDigitalSpeedoScreen(Screen):551    pass552class OBDDigitalTachScreen(Screen):553    pass554class OBDGraphicTachScreen(Screen):555    pass556class OBDGraphicTach2Screen(Screen):557    pass558class OBDCoolantScreen(Screen):559    pass560class OBDIntakeTempScreen(Screen):561    pass562class OBDLoadScreen(Screen):563    pass564class OBDThrottlePosScreen(Screen):565    pass566class OBDIntakePressureScreen(Screen):567    pass568class OBDSettingsScreen(Screen):569    pass570class AccelerometerScreen(Screen):571    pass572class NOSScreen(Screen):573    pass574class WallpaperSelectScreen(Screen):575    pass576class HotKey1ChooserScreen(Screen):577    pass578class HotKey2ChooserScreen(Screen):579    pass580class OffScreen(Screen):581    pass582#APP CLASSES583class Painter(Widget): #Paint App584    585    def on_touch_down(self, touch):586        with self.canvas:587            touch.ud["line"] = Line(points=(touch.x, touch.y))588    def on_touch_move(self, touch):589        touch.ud["line"].points += [touch.x, touch.y]590#_________________________________________________________________591#MAINAPP592class MainApp(App):593    theme_cls = ThemeManager()594    version = StringProperty()595    timenow = StringProperty()596    timenow_hour = NumericProperty(0)597    timenow_minute = NumericProperty(0)598    timenow_second = NumericProperty(0)599    launch_start_time = NumericProperty(0)600    time_second_mod = NumericProperty(0)601    datenow = StringProperty()602    daynow = StringProperty()603    yearnow = StringProperty()604    ampm = StringProperty()605    tempnow = StringProperty()606    CPUtempnow = StringProperty()607    corevoltagenow = StringProperty()608    stopwatchnow = StringProperty()609    stopwatchsecnow = ObjectProperty()610    stopwatchmilnow = ObjectProperty()611    HKonenow = StringProperty()612    HKtwonow = StringProperty()613    radariconsource = StringProperty()614    lightsiconsource = StringProperty()615    wallpapernow = StringProperty()616    obdspeed = StringProperty()617    obdspeedval = ObjectProperty()618    obdspeedlimitval = ObjectProperty(speedlimit)619    obdspeedmax = StringProperty()620    obdRPM = StringProperty()621    obdRPMval = NumericProperty(0)622    obdRPMmax = StringProperty()623    maxRPMvar = ObjectProperty()624    obdRPMredline = ObjectProperty(rpmredline)625    obdcoolanttemp = StringProperty()626    obdcoolanttempval = ObjectProperty()627    obdintaketemp = StringProperty()628    obdintakepressure = StringProperty()629    obdengineload = StringProperty()630    obdengineloadval = ObjectProperty()631    obdthrottlepos = StringProperty()632    obdthrottleposval = ObjectProperty()633    oildatemonth = ObjectProperty()634    oildateday = ObjectProperty()635    oildateyear = ObjectProperty()636    oilmileage = ObjectProperty()637    oilnotify = ObjectProperty()638    changeoil = ObjectProperty()639    ip = StringProperty()640    accelx = NumericProperty(0)641    accely = NumericProperty(0)642    accelxmaxpos = ObjectProperty()643    accelxmaxneg = ObjectProperty()644    accelymaxpos = ObjectProperty()645    accelymaxneg = ObjectProperty()646    bluetoothtitle = StringProperty()647    bluetoothartist = StringProperty()648    bluetoothduration = NumericProperty(0)649    bluetoothprogress = NumericProperty(0)650    theme_cls.theme_style = "Dark"651    #theme_cls.primary_palette = "Indigo"652    global theme653    theme_cls.primary_palette = theme654    def updatetime(self, *args):655        time = datetime.datetime.now()656        time_hour = time.strftime("%I")  # time_hour657        if time_hour[0] == "0":  # one digit format658            time_hour = " " + time_hour[1]659        time_minute = time.strftime("%M")  # time_minute660        timenow = time_hour + ":" + time_minute  # create sting format (hour:minute)661        self.timenow = timenow662        #self.timenow = "3:14" # for screenshots663        self.timenow_hour = time.hour664        self.timenow_minute = time.minute665        self.timenow_second = time.second666        global time_second_mod667        time_second_mod = int(float(time_second_mod)) + 1668        if time_second_mod > 10000000:  # doesnt allow this var to get too big669            time_second_mod = 0670        self.time_second_mod = time_second_mod671        global launch_start_time672        self.launch_start_time = launch_start_time673    def updatedate(self, *args):674        day = time.strftime("%A") #current day of week675        month = time.strftime("%B") #current month676        date = time.strftime("%d")  #current day of month677        year = time.strftime("%Y")  #current year678        ampm = time.strftime("%p")  #AM or PM679        if date[0] == "0":  # one digit format for day of month680            date = " " + date[1]681        datenow = month + " " + date682        self.datenow = datenow683        self.daynow = day684        self.yearnow = year685        self.ampm = ampm686    def updatetemp(self, *args):687        temp_f_string = str(temp_f)688        #if int(float(animation_start_time))+5 <= int(float(time_second_mod)): #animation is delayed for better asthetics689        global TEMPON690        if TEMPON == 1:691            if TempProbePresent == 1:692                    read_temp()693                    tempnow = " " + temp_f_string + u'\N{DEGREE SIGN}'694            if TempProbePresent == 0:695                    tempnow = " " + "72" + u'\N{DEGREE SIGN}'696        if TEMPON == 0:697            if TempProbePresent == 1:698                    tempnow = " " + temp_f_string + u'\N{DEGREE SIGN}'699            if TempProbePresent == 0:700                    tempnow = " " + "72" + u'\N{DEGREE SIGN}'701        self.tempnow = tempnow702    def updatevariables(self, *args):703        global swminute704        global swsecond705        global swtenth706        global swactive707        global swstring708        global swminutestring709        global swsecondstring710        global version711        global devtaps712        global OBDpage713        if swactive == 1:714            swtenth += 1715            if swtenth == 10:716                swtenth = 0717                swsecond += 1718            if swsecond == 60:719                swsecond = 0720                swminute += 1721        # fortmatting for stopwatch display - outside of if statement because watch will run in background722        if swsecond < 10:723            swsecondstring = "0" + str(swsecond)724        else:725            swsecondstring = str(swsecond)726        if swminute < 10:727            swminutestring = "0" + str(swminute)728        else:729            swminutestring = str(swminute)730        swstring = (swminutestring + ":" + swsecondstring + ":" + str(swtenth) + "0")731        #set vars732        self.stopwatchnow = swstring733        self.stopwatchsecnow = swsecond + (swtenth*.1)734        self.HKonenow = hotkey1string735        self.HKtwonow = hotkey2string736        self.version = version737        self.ip = ip738        self.devtaps = devtaps739        self.oildatemonth = oildatemonth740        self.oildateday = oildateday741        self.oildateyear = oildateyear742        self.oilmileage = oilmileage743        self.oilnotify = oilnotify744        self.changeoil = changeoil745        self.OBDpage = OBDpage746        global BLUETOOTHON747        if BLUETOOTHON == 1:748            if int(float(animation_start_time)) + 5 <= int(float(time_second_mod)):749                try:750                    if DISPLAYBTDATA == 1:751                        bluetoothdataraw = os.popen('dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0/dev_' + bluetoothdevicemac + '/player0 org.freedesktop.DBus.Properties.Get string:org.bluez.MediaPlayer1 string:Track').read()752                        bluetoothduration = int((bluetoothdataraw.split("uint32"))[1].split('\n')[0])753                        bluetoothprogressraw = os.popen('dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0/dev_' + bluetoothdevicemac + '/player0 org.freedesktop.DBus.Properties.Get string:org.bluez.MediaPlayer1 string:Position').read()754                        bluetoothprogress = int((bluetoothprogressraw.split("uint32"))[1].split('\n')[0])755                        bluetoothdata = bluetoothdataraw.split('"')[1::2]  # takes string and finds things in quotes756                        self.bluetoothtitle = bluetoothdata[1]757                        self.bluetoothartist = bluetoothdata[7]758                        self.bluetoothduration = bluetoothduration759                        self.bluetoothprogress = bluetoothprogress760                    else:761                        self.bluetoothtitle = ''762                        self.bluetoothartist = ''763                        self.bluetoothduration = 0764                        self.bluetoothprogress = 0765                except:766                    self.bluetoothtitle = ''767                    self.bluetoothartist = ''768                    self.bluetoothduration = 0769                    self.bluetoothprogress = 0770        if BLUETOOTHON == 0: #show nothing when bluetooth is off771            self.bluetoothtitle = ''772            self.bluetoothartist = ''773            self.bluetoothduration = 0774            self.bluetoothprogress = 0775        global theme776        theme = self.theme_cls.primary_palette777        if RADARON == 1:778            self.radariconsource = 'data/icons/radarindicator.png'779        if RADARON == 0:780            self.radariconsource = 'data/icons/null.png'781        if LEDSON == 1:782            self.lightsiconsource = 'data/icons/app_icons/lights_icon_on.png'783        if LEDSON == 0:784            self.lightsiconsource = 'data/icons/app_icons/lights_icon.png'785        if wallpaper == 0:786            self.wallpapernow = 'data/wallpapers/greenmaterial.png'787        if wallpaper == 1:788            self.wallpapernow = 'data/wallpapers/blackgreenmaterial.png'789        if wallpaper == 2:790            self.wallpapernow = 'data/wallpapers/darkgreymaterial2.png'791        if wallpaper == 3:792            self.wallpapernow = 'data/wallpapers/polymountain.png'793        if wallpaper == 4:794            self.wallpapernow = 'data/wallpapers/trianglematerial.png'795        if wallpaper == 5:796            self.wallpapernow = 'data/wallpapers/blackredmaterial.png'797        if wallpaper == 6:798            self.wallpapernow = 'data/wallpapers/greybluematerial.png'799        if wallpaper == 7:800            self.wallpapernow = 'data/wallpapers/lightblueblackmaterial.png'801        if wallpaper == 8:802            self.wallpapernow = 'data/wallpapers/greyplain.png'803        if wallpaper == 9:804            self.wallpapernow = 'data/wallpapers/stopwatchblue.png'805        if wallpaper == 10:806            self.wallpapernow = 'data/wallpapers/polycube.png'807        if wallpaper == 11:808            self.wallpapernow = 'data/wallpapers/polyvalley.png'809        if wallpaper == 12:810            self.wallpapernow = 'data/wallpapers/purplebluematerial.png'811        if wallpaper == 13:812            self.wallpapernow = 'data/wallpapers/bluegreymaterial.png'813        if wallpaper == 14:814            self.wallpapernow = 'data/wallpapers/redpurplematerial.png'815        if wallpaper == 15:816            self.wallpapernow = 'data/wallpapers/CoPilot_Wallpaper_2.png'817        if wallpaper == 16:818            self.wallpapernow = 'data/wallpapers/blackredmaterial2.png'819        if wallpaper == 17:820            self.wallpapernow = 'data/wallpapers/androidauto.png'821        if wallpaper == 18:822            self.wallpapernow = 'data/wallpapers/tealmaterialdesign.png'823        if wallpaper == 19:824            self.wallpapernow = 'data/wallpapers/blueblackmaterial.png'825        if wallpaper == 20:826            self.wallpapernow = 'data/wallpapers/greenmaterial2.png'827        if wallpaper == 21:828            self.wallpapernow = 'data/wallpapers/redbluematerial.png'829        if wallpaper == 22:830            self.wallpapernow = 'data/wallpapers/blueblackwhitematerial.png'831        if wallpaper == 23:832            self.wallpapernow = 'data/wallpapers/polymountain2.png'833        if wallpaper == 24:834            self.wallpapernow = 'data/wallpapers/blackpoly.png'835        if wallpaper == 25:836            self.wallpapernow = 'data/wallpapers/blackredlacematerial.png'837        if wallpaper == 26:838            self.wallpapernow = 'data/wallpapers/blueredpoly.png'839        if wallpaper == 27:840            self.wallpapernow = 'data/wallpapers/firewaterpoly.png'841        if wallpaper == 28:842            self.wallpapernow = 'data/wallpapers/tanbluepoly.png'843        if wallpaper == 29:844            self.wallpapernow = 'data/wallpapers/road.png'845        if wallpaper == 30:846            self.wallpapernow = 'data/wallpapers/road2.png'847        if wallpaper == 31:848            self.wallpapernow = 'data/wallpapers/pixel.png'849        if wallpaper == 32:850            self.wallpapernow = 'data/wallpapers/pixel2.png'851        if wallpaper == 33:852            self.wallpapernow = 'data/wallpapers/darkgreyplain.png'853        if wallpaper == 34:854            self.wallpapernow = 'data/wallpapers/city.png'855        if wallpaper == 35:856            self.wallpapernow = 'data/wallpapers/cincy.png'857        if wallpaper == 36:858            self.wallpapernow = 'data/wallpapers/grad1.png'859        if wallpaper == 37:860            self.wallpapernow = 'data/wallpapers/grad2.png'861        if wallpaper == 38:862            self.wallpapernow = 'data/wallpapers/smoke.png'863    def updatemessage(self, *args):864        # the logic for what the message says865        if message == 0:866            self.text = " "867        if message == 1:  # used for displaying the CPU temp868            if developermode == 0:869                temperaturestring = subprocess.check_output(["/opt/vc/bin/vcgencmd", "measure_temp"])870                corevoltagestring = subprocess.check_output(["/opt/vc/bin/vcgencmd", "measure_volts core"])871                temperature = (temperaturestring.split('=')[1][:-3])872                corevoltage = (corevoltagestring.split('=')[1][:-3])873                CPUtempnow = temperature + u'\N{DEGREE SIGN}' + "C"874                corevoltagenow = corevoltage + " V"875            if developermode == 1:876                CPUtempnow = "40" + u'\N{DEGREE SIGN}' + "C"877                corevoltagenow = "3.14" + " V"878            self.CPUtempnow = CPUtempnow879            self.corevoltagenow = corevoltagenow880    def updateaccel(self, *args):881        global ACCELON882        global accelxmaxpos883        global accelxmaxneg884        global accelymaxpos885        global accelymaxneg886        if ACCELON == 1:887            if AccelPresent == 1:888                axes = adxl345.getAxes(True)889                accelx = axes['x'] - .13  # compensation amount890                self.accelx = accelx891                accely = axes['y'] - .34  # compensation amount892                self.accely = accely893                if accelx > accelxmaxpos:894                    accelxmaxpos = accelx895                if accelx < accelxmaxneg:896                    accelxmaxneg = accelx897                if accely > accelymaxpos:898                    accelymaxpos = accely899                if accely < accelymaxneg:900                    accelymaxneg = accely901                self.accelxmaxpos = accelxmaxpos902                self.accelxmaxneg = accelxmaxneg903                self.accelymaxpos = accelymaxpos904                self.accelymaxneg = accelymaxneg905        if ACCELON == 0:906            self.accelx = 0907            self.accely = 0908            self.accelxmaxpos = accelxmaxpos909            self.accelxmaxneg = accelxmaxneg910            self.accelymaxpos = accelymaxpos911            self.accelymaxneg = accelymaxneg912    def updateOBDdata(self, *args):913        global clocktheme914        global response_RPM_int_adjusted915        global response_SPEED_int_adjusted916        global devobd917        global incobd918        global maxRPM919        global animation_time_start920        global rpmredline921        global speedlimit922        # _____________________________________________________________________________________923        if int(float(animation_start_time)) + 5 <= int(float(time_second_mod)):  # animation is delayed for better asthetics924            if OBDVAR == "NONE":  # code for no OBD stuff925                self.obdspeed = "0"926                self.obdRPM = "0"927                self.obdcoolanttemp = "0"928                self.obdintaketemp = "0"929                self.obdengineload = "0"930            if OBDVAR == "SPEED":  # code for OBD Digital Speedo931                if developermode == 1:932                    if incobd == 1:933                        devobd = devobd + 1934                    else:935                        devobd = devobd - 1936                    if devobd > 125:937                        incobd = 0938                    if devobd < 1:939                        incobd = 1940                    self.obdspeed = str(devobd)941                    self.obdspeedval = devobd942                    self.obdspeedlimitval = speedlimit943                else:944                    if OBDconnection == 1:945                        response_SPEED = connection.query(cmd_SPEED)  # send the command, and parse the response946                        response_SPEED_string = str(response_SPEED.value)  # change value into a string for comparing to "None"947                        if response_SPEED_string != 'None':  # only proceed if string value is not None948                            response_SPEED_int = int(response_SPEED.value)  # change the var type to int949                            # if response_SPEED_int == 0:  # to avoid the formula950                            #     response_SPEED_int_adjusted = 0951                            #     self.obdspeed = "0"952                            #953                            # if response_SPEED_int == 1:  # to avoid the formula954                            #     response_SPEED_int_adjusted = 1955                            #     self.obdspeed = "1"956                            #957                            # if response_SPEED_int == 2:  # to avoid the formula958                            #     response_SPEED_int_adjusted = 1959                            #     self.obdspeed = "1"960                            #961                            # if response_SPEED_int > 2:  # start to apply the formula to speed962                            #     response_SPEED_int_adjusted = math.floor(((response_SPEED_int) * (.6278)) - .664)  # adjusts number according to formula and rounds down to nearesr whole MPH - sets new adjusted int963                            #     response_SPEED_string_adjusted = str(response_SPEED_int_adjusted)  # sets string964                            #     self.obdspeed = response_SPEED_string_adjusted.strip()[:-2]  # set text965                            #966                            # if  response_SPEED_int_adjusted > 60: #apply new formula after 60 mph - from driving tests967                            #     response_SPEED_int_adjusted = math.floor((1.0264 * (response_SPEED_int_adjusted)) - 0.6739)968                            #     response_SPEED_string_adjusted = str(response_SPEED_int_adjusted)  # sets string969                            #     self.obdspeed = response_SPEED_string_adjusted.strip()[:-2]  # set text970                            response_SPEED_int_adjusted = math.floor((response_SPEED_int)*0.6213711922)971                            response_SPEED_string_adjusted = str(response_SPEED_int_adjusted)  # sets string972                            self.obdspeed = response_SPEED_string_adjusted.strip()[:-2]  # set text973                            self.obdspeedval = response_SPEED_int_adjusted974                            self.obdspeedlimitval = speedlimit975            if OBDVAR == "RPM":  # code for OBD Digital Tach976                if developermode == 1: #code to simulate 0 to 6750 and back down - for testing purposes977                    if incobd == 1:978                        devobd = devobd + 10979                    else:980                        devobd = devobd - 10981                    if devobd > 6900:982                        incobd = 0983                    if devobd < 100:984                        incobd = 1985                    if devobd > maxRPM:986                        maxRPM = devobd987                    self.obdRPMmax = str(maxRPM)988                    self.obdRPM = str(devobd)989                    self.obdRPMval = devobd990                    self.obdRPMredline = rpmredline991                else:992                    if OBDconnection == 1:993                        response_RPM = connection.query(cmd_RPM)  # send the command, and parse the response994                        response_RPM_string = str(response_RPM.value)  # change value into a string for comparing to "None"995                        if response_RPM_string != 'None':  # only proceed if string value is not None996                            response_RPM_int = int(response_RPM.value)  # set int value997                            response_RPM_int_adjusted = math.floor(response_RPM_int)  # round down to nearest whole RPM998                            if response_RPM_int_adjusted > maxRPM:999                                maxRPM = response_RPM_int_adjusted1000                            self.maxRPMvar = maxRPM1001                            maxRPM_string = str(maxRPM)1002                            maxRPM_string = maxRPM_string.strip()[:-2]  # strip .0 at the end of string1003                            response_RPM_string = str(response_RPM_int_adjusted)  # set string value1004                            response_RPM_string = response_RPM_string.strip()[:-2]  # strip .0 at the end of string1005                            self.obdRPM = response_RPM_string1006                            self.obdRPMmax = maxRPM_string1007                            self.obdRPMval = response_RPM_int1008                            self.obdRPMredline = rpmredline1009            if OBDVAR == "COOLANT_TEMP":  # code for OBD Coolant Temp1010                if developermode == 1:1011                    if incobd == 1:1012                        devobd = devobd + 11013                    else:1014                        devobd = devobd - 11015                    if devobd > 249:1016                        incobd = 01017                    if devobd < 1:1018                        incobd = 11019                    self.obdcoolanttemp = str(devobd) + u'\N{DEGREE SIGN}'1020                    self.obdcoolanttempval = devobd1021                else:1022                    if OBDconnection == 1:1023                        response_CoolantTemp = connection.query(cmd_CoolantTemp)  # send the command, and parse the response1024                        response_CoolantTemp_string = str(response_CoolantTemp.value)  # change value into a string for comparing to "None"1025                        if response_CoolantTemp_string != 'None':  # only proceed if string value is not None1026                            response_CoolantTemp_int = int(response_CoolantTemp.value) * 9.0 / 5.0 + 32.0  # set int value - change to farenheit1027                            response_CoolantTemp_int_adjusted = math.floor(response_CoolantTemp_int)  # round down to nearest whole RPM1028                            self.obdcoolanttempval = response_CoolantTemp_int_adjusted1029                            response_CoolantTemp_string = str(response_CoolantTemp_int_adjusted)  # set string value1030                            response_CoolantTemp_string = response_CoolantTemp_string.strip()[:-2]  # strip .0 at the end of string1031                            self.obdcoolanttemp = response_CoolantTemp_string + u'\N{DEGREE SIGN}'  # set text1032            if OBDVAR == "INTAKE_TEMP":  # code for OBD Intake Temp1033                if developermode == 1:1034                    if incobd == 1:1035                        devobd = devobd + 11036                    else:1037                        devobd = devobd - 11038                    if devobd > 120:1039                        incobd = 01040                    if devobd < 1:1041                        incobd = 11042                    self.obdintaketemp = str(devobd) + u'\N{DEGREE SIGN}'1043                else:1044                    if OBDconnection == 1:1045                        response_IntakeTemp = connection.query(cmd_IntakeTemp)  # send the command, and parse the response1046                        response_IntakeTemp_string = str(response_IntakeTemp.value)  # change value into a string for comparing to "None"1047                        if response_IntakeTemp_string != 'None':  # only proceed if string value is not None1048                            response_IntakeTemp_int = int(response_IntakeTemp.value) * 9.0 / 5.0 + 32.0  # set int value - change to farenheit1049                            response_IntakeTemp_int_adjusted = math.floor(response_IntakeTemp_int)  # round down to nearest whole RPM1050                            response_IntakeTemp_string = str(response_IntakeTemp_int_adjusted)  # set string value1051                            response_IntakeTemp_string = response_IntakeTemp_string.strip()[:-2]  # strip .0 at the end of string1052                            self.obdintaketemp = response_IntakeTemp_string + u'\N{DEGREE SIGN}'  # set text1053            if OBDVAR == "LOAD":  # code for OBD Engine Load1054                if developermode == 1:1055                    if incobd == 1:1056                        devobd = devobd + 11057                    else:1058                        devobd = devobd - 11059                    if devobd > 99:1060                        incobd = 01061                    if devobd < 1:1062                        incobd = 11063                    self.obdengineload = str(devobd) + '%'1064                    self.obdengineloadval = devobd1065                else:1066                    if OBDconnection == 1:1067                        response_Load = connection.query(cmd_Load)  # send the command, and parse the response1068                        response_Load_string = str(response_Load.value)  # change value into a string for comparing to "None"1069                        if response_Load_string != 'None':  # only proceed if string value is not None1070                            response_Load_int = int(response_Load.value)1071                            response_Load_int_adjusted = math.floor(response_Load_int)  # round down to nearest whole RPM1072                            response_Load_string = str(response_Load_int_adjusted)  # set string value1073                            response_Load_string = response_Load_string.strip()[:-2]  # strip .0 at the end of string1074                            self.obdengineload = response_Load_string + '%'  # set text1075                            self.obdengineloadval = response_Load_int_adjusted #value, for progress bar1076            if OBDVAR == "THROTTLE_POS":  # code for OBD Throttle Position1077                if developermode == 1:1078                    if incobd == 1:1079                        devobd = devobd + 11080                    else:1081                        devobd = devobd - 11082                    if devobd > 99:1083                        incobd = 01084                    if devobd < 1:1085                        incobd = 11086                    self.obdthrottlepos = str(devobd) + '%'1087                    self.obdthrottleposval = devobd1088                else:1089                    if OBDconnection == 1:1090                        response_ThrottlePos = connection.query(cmd_ThrottlePos)  # send the command, and parse the response1091                        response_ThrottlePos_string = str(response_ThrottlePos.value)  # change value into a string for comparing to "None"1092                        if response_ThrottlePos_string != 'None':  # only proceed if string value is not None1093                            response_ThrottlePos_int = int(response_ThrottlePos.value)1094                            response_ThrottlePos_int_adjusted = math.floor(response_ThrottlePos_int)  # round down to nearest whole RPM1095                            response_ThrottlePos_string = str(response_ThrottlePos_int_adjusted)  # set string value1096                            response_ThrottlePos_string = response_ThrottlePos_string.strip()[:-2]  # strip .0 at the end of string1097                            self.obdthrottlepos = response_ThrottlePos_string + '%'  # set text1098                            self.obdthrottleposval = response_ThrottlePos_int_adjusted #value, for progress bar1099            if OBDVAR == "INTAKE_PRESSURE":  # code for OBD Intake Pressure1100                if developermode == 1:1101                    if incobd == 1:1102                        devobd = devobd + .11103                    else:1104                        devobd = devobd - .11105                    if devobd > -.1:1106                        incobd = 01107                    if devobd < -14.7:1108                        incobd = 11109                    self.obdintakepressure = str(devobd)1110                else:1111                    if OBDconnection == 1:1112                        response_IntakePressure = connection.query(cmd_IntakePressure)  # send the command, and parse the response1113                        response_IntakePressure_string = str(response_IntakePressure.value)  # change value into a string for comparing to "None"1114                        if response_IntakePressure_string != 'None':  # only proceed if string value is not None1115                            response_IntakePressure_int = (int(response_IntakePressure.value)-101.325) * 0.145038 # set int value - compare against atmospheric pressure for vaccuum - change to psi1116                            response_IntakePressure_int_adjusted = round(response_IntakePressure_int, 2)  # round down to 2 decimal places1117                            response_IntakePressure_string = str(response_IntakePressure_int_adjusted)  # set string value1118                            self.obdintakepressure = response_IntakePressure_string  # set text1119    def build(self):1120        global developermode1121        KVFILE = Builder.load_file("main.kv")1122        global root1123        root = ROOT()1124        Clock.schedule_interval(self.updatetime, .1)1125        Clock.schedule_interval(self.updatedate, 1)1126        Clock.schedule_interval(self.updatetemp, 1)1127        Clock.schedule_interval(self.updatevariables, .104556) #weird number to get RPi stopwatch as close as possible - found through testing1128        Clock.schedule_interval(self.updatemessage, 1)1129        Clock.schedule_interval(self.updateaccel, .1)1130        if developermode == 1:1131            Clock.schedule_interval(self.updateOBDdata, .01)1132        else:1133            Clock.schedule_interval(self.updateOBDdata, .1)1134        #add the widgets1135        1136        root.add_widget(KVFILE) #adds the main GUI1137        return root1138#Some KivyMD Stuff1139    def show_easter_dialog(self):1140        content = MDLabel(font_style='Body1',1141                          theme_text_color='Secondary',1142                          text="Congrats! You found this easter egg!\n\n"1143                               "Thanks for trying out CoPilot!  :)",1144                          valign='top')1145        content.bind(size=content.setter('text_size'))1146        self.dialog = MDDialog(title="Easter Egg!",1147                               content=content,1148                               size_hint=(.8, None),1149                               height=dp(200),1150                               auto_dismiss=False)1151        self.dialog.add_action_button("Dismiss",1152                                      action=lambda *x: self.dialog.dismiss())1153        self.dialog.open()1154    def show_indev_dialog(self):1155        content = MDLabel(font_style='Body1',1156                          theme_text_color='Secondary',1157                          text="This feature is currently in development.\n\n"1158                               "Thanks for trying out CoPilot!  :)",1159                          valign='top')1160        content.bind(size=content.setter('text_size'))1161        self.dialog = MDDialog(title="Coming soon!",1162                               content=content,1163                               size_hint=(.8, None),1164                               height=dp(200),1165                               auto_dismiss=False)1166        self.dialog.add_action_button("Dismiss",1167                                      action=lambda *x: self.dialog.dismiss())1168        self.dialog.open()1169    def show_version_dialog(self):1170        content = MDLabel(font_style='Body1',1171                          theme_text_color='Secondary',1172                          text="Created by Joel Zeller\n\n"1173                               "Please send any bugs to joelzeller25@hotmail.com",1174                          valign='top')1175        content.bind(size=content.setter('text_size'))1176        self.dialog = MDDialog(title="CoPilot "+version,1177                               content=content,1178                               size_hint=(.8, None),1179                               height=dp(200),1180                               auto_dismiss=False)1181        self.dialog.add_action_button("Dismiss",1182                                      action=lambda *x: self.dialog.dismiss())1183        self.dialog.open()1184    def show_example_snackbar(self, snack_type):1185        if devtaps == 4:1186            if snack_type == 'enabledev':1187                Snackbar.make("Developer Mode Enabled")1188        # elif snack_type == 'button':1189        #     Snackbar.make("This is a snackbar", button_text="with a button!",1190        #                   button_callback=lambda *args: 2)1191        # elif snack_type == 'verylong':1192        #     Snackbar.make("This is a very very very very very very very long "1193        #                   "snackbar!",1194        #                   button_text="Hello world")1195#SCHEDUALING1196        #AUDIO1197    def bluetoothplay_callback_schedge(obj):1198        if BLUETOOTHON == 1:1199            try:1200                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_'+bluetoothdevicemac+'/player0 org.bluez.MediaPlayer1.Play')1201                #subprocess.call('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_' + bluetoothdevicemac + '/player0 org.bluez.MediaPlayer1.Play') #doesnt work right now...1202                #maybe try this: subprocess.call('sudo shutdown now', shell=True)1203            except:1204                print "can't play"1205    def bluetoothpause_callback_schedge(obj):1206        if BLUETOOTHON == 1:1207            try:1208                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_'+bluetoothdevicemac+'/player0 org.bluez.MediaPlayer1.Pause')1209            except:1210                print "can't pause"1211    def seekup_callback_schedge(obj):1212        if BLUETOOTHON == 0:1213            Clock.schedule_once(seekup_callback)1214            Clock.schedule_once(seekup_callback, 0.1) #on for .1 secs, then off again1215        if BLUETOOTHON == 1:1216            try:1217                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_'+bluetoothdevicemac+'/player0 org.bluez.MediaPlayer1.Next')1218            except:1219                print "can't next"1220    def seekdown_callback_schedge(obj):1221        if BLUETOOTHON == 0:1222            Clock.schedule_once(seekdown_callback)1223            Clock.schedule_once(seekdown_callback, 0.1) #on for .1 secs, then off again1224        if BLUETOOTHON == 1:1225            try:1226                os.system('dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_'+bluetoothdevicemac+'/player0 org.bluez.MediaPlayer1.Previous')1227            except:1228                print "can't prev"1229    def aux_callback_schedge(obj):1230        Clock.schedule_once(aux_callback)1231        Clock.schedule_once(aux_callback, 0.1) #on for .1 secs, then off again1232    def amfm_callback_schedge(obj):1233        Clock.schedule_once(amfm_callback) 1234        Clock.schedule_once(amfm_callback, 0.1) #on for .1 secs, then off again1235    def enablebluetooth(obj):1236        global BLUETOOTHON1237        BLUETOOTHON = 11238    def disablebluetooth(obj):1239        global BLUETOOTHON1240        BLUETOOTHON = 01241    def displaybtdata(obj):1242        global DISPLAYBTDATA1243        DISPLAYBTDATA = 11244        global animation_start_time1245        animation_start_time = int(float(time_second_mod))  # sets a reference time for animations1246    def killbtdata(obj):1247        global DISPLAYBTDATA1248        DISPLAYBTDATA = 01249        #CONTROLS1250    def garage_callback_schedge(obj):1251        Clock.schedule_once(garage_callback) #called once - setup to only activate when button is down1252    def radar_callback_schedge(obj):1253        Clock.schedule_once(radar_callback) #called once so next press alternates status1254    def leds_callback_schedge(obj):1255        Clock.schedule_once(leds_callback) #called once so next press alternates status1256    def windowsup_callback_schedge(obj):1257        global WINDOWSUPON1258        global WINDOWSDOWNON1259        if WINDOWSDOWNON == 0: #only works when windows down isnt running1260            Clock.schedule_once(windowsup_callback) #called once so next press alternates status1261            Clock.schedule_once(windowsupOFF_callback, windowuptime) #on for set x secs, then off again - time needs edited1262            return1263        if WINDOWSUPON == 1:1264            Clock.schedule_once(windowsupOFF_callback) #if windows going up while pushed, will cancel and stop windows1265    def windowsdown_callback_schedge(obj):1266        global WINDOWSUPON1267        global WINDOWSDOWNON1268        if WINDOWSUPON == 0: #only works when windows up isnt running1269            Clock.schedule_once(windowsdown_callback) #called once so next press alternates status1270            Clock.schedule_once(windowsdownOFF_callback, windowdowntime) #on for set x secs, then off again - time needs edited1271            return1272        if WINDOWSDOWNON == 1:1273            Clock.schedule_once(windowsdownOFF_callback) #if windows going down while pushed, will cancel and stop windows1274    # following 6 functions serve purpose to debug windows1275    def driverup_callback_schedge(obj):1276        Clock.schedule_once(driverup_callback) #called once - setup to only activate when button is down1277    def driverstop_callback_schedge(obj):1278        Clock.schedule_once(driverstop_callback) #called once - setup to only activate when button is down1279    def driverdown_callback_schedge(obj):1280        Clock.schedule_once(driverdown_callback) #called once - setup to only activate when button is down1281    def passengerup_callback_schedge(obj):1282        Clock.schedule_once(passengerup_callback) #called once - setup to only activate when button is down1283    def passengerstop_callback_schedge(obj):1284        Clock.schedule_once(passengerstop_callback) #called once - setup to only activate when button is down1285    def passengerdown_callback_schedge(obj):1286        Clock.schedule_once(passengerdown_callback) #called once - setup to only activate when button is down1287    def allwindowsstop_callback_schedge(obj):1288        Clock.schedule_once(allwindowsstop_callback) #called once - setup to only activate when button is down1289#VARIBLE SETTINGS1290    def add_launch(obj): #use on_release: app.add_launchanalog() to call - used to create the lights on the xmas tree drag lights1291        global time_second_mod1292        global launch_start_time1293        launch_start_time = int(float(time_second_mod)) #sets a reference time for launch control timing1294    #messages1295    def kill_message(obj): #use on_release: app.kill_message() to call1296        global message1297        message = 01298        1299    def add_message(obj): #use on_release: app.add_message() to call1300        global message1301        message = 11302    def update_IP(obj): #updates IP address on button tap in System Diagnostics1303        global ip1304        try:1305            ip = get_ip_address()1306        except:1307            ip = "No IP address found..."1308    #stopwatch button functions1309    def stopwatch_start(obj): #use on_release: app.stopwatch_start() to call1310        global swactive1311        swactive = 11312    def stopwatch_stop(obj): #use on_release: app.stopwatch_start() to call1313        global swactive1314        swactive = 01315    def stopwatch_reset(obj): #use on_release: app.stopwatch_start() to call1316        global swactive1317        global swminute1318        global swsecond1319        global swtenth1320        swactive = 01321        swminute = 01322        swsecond = 01323        swtenth = 01324    #hot key 1 settings functions1325    def sethotkey1_SeekUp(obj):1326        global hotkey1string1327        hotkey1string = "Seek Up"1328    def sethotkey1_SeekDown(obj):1329        global hotkey1string1330        hotkey1string = "Seek Down"1331    def sethotkey1_Garage(obj):1332        global hotkey1string1333        hotkey1string = "Garage"1334    def sethotkey1_Radar(obj):1335        global hotkey1string1336        hotkey1string = "Radar"1337    def sethotkey1_CupLights(obj):1338        global hotkey1string1339        hotkey1string = "Cup Lights"1340    def sethotkey1_WindowsUp(obj):1341        global hotkey1string1342        hotkey1string = "Windows Up"1343    def sethotkey1_WindowsDown(obj):1344        global hotkey1string1345        hotkey1string = "Windows Down"1346    def sethotkey1_ScreenToggle(obj):1347        global hotkey1string1348        hotkey1string = "Screen Toggle"1349    def sethotkey1_None(obj):1350        global hotkey1string1351        hotkey1string = "None"1352    #hot key 2 settings functions1353    def sethotkey2_SeekUp(obj):1354        global hotkey2string1355        hotkey2string = "Seek Up"1356    def sethotkey2_SeekDown(obj):1357        global hotkey2string1358        hotkey2string = "Seek Down"1359    def sethotkey2_Garage(obj):1360        global hotkey2string1361        hotkey2string = "Garage"1362    def sethotkey2_Radar(obj):1363        global hotkey2string1364        hotkey2string = "Radar"1365    def sethotkey2_CupLights(obj):1366        global hotkey2string1367        hotkey2string = "Cup Lights"1368    def sethotkey2_WindowsUp(obj):1369        global hotkey2string1370        hotkey2string = "Windows Up"1371    def sethotkey2_WindowsDown(obj):1372        global hotkey2string1373        hotkey2string = "Windows Down"1374    def sethotkey2_ScreenToggle(obj):1375        global hotkey2string1376        hotkey2string = "Screen Toggle"1377    def sethotkey2_None(obj):1378        global hotkey2string1379        hotkey2string = "None"1380    def sethotkeydefaults(obj):1381        global hotkey1string1382        global hotkey2string1383        hotkey1string = "None"1384        hotkey2string = "None"1385    def setwallpaper(obj,wallpapernum):1386        global wallpaper1387        wallpaper = wallpapernum1388    def devtap(obj):1389        global devtaps1390        global developermode1391        if devtaps <= 4:1392            devtaps = devtaps + 11393        if devtaps == 5:            # five taps on the settings title will enter dev mode1394            developermode = 11395    def killdev(obj):1396        global devtaps1397        global developermode1398        developermode = 01399        devtaps = 01400    def save(obj):1401        # save new varibles for next boot1402        global theme1403        global wallpaper1404        global hotkey1string1405        global hotkey2string1406        global oildatemonth1407        global oildateday1408        global oildateyear1409        global oilmileage1410        global oilnotify1411        global speedlimit1412        global rpmredline1413        wallpaper = str(wallpaper)1414        oildatemonth = str(oildatemonth)1415        oildateday = str(oildateday)1416        oildateyear = str(oildateyear)1417        oilmileage = str(oilmileage)1418        oilnotify = str(oilnotify)1419        speedlimit = str(int(speedlimit))1420        rpmredline = str(int(rpmredline))1421        f = open('savedata.txt', 'r+')1422        f.truncate() # wipe everything1423        f.write(theme + "\n" + wallpaper + "\n" + hotkey1string + "\n" + hotkey2string + "\n" + oildatemonth + "\n" + oildateday + "\n" + oildateyear + "\n" + oilmileage + "\n" + oilnotify + "\n" + speedlimit + "\n" + rpmredline)1424        f.close()1425        oildatemonth = int(oildatemonth)1426        oildateday = int(oildateday)1427        oildateyear = int(oildateyear)1428        oilmileage = int(oilmileage)1429        oilnotify = int(oilnotify)1430        speedlimit = int(speedlimit)1431        rpmredline = int(rpmredline)1432    def shutdown(obj):1433        # save new varibles for next boot1434        global theme1435        global wallpaper1436        global hotkey1string1437        global hotkey2string1438        global oildatemonth1439        global oildateday1440        global oildateyear1441        global oilmileage1442        global oilnotify1443        global speedlimit1444        global rpmredline1445        wallpaper = str(wallpaper)1446        oildatemonth = str(oildatemonth)1447        oildateday = str(oildateday)1448        oildateyear = str(oildateyear)1449        oilmileage = str(oilmileage)1450        oilnotify = str(oilnotify)1451        speedlimit = str(int(speedlimit))1452        rpmredline = str(int(rpmredline))1453        f = open('savedata.txt', 'r+')1454        f.truncate() # wipe everything1455        f.write(theme + "\n" + wallpaper + "\n" + hotkey1string + "\n" + hotkey2string + "\n" + oildatemonth + "\n" + oildateday + "\n" + oildateyear + "\n" + oilmileage + "\n" + oilnotify + "\n" + speedlimit + "\n" + rpmredline)1456        f.close()1457        oildatemonth = int(oildatemonth)1458        oildateday = int(oildateday)1459        oildateyear = int(oildateyear)1460        oilmileage = int(oilmileage)1461        oilnotify = int(oilnotify)1462        speedlimit = int(speedlimit)1463        rpmredline = int(rpmredline)1464        # turn off screen and shutdown1465        os.system("sudo echo 1 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen off1466        os.system("sudo shutdown -h now")1467    def reboot(obj):1468        # save new varibles for next boot1469        global theme1470        global wallpaper1471        global hotkey1string1472        global hotkey2string1473        global oildatemonth1474        global oildateday1475        global oildateyear1476        global oilmileage1477        global oilnotify1478        global speedlimit1479        global rpmredline1480        wallpaper = str(wallpaper)1481        oildatemonth = str(oildatemonth)1482        oildateday = str(oildateday)1483        oildateyear = str(oildateyear)1484        oilmileage = str(oilmileage)1485        speedlimit = str(int(speedlimit))1486        rpmredline = str(int(rpmredline))1487        f = open('savedata.txt', 'r+')1488        f.truncate()1489        f.write(theme + "\n" + wallpaper + "\n" + hotkey1string + "\n" + hotkey2string + "\n" + oildatemonth + "\n" + oildateday + "\n" + oildateyear + "\n" + oilmileage + "\n" + oilnotify + "\n" + speedlimit + "\n" + rpmredline)1490        f.close()1491        oildatemonth = int(oildatemonth)1492        oildateday = int(oildateday)1493        oildateyear = int(oildateyear)1494        oilmileage = int(oilmileage)1495        oilnotify = int(oilnotify)1496        speedlimit = int(speedlimit)1497        rpmredline = int(rpmredline)1498        os.system("sudo reboot")1499    def TurnScreenOn(obj):1500        global screenon1501        screenon = 11502        os.system("sudo echo 0 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen on1503    def TurnScreenOff(obj):1504        global screenon1505        screenon = 01506        os.system("sudo echo 1 > /sys/class/backlight/rpi_backlight/bl_power") #turns screen off1507    #brightness control functions1508    def BrightnessSetLock(obj): #only for lockscreen - not used yet1509        os.system("sudo echo 15 > /sys/class/backlight/rpi_backlight/brightness") #sets screen brightness to ~ 1%1510    def BrightnessSet1(obj):1511        os.system("sudo echo 15 > /sys/class/backlight/rpi_backlight/brightness") #sets screen brightness to ~ 10%1512    def BrightnessSet2(obj):1513        os.system("sudo echo 60 > /sys/class/backlight/rpi_backlight/brightness") #sets screen brightness to ~ 25%1514    def BrightnessSet3(obj):1515        os.system("sudo echo 80 > /sys/class/backlight/rpi_backlight/brightness") #sets screen brightness to ~ 50%1516    def BrightnessSet4(obj):1517        os.system("sudo echo 120 > /sys/class/backlight/rpi_backlight/brightness") #sets screen brightness to ~ 75%1518    def BrightnessSet5(obj):1519        os.system("sudo echo 200 > /sys/class/backlight/rpi_backlight/brightness") #sets screen brightness to ~ 100%1520    def killtemp(obj): #used to kill the temp label when on screens other than main1521        global TEMPON1522        TEMPON = 01523    def addtemp(obj): #used to kill the temp label when on screens other than main1524        global TEMPON1525        global animation_start_time1526        TEMPON = 11527        animation_start_time = int(float(time_second_mod)) #sets a reference time for animations1528    def killaccel(obj):1529        global ACCELON1530        ACCELON = 01531    def addaccel(obj):1532        global ACCELON1533        ACCELON = 11534    def resetaccelmaxes(obj):1535        global accelxmaxpos1536        global accelxmaxneg1537        global accelymaxpos1538        global accelymaxneg1539        accelxmaxpos = 01540        accelxmaxneg = 01541        accelymaxpos = 01542        accelymaxneg = 01543    def connect_OBD(obj): #sets value to one so connection code only runs once1544        global OBDconnection1545        if developermode == 0:1546            OBDconnection = 11547    def set_OBDVAR(obj,OBDVARIABLE): #used to change the OBD label to other types of data1548        global OBDVAR1549        global devobd1550        global time_second_mod1551        global animation_start_time1552        OBDVAR = OBDVARIABLE1553        if OBDVAR == "NONE":1554            devobd = 01555        animation_start_time = int(float(time_second_mod)) #sets a reference time for animations1556    def zero_RPMmax(obj): #zeros out RPM max1557        global maxRPM1558        maxRPM = 01559    def redline_value(self, instance, value): #function that is updated when redline slider is moved1560        global rpmredline1561        rpmredline = value1562    def speedlimit_value(self, instance, value): #function that is updated when speed limit slider is moved1563        global speedlimit1564        speedlimit = value1565    def set_OBDpage(obj, OBDpagevar):1566        global OBDpage1567        OBDpage = OBDpagevar1568        #print OBDpage #testing1569    #_________________________________________________________________1570    #Function to setup OBD stuff1571    def setup_OBD(obj):1572        if developermode == 0:1573            global connection1574            global cmd_RPM1575            global cmd_SPEED1576            global cmd_CoolantTemp1577            global cmd_IntakeTemp1578            global cmd_Load1579            global cmd_ThrottlePos1580            global cmd_IntakePressure1581            global OBDconnection1582            if OBDconnection == 0:1583                try:1584                    os.system('sudo rfcomm bind /dev/rfcomm1 00:1D:A5:16:3E:ED')1585                except:1586                    print "OBDII device already connected"1587                try:1588                    connection = obd.OBD() # auto-connects to USB or RF port1589                except:1590                    print "can't connect to OBDII device - make sure it is connected"1591                cmd_RPM = obd.commands.RPM # select RPM OBD command1592                cmd_SPEED = obd.commands.SPEED # select SPEED OBD command1593                cmd_CoolantTemp = obd.commands.COOLANT_TEMP # select CoolantTemp OBD command1594                cmd_IntakeTemp = obd.commands.INTAKE_TEMP # select IntakeTemp OBD command1595                cmd_Load = obd.commands.ENGINE_LOAD # select EngineLoad OBD command1596                cmd_ThrottlePos = obd.commands.THROTTLE_POS  # select Throttle Position OBD command1597                cmd_IntakePressure = obd.commands.INTAKE_PRESSURE  # select Intake Pressure OBD command1598    def oilmileageup100(obj):1599        global oilmileage1600        oilmileage = oilmileage+1001601    def oilmileagedown100(obj):1602        global oilmileage1603        oilmileage = oilmileage-1001604    def oilmileageup1k(obj):1605        global oilmileage1606        oilmileage = oilmileage+10001607    def oilmileagedown1k(obj):1608        global oilmileage1609        oilmileage = oilmileage-10001610    def oilmileageup10k(obj):1611        global oilmileage1612        oilmileage = oilmileage+100001613    def oilmileagedown10k(obj):1614        global oilmileage1615        oilmileage = oilmileage-100001616    def oilmileageup100k(obj):1617        global oilmileage1618        oilmileage = oilmileage+1000001619    def oilmileagedown100k(obj):1620        global oilmileage1621        oilmileage = oilmileage-1000001622    def oildatemonthup(obj):1623        global oildatemonth1624        if oildatemonth < 12:1625            oildatemonth = oildatemonth+11626        else:1627            oildatemonth = 11628    def oildatemonthdown(obj):1629        global oildatemonth1630        if oildatemonth > 1:1631            oildatemonth = oildatemonth-11632        else:1633            oildatemonth = 121634    def oildatedayup(obj):1635        global oildateday1636        if oildateday < 31:1637            oildateday = oildateday+11638        else:1639            oildateday = 11640    def oildatedaydown(obj):1641        global oildateday1642        if oildateday > 1:1643            oildateday = oildateday-11644        else:1645            oildateday = 311646    def oildateyearup(obj):1647        global oildateyear1648        oildateyear = oildateyear+11649    def oildateyeardown(obj):1650        global oildateyear1651        oildateyear = oildateyear-11652    def oilnotifyflip(obj):1653        global oilnotify1654        if oilnotify == 1:1655            oilnotify = 01656            return1657        if oilnotify == 0:1658            oilnotify = 11659#____________________________________________________________________1660#GPIO CALLBACKS1661def seekup_callback(obj): #logic for seekup gpio1662    global SEEKUPON1663    if SEEKUPON == 0:1664        if developermode == 0:1665            GPIO.output(seekupPin, GPIO.LOW)1666        SEEKUPON = 11667    else:1668        if developermode == 0:1669            GPIO.output(seekupPin, GPIO.HIGH)1670        SEEKUPON = 01671def seekdown_callback(obj): #logic for seekdown gpio1672    global SEEKDOWNON1673    if SEEKDOWNON == 0:1674        if developermode == 0:1675            GPIO.output(seekdownPin, GPIO.LOW)1676        SEEKDOWNON = 11677    else:1678        if developermode == 0:1679            GPIO.output(seekdownPin, GPIO.HIGH)1680        SEEKDOWNON = 01681def aux_callback(obj): #logic for aux gpio1682    global AUXON1683    if AUXON == 0:1684        if developermode == 0:1685            GPIO.output(auxPin, GPIO.LOW)1686        AUXON = 11687    else:1688        if developermode == 0:1689            GPIO.output(auxPin, GPIO.HIGH)1690        AUXON = 01691def amfm_callback(obj): #logic for amfm gpio1692    global AMFMON1693    if AMFMON == 0:1694        if developermode == 0:1695            GPIO.output(amfmPin, GPIO.LOW)1696        AMFMON = 11697    else:1698        if developermode == 0:1699            GPIO.output(amfmPin, GPIO.HIGH)1700        AMFMON = 01701        #CONTROLS1702def garage_callback(obj): #logic for garage gpio1703    global GARAGEON1704    if GARAGEON == 0:1705        if developermode == 0:1706            GPIO.output(garagePin, GPIO.LOW)1707        GARAGEON = 11708    else:1709        if developermode == 0:1710            GPIO.output(garagePin, GPIO.HIGH)1711        GARAGEON = 01712def radar_callback(obj): #logic for radar gpio1713    global RADARON1714    if RADARON == 0:1715        if developermode == 0:1716            GPIO.output(radarPin, GPIO.LOW)1717        RADARON = 11718    else:1719        if developermode == 0:1720            GPIO.output(radarPin, GPIO.HIGH)1721        RADARON = 01722def leds_callback(obj): #logic for cup holder leds gpio1723    global LEDSON1724    if LEDSON == 0:1725        if developermode == 0:1726            GPIO.output(ledsPin, GPIO.HIGH)1727        LEDSON = 11728    else:1729        if developermode == 0:1730            GPIO.output(ledsPin, GPIO.LOW)1731        LEDSON = 01732def windowsup_callback(obj): #logic for windows up gpio1733    global WINDOWSUPON1734    global WINDOWSDOWNON1735    1736    if WINDOWSDOWNON == 0:1737        1738        if WINDOWSUPON == 0:1739            if developermode == 0:1740                GPIO.output(driverwindowupPin, GPIO.LOW)1741                GPIO.output(passwindowupPin, GPIO.LOW)1742            WINDOWSUPON = 11743            return1744        if WINDOWSUPON == 1:1745            if developermode == 0:1746                GPIO.output(driverwindowupPin, GPIO.HIGH)1747                GPIO.output(passwindowupPin, GPIO.HIGH)1748            WINDOWSUPON = 01749            return1750        1751def windowsupOFF_callback(obj): #logic to halt the windows1752    global WINDOWSUPON1753    global WINDOWSDOWNON1754    WINDOWSUPON = 01755    if developermode == 0:1756        GPIO.output(driverwindowupPin, GPIO.HIGH)1757        GPIO.output(passwindowupPin, GPIO.HIGH)1758def windowsdown_callback(obj): #logic for windows down gpio1759    global WINDOWSDOWNON1760    global WINDOWSUPON1761    1762    if WINDOWSUPON == 0:1763        1764        if WINDOWSDOWNON == 0:1765            if developermode == 0:1766                GPIO.output(driverwindowdownPin, GPIO.LOW)1767                GPIO.output(passwindowdownPin, GPIO.LOW)1768            WINDOWSDOWNON = 11769            return1770        if WINDOWSDOWNON == 1:1771            if developermode == 0:1772                GPIO.output(driverwindowdownPin, GPIO.HIGH)1773                GPIO.output(passwindowdownPin, GPIO.HIGH)1774            WINDOWSDOWNON = 01775            return1776def windowsdownOFF_callback(obj): #logic to halt the windows1777    global WINDOWSDOWNON1778    global WINDOWSUPON1779    WINDOWSDOWNON = 01780    if developermode == 0:1781        GPIO.output(driverwindowdownPin, GPIO.HIGH)1782        GPIO.output(passwindowdownPin, GPIO.HIGH)1783    # callback functions for window debugging1784def driverup_callback(obj): #logic for driver up gpio1785    global DRIVERUPON1786    if DRIVERUPON == 0:1787        if developermode == 0:1788            GPIO.output(driverwindowupPin, GPIO.LOW)1789        DRIVERUPON = 11790    else:1791        if developermode == 0:1792            GPIO.output(driverwindowupPin, GPIO.HIGH)1793        DRIVERUPON = 01794def driverstop_callback(obj): #logic for driver window emergency stop1795    global WINDOWSDOWNON1796    global WINDOWSUPON1797    WINDOWSDOWNON = 01798    WINDOWSUPON = 01799    if developermode == 0:1800        GPIO.output(driverwindowupPin, GPIO.HIGH)1801        GPIO.output(driverwindowdownPin, GPIO.HIGH)1802def driverdown_callback(obj): #logic for driver down gpio1803    global DRIVERDOWNON1804    if DRIVERDOWNON == 0:1805        if developermode == 0:1806            GPIO.output(driverwindowdownPin, GPIO.LOW)1807        DRIVERDOWNON = 11808    else:1809        if developermode == 0:1810            GPIO.output(driverwindowdownPin, GPIO.HIGH)1811        DRIVERDOWNON = 01812def passengerup_callback(obj): #logic for passenger up gpio1813    global PASSENGERUPON1814    if PASSENGERUPON == 0:1815        if developermode == 0:1816            GPIO.output(passwindowupPin, GPIO.LOW)1817        PASSENGERUPON = 11818    else:1819        if developermode == 0:1820            GPIO.output(passwindowupPin, GPIO.HIGH)1821        PASSENGERUPON = 01822def passengerstop_callback(obj): #logic for passenger window emergency stop1823    global WINDOWSDOWNON1824    global WINDOWSUPON1825    WINDOWSDOWNON = 01826    WINDOWSUPON = 01827    if developermode == 0:1828        GPIO.output(passwindowupPin, GPIO.HIGH)1829        GPIO.output(passwindowdownPin, GPIO.HIGH)1830def passengerdown_callback(obj): #logic for passenger down gpio1831    global PASSENGERDOWNON1832    if PASSENGERDOWNON == 0:1833        if developermode == 0:1834            GPIO.output(passwindowdownPin, GPIO.LOW)1835            GPIO.output(passwindowdownPin, GPIO.LOW)1836        PASSENGERDOWNON = 11837    else:1838        if developermode == 0:1839            GPIO.output(passwindowdownPin, GPIO.HIGH)1840        PASSENGERDOWNON = 01841def allwindowsstop_callback(obj): #logic for all windows emergency stop1842    global WINDOWSDOWNON1843    global WINDOWSUPON1844    WINDOWSDOWNON = 01845    WINDOWSUPON = 01846    if developermode == 0:1847        GPIO.output(passwindowupPin, GPIO.HIGH)1848        GPIO.output(passwindowdownPin, GPIO.HIGH)1849        GPIO.output(driverwindowupPin, GPIO.HIGH)1850        GPIO.output(driverwindowdownPin, GPIO.HIGH)1851if __name__ =='__main__':...__init__.py
Source:__init__.py  
...446    event_name = u"kbevent%s%s" % (keys, modifiers)447    if event_name in _pollEvents._callback:448        del _pollEvents._callback[event_name]449    return _remote_deregisterkbevent(keys, modifiers)450def windowuptime(window_name):451    """452    Get window uptime453    454    @param window_name: Window name to look for, either full name,455    LDTP's name convention, or a Unix glob.456    @type window_name: string457    @return: "starttime, endtime" as datetime python object458    """459    tmp_time = _remote_windowuptime(window_name)460    if tmp_time:461        tmp_time = tmp_time.split('-')462        start_time = tmp_time[0].split(' ')463        end_time = tmp_time[1].split(' ')464        _start_time = datetime.datetime(int(start_time[0]), int(start_time[1]),465                                        int(start_time[2]), int(start_time[3]),466                                        int(start_time[4]), int(start_time[5]))467        _end_time = datetime.datetime(int(end_time[0]), int(end_time[1]),468                                      int(end_time[2]),int(end_time[3]),469                                      int(end_time[4]), int(end_time[5]))470        return _start_time, _end_time471    return None472_populateNamespace(globals())473_pollEvents = PollEvents()...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
