def lcd_toggle_enable(): # Toggle enable time.sleep(E_DELAY) GPIO.output(LCD_E, True) time.sleep(E_PULSE) GPIO.output(LCD_E, False) time.sleep(E_DELAY)
def Cellular_LED(inSLED): # This function sets the cellular LED # Arguments: # inStatus : GPS LED status. Pass in either 'ON' or 'OFF' # OFF - LED always OFF # ON - LED function ON # # Returns: # 0: Pass # -1: Exception tmpReturn = -1 try: #Set Stat LED to default value, 0 for OFF, 2 for ON if (inSLED == 'ON'): res = GPIO.setSLED(2, 10, 90) else: res = GPIO.setSLED(0, 10, 90) res = ATC.sendAtCmd('AT#SLEDSAV',ATC.properties.CMD_TERMINATOR,0,20) if (res == -1): #Errored out, 1 if no error -1 if error return tmpReturn tmpReturn = 0 except: printException("Cellular_LED") JANUS_SER.sendUART("GPS LED exception. \r\n") return tmpReturn
def stopEngine(sms): Helper.writeLog('#Begin: StopEngine function') Helper.writeLog('-Password in sms is '+sms.password) if Password == SavedPassword and SavedPassword != 0 : Helper.writeLog('-In Stop engine Condition') GPSLat = getGPSLocation('Lat') Helper.writeLog('-Latitude= '+GPSLat) GPSLon = getGPSLocation('Lon') Helper.writeLog('-Longitude= '+GPSLon) Number = sms.number GPIO.setIOvalue(8,0) Helper.writeLog('-Before Sending the SMS') SMSHandler.sendSMS(Number,'Your car was last seen in this location http://maps.google.com/?q='+GPSLat.rstrip().lstrip()+','+GPSLon.rstrip().lstrip()) Helper.writeLog('-Deleting SMS') SMSHandler.deleteSMS(MessageIndex,'STP') else : Helper.writeLog('Deleting SMS') SMSHandler.deleteSMS(MessageIndex,'STP 2')
def checkCon(pin): a = SER.send('DEBUG: Now in checkCon...\r\n') #print '\r\ncheckCon PIN:',pin res = MDM2.send('AT+CREG?\r',0) res = MDM2.receive(30) b = SER.send('DEBUG: following is result from AT+CREG?\r\n') c = SER.send(res); if ( (res.find('0,1') > -1) or (res.find('0,5') > -1 ) ): return 1 ret = '' ret = setPin(pin) if ( ret != 1 ): GPIO.setIOdir(19,1,1) return -1 timer = MOD.secCounter() + 120 while ( (res.find('0,1') == -1) and (res.find('0,5') == -1 ) ): res = MDM2.send('AT+CREG?\r',0) res = MDM2.receive(20) b = SER.send('DEBUG: following is result from AT+CREG?\r\n') c = SER.send(res); if ( MOD.secCounter() > timer ): return -1 MOD.sleep(50) MOD.sleep(20) return 1
def setOUT2(state): """Установка состояния реле 2 Args: state: требуемое состояние """ GPIO.setIOvalue(1, state)
def setSIMSELECT(state): """Установка состояния выхода SIMSELECT Args: state: требуемое состояние """ GPIO.setIOvalue(5, state)
def feed(): b = GPIO.setIOvalue(11, 0) b = GPIO.setIOvalue(12, 0) MOD.sleep(10) b = GPIO.setIOvalue(11, 1) b = GPIO.setIOvalue(12, 1) msg = "Reseting External Watchdog" # Log.appendLog(msg) return 1
def toggleGPIO(id,z_on,z_off,anz): ra = '' while anz > 0: ra = GPIO.setIOdir(id,1,1) MOD.sleep(z_on) ra = GPIO.setIOdir(id,0,1) MOD.sleep(z_off) # flash continusly if ( anz != 99 ): anz = anz - 1 return ra
def blink_gpio12(self): """This Will Start the Led blink process This function will start the led blink process and continue until blink_active is false. """ if self.blink_active: threading.Timer(10, self.blink_gpio12).start() if self.blink_active: if GPIO.get("GPIO12") != "On": GPIO.set("GPIO12", "On") else: GPIO.set("GPIO12", "Off")
def handle_total_enrollment_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("total.enrollment") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_graduation_rate_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("graduation.rate") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_entrepreneurship_engineering_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("entrepreneurship.engineering") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_engineering_freshman_curriculum_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("engineering.freshman.curriculum") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_engineering_study_abroad_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("engineering.study.abroad") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_bathroom_directions_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("bathroom.directions") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_church_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("church") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def handle_nursing_synopsis_intent(self, message): GPIO.set("GPIO2", "Off") GPIO.set("GPIO3", "On") GPIO.set("GPIO4", "Off") time.sleep(1) self.speak_dialog("nursing.synopsis") time.sleep(1) #I put the V eyes here GPIO.set("GPIO4", "On") mycroft.audio.wait_while_speaking() GPIO.set("GPIO3", "Off")
def speak_joke(self, lang, category): GPIO.set("GPIO2", "Off") #Added GPIO.set("GPIO3", "On") #Added GPIO.set("GPIO4", "On") #Added self.speak(pyjokes.get_joke(language=lang, category=category)) mycroft.audio.wait_while_speaking() #Added GPIO.set("GPIO3", "Off") #Added
def setup(self, RF, RR, LF, LR): """This will set up the GPIO pins to move the robot""" self.RF = RF self.RR = RR self.LF = LF self.LR = LR OUT = 'out' IN = 'in' self.pins = GPIO() self.pins.setup(self.RF, OUT) self.pins.setup(self.RR, OUT) self.pins.setup(self.LF, OUT) self.pins.setup(self.LR, OUT)
def run(self): pp_last = None tmp_last = None hvgv_last = None vv_last = None while not self._stop.isSet(): # endless loop to read buttons if GPIO.input(self.sw_pp_pin) != pp_last: pp_last = GPIO.input(self.sw_pp_pin) if pp_last: self.queue.put("pp_on") else: self.queue.put("pp_off") if GPIO.input(self.sw_tmp_pin) != tmp_last: tmp_last = GPIO.input(self.sw_tmp_pin) if tmp_last: self.queue.put("tmp_on") else: self.queue.put("tmp_off") if GPIO.input(self.sw_hvgv_pin) != hvgv_last: hvgv_last = GPIO.input(self.sw_hvgv_pin) if hvgv_last: self.queue.put("hvgv_on") else: self.queue.put("hvgv_off") if GPIO.input(self.sw_vv_pin) != vv_last: vv_last = GPIO.input(self.sw_vv_pin) if vv_last: self.queue.put("vv_on") else: self.queue.put("vv_off") time.sleep(0.05) # small delay to prevent excessive CPU usage
def setupPins(self): gpio.setmode(gpio.BCM) gpio.setup(self.stepPin, gpio.OUT) gpio.setup(self.dirPin, gpio.OUT) # default to clockwise direction gpio.output(self.dirPin, 1) print("StepperDriver: Setup Complete")
def executeCommand(command): global OUT1_STATE global OUT1_OFF_TIME ok = 0 if (command.getCommand() == 'OUT1'): if (command.getParameter() == '0'): GPIO.setIOvalue(6, 0) OUT1_STATE = 0 ok = 1 if (command.getParameter() == '1'): GPIO.setIOvalue(6, 1) OUT1_STATE = 1 OUT1_OFF_TIME = MOD.secCounter() + int(CFG.get('OUT1TIME')) ok = 1 print('Set OUT1 to %s\r' % (command.getParameter())) elif (command.getCommand() == 'PASS'): CFG.set('PASS', command.getParameter()) CFG.write() print('PASS is set to: %s\r' % (command.getParameter())) ok = 1 elif (command.getCommand() == 'IN1ONTXT'): CFG.set('IN1ONTXT', command.getParameter()) CFG.write() print('IN1ONTXT is set to: %s\r' % (command.getParameter())) ok = 1 elif (command.getCommand() == 'IN1OFFTXT'): CFG.set('IN1OFFTXT', command.getParameter()) CFG.write() print('IN1OFFTXT is set to: %s\r' % (command.getParameter())) ok = 1 elif (command.getCommand() == 'OUT1TIME'): CFG.set('OUT1TIME', command.getParameter()) CFG.write() print('OUT1TIME is set to: %s\r' % (command.getParameter())) ok = 1 elif (command.getCommand() == 'ALERT'): CFG.set('ALERT', command.getParameter()) CFG.write() print('ALERT is set to: %s\r' % (command.getParameter())) ok = 1 elif (command.getCommand() == 'SMSDELETEALL'): CFG.set('SMSDELETEALL', command.getParameter()) CFG.write() print('SMSDELETEALL is set to: %s\r' % (command.getParameter())) ok = 1 if (ok == 1): return 'COMMAND %s OK;' % (command.getCommand()) else: return 'COMMAND %s WRONG;' % (command.getCommand())
def on_gpio12_change(self): """used to report the state of the led. This is attached to the on change event. And will speak the status of the led. """ status = GPIO.get("GPIO12") self.speak("Led is %s" % status)
def read_50PIN(): # This function receives data via External 50 pin Header Serial Port try: GPIO.setIOvalue(20, 0) #Set MUX SELECT, GPIO 20 value is Set to '0' res = SER.receive(10) except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> GSM864QP_SER' print 'METHOD -> read_50PIN()' return(res)
def send_DB9(inSTR): # This function sends data via External DB9 Serial Port try: GPIO.setIOvalue(20, 1) #Set MUX SELECT, GPIO 20 value is Set to '1' res = SER.send(str(inSTR)) except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> GSM864QP_SER' print 'METHOD -> send_DB9()' return(res)
def handle_command_intent(self, message): """This will handle all command intents for controlling GPIO This handles all commands to controll the LEDS including checking the status. Args: message(obj): This is the object containing the message that fired the intent. This is used to discover what to do within the intent. """ if message.data["command"].upper() == "BLINKING": #if message.data["ioobject"].upper() == "RED LED": if message.data["ioobject"].upper() == "BLUE LED": #self.speak_dialog("redledblink") self.speak_dialog("blueledblink") if self.blink_active: self.blink_active = False else: self.blink_active = True self.blink_gpio12() elif message.data["ioobject"].upper() == "GREEN LED": self.speak_dialog("greenledblink") if self.blink_active: self.blink_active = False else: self.blink_active = True self.blink_gpio13() elif message.data["ioparam"].upper() == "STOP": self.stop() elif message.data["command"].upper() == "STATUS": #if message.data["ioobject"].upper() == "RED LED": if message.data["ioobject"].upper() == "BLUE LED": self.on_gpio12_change() elif message.data["ioobject"].upper() == "GREEN LED": self.on_gpio13_change() elif message.data["command"].upper() == "TURN": #if message.data["ioobject"].upper() == "RED LED": if message.data["ioobject"].upper() == "BLUE LED": if "ioparam" in message.data: if message.data["ioparam"].upper() == "ON": self.blink_active = False GPIO.set("GPIO12", "On") elif message.data["ioparam"].upper() == "OFF": self.blink_active = False GPIO.set("GPIO12", "Off") else: self.speak_dialog("ipparamrequired") elif message.data["ioobject"].upper() == "GREEN LED": if "ioparam" in message.data: if message.data["ioparam"].upper() == "ON": self.blink_active = False GPIO.set("GPIO13", "On") elif message.data["ioparam"].upper() == "OFF": self.blink_active = False GPIO.set("GPIO13", "Off") else: self.speak_dialog("ipparamrequired")
def getOUT2(): """Чтение состояния реле 2 Returns: Состояние """ state = GPIO.getIOvalue(1) return state
def getOUT1(): """Чтение состояния реле 1 Returns: Состояние """ state = GPIO.getIOvalue(6) return state
def getJDR(): """Чтение состояния входа JD Returns: Состояние """ state = GPIO.getIOvalue(2) return state
def getSIMSELECT(): """Чтение состояния выхода SIMSELECT Returns: Состояние """ state = GPIO.getIOvalue(5) return state
def getSK2(): """Чтение состояния сухого контакта 2 Returns: Состояние """ state = GPIO.getIOvalue(3) return state
def getADC(): """Чтение значения АЦП Returns: Значение АЦП """ mV = GPIO.getADC(1) return mV
def getInputs(): val1 = GPIO.getPuzzleButton() if val1 != None: Event('puzzleClick', val1) if val1 == LONG_PRESS: Event('shutdown', None) val2 = GPIO.getJungleButton() if val2 != None: Event('jungleClick', val2) if val2 == LONG_PRESS: Event('changeDifficulty', None) val3 = GPIO.getRepeatButton() if val3 != None: Event('repeatClick', val3) if val3 == LONG_PRESS: Event('resetWifi', None) val4 = GPIO.getSkipButton() if val4 != None: Event('skipClick', val4)
def on_change(self, gpio): """used to report the state of the led. This is attached to the on change event. And will speak the status of the led. """ key = self.getSwitchKey(self.switches, gpio) status = GPIO.get(gpio) name = self.switches[key]['name'] self.speak("%s %s" % (name, status))
def GPS_LED(inStatus, inActive): # This function initializes the IO # Arguments: # inStatus : GPS LED status. Pass in either 'ON' or 'OFF' # OFF - LED always OFF # ON - LED always ON # inActive : GPS LED Usage. Pass in either 'ON' or 'OFF' # OFF - LED is not used, ignore LED commands # ON - LED is used, allow LED commands # # Returns: # 0: Pass # -1: Exception if (inActive == 'OFF'): #We are not using the LED, permanently turn it off and return as passing res = GPIO.setIOvalue(5, 0) return 0 tmpReturn = -1 try: #GPIO.setIOvalue(GPIOnumber, value) # 5 - GPS LED (User LED) if (inStatus == 'OFF'): res = GPIO.setIOvalue(5, 0) elif (inStatus == 'ON'): res = GPIO.setIOvalue(5, 1) if (res == -1): return tmpReturn #Errored out, 1 if no error -1 if error tmpReturn = 0 except: printException("GPS_LED") JANUS_SER.sendUART("GPS LED exception. \r\n") return tmpReturn
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None, spi=None, i2c_bus=None, i2c_address=SSD1305_I2C_ADDRESS, i2c=None): self._log = logging.getLogger('Adafruit_SSD1305.SSD1305Base') self._spi = None self._i2c = None self.width = width self.height = height self._pages = 4 self._buffer = [0] * (width * self._pages) # Default to platform GPIO if not provided. self._gpio = gpio if self._gpio is None: self._gpio = GPIO.get_platform_gpio() # Setup reset pin. self._rst = rst if not self._rst is None: self._gpio.setup(self._rst, GPIO.OUT) # Handle hardware SPI if spi is not None: self._log.debug('Using hardware SPI') self._spi = spi self._spi.set_clock_hz(8000000) # Handle software SPI elif sclk is not None and din is not None and cs is not None: self._log.debug('Using software SPI') self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs) # Handle hardware I2C elif i2c is not None: self._log.debug('Using hardware I2C with custom I2C provider.') self._i2c = i2c.get_i2c_device(i2c_address) else: self._log.debug('Using hardware I2C with platform I2C provider.') import Adafruit_GPIO.I2C as I2C if i2c_bus is None: self._i2c = I2C.get_i2c_device(i2c_address) else: self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus) # Initialize DC pin if using SPI. if self._spi is not None: if dc is None: raise ValueError('DC pin must be provided when using SPI.') self._dc = dc self._gpio.setup(self._dc, GPIO.OUT)
def ioProcessing(): if((int(CFG.get('OUT1TIME')) > 0) and (MOD.secCounter() > OUT1_OFF_TIME) and (OUT1_STATE == 1)): executeCommand(command.Command('OUT1', '0')) global IN1_STATE IN1_STATE_NEW = GPIO.getIOvalue(4) if(IN1_STATE_NEW != IN1_STATE): if(IN1_STATE_NEW == 1): sendAlert(CFG.get('IN1ONTXT')) else: sendAlert(CFG.get('IN1OFFTXT')) IN1_STATE = IN1_STATE_NEW
def init(): # This function initializes the IO # Arguments: # None # #GPIO Connections: # 1 - Cellular LED # 2 - GPS LED (User LED) try: rtnList = [-1,-1] #[return status,return data] # return status: # -1: Exception occurred # 0: No errors occurred, no return data # 1: No errors occurred, return data #Now set all used GPIO to proper states. #GPIO.setIOvalue(GPIOnumber, value) #We do not need the above command, setIODir works best for this. #GPIO.setIOdir(number, value, direction) a = GPIO.setIOdir(1, 0, 2) #Output, Alternate Function b = GPIO.setIOdir(2, 0, 1) #Output, LOW (LED OFF) if ( a == -1 or b == -1 ): return rtnList #Errored out rtnList[0] = 0 #no error, no data except: print sys.exc_info() rtnList[0] = -1 return rtnList
def on_change(self, gpio): """used to report the state of the led. This is attached to the on change event. And will speak the status of the led. """ key = self.getSwitchKey(self.switches, gpio) status = GPIO.get(gpio) name = self.switches[key]['name'] self.speak("%s is %s" % (name, status)) LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, "%s is %s" % (name, status))
def __init__(self): self.blink_active = False GPIO.on("GPIO12", self.on_gpio12_change) GPIO.on("GPIO13", self.on_gpio13_change) GPIO.on("Button", self.on_button_change) super(Respeaker2MicLedSkill, self).__init__(name="Respeaker2MicLedSkill")
def initGPS (speed,format): try: #GPS RESET, GPIO 18 configured as Output, value is Cleared to '0' #GPS held in RESET GPIO.setIOdir(18,1,1) #GPS RESET, GPIO 18 configured as Output, value is Cleared to '0' #GPS is running GPIO.setIOvalue(18, 0) #Init Serial Port Settings res = GSM864QP_SER.init_parameters(speed,format) MOD.sleep(10) res = GSM864QP_SER.send_50PIN('\r\n') #Disable all NMEA output sentences #NMEA GPS sentences will only transmit when polled by CW20.update() method res = GSM864QP_SER.send_50PIN('$PNMRX103,ALL,0\r\n') ## Start timeout timer CW20_timerA = timers.timer(0) CW20_timerA.start(2) # Empty Serial Port Buffer res = "junk" while(res != ""): res = GSM864QP_SER.read_50PIN() if (CW20_timerA.isexpired()): break except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> CW20' print 'METHOD -> initGPS(' + speed + ',' + format + ')' return
def Cellular_LED(inSLED): # This function sets the cellular LED # Arguments: # inStatus : GPS LED status. Pass in either 'ON' or 'OFF' # OFF - LED always OFF # ON - LED function ON # try: rtnList = [-1,-1] #[return status,return data] # return status: # -1: Exception occurred # 0: No errors occurred, no return data # 1: No errors occurred, return data #Set Stat LED to default value, 0 for OFF, 2 for ON if (inSLED == 'ON'): rtnList[1] = GPIO.setSLED(2, 10, 90) else: rtnList[1] = GPIO.setSLED(0, 10, 90) if (rtnList[1] == -1): #Errored out return rtnList rtnList = myATC.sendAtCmd('AT#SLEDSAV',myATC.properties.CMD_TERMINATOR,0,20) if (rtnList[1] == -1): #Errored out return rtnList rtnList[0] = 0 #no error, no data except: print sys.exc_info() rtnList[0] = -1 return rtnList
def USER_LED(inStatus): # This function initializes the IO # Arguments: # inStatus : GPS LED status. Pass in either 'ON' or 'OFF' # OFF - LED always OFF # ON - LED always ON # try: rtnList = [-1,-1] #[return status,return data] # return status: # -1: Exception occurred # 0: No errors occurred, no return data # 1: No errors occurred, return data #GPIO.setIOvalue(GPIOnumber, value) # 2 - GPS LED (User LED) if (inStatus == 'OFF'): rtnList[1] = GPIO.setIOvalue(2, 0) #Output, LOW (LED OFF) elif (inStatus == 'ON'): rtnList[1] = GPIO.setIOvalue(2, 1) #Output, HIGH (LED ON) if (rtnList[1] == -1): #Errored out return rtnList rtnList[0] = 0 #no error, no data except: print sys.exc_info() rtnList[0] = -1 return rtnList
def setup(self,RF,RR,LF,LR): """This will set up the GPIO pins to move the robot""" self.RF=RF self.RR=RR self.LF=LF self.LR=LR OUT='out' IN='in' self.pins = GPIO() self.pins.setup(self.RF, OUT) self.pins.setup(self.RR, OUT) self.pins.setup(self.LF, OUT) self.pins.setup(self.LR, OUT)
def init_parameters (speed,format): try: ## ######################################################################################################## ## Take control of UART_SEL input ## Warning don't externaly drive the UART_SEL input via 50-PIN header when controlling via this script!!!! ## ######################################################################################################## #MUX SELECT, GPIO 20 configured as Output, value is Set to '1' #DB9 connected to SER MODULE GPIO.setIOdir(20,1,1) #Init Serial Port Settings res = SER.set_speed(speed,format) except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> GSM864QP_SER' print 'METHOD -> init_parameters(' + speed + ',' + format + ')' return (res)
def main(): global uart global spi gpio.GPIO_init() try: while True: #SPI_mainloop() #GDL_mainloop() uart.xbee_mainloop() sys.stdout.flush() except KeyboardInterrupt(): exit_handler()
def __init__(self, resistor_channel, button_1_gpio, button_2_gpio, sw_debounce, scale_adc): self.control_bus = I2CBus.I2CBus(0x21) self.debouncer = Debouncer.Debouncer(0, 1, 0.4) self.sw_debounce = sw_debounce self.resistor_address = resistor_channel self.button_1_address = button_1_gpio self.button_2_address = button_2_gpio GPIO.add_channel(self.button_1_address, False) GPIO.add_channel(self.button_2_address, False) self.resistor_position = self.get_resistor_position() self.button_1_pressed = False self.button_2_pressed = False if scale_adc: self.scale_adc = True self.resistor_max = (4092 / Constants.resistor_max) * 2.5 self.resistor_min = (4092 / Constants.resistor_max) * 0.5 self.voltage_interval = (self.resistor_max - self.resistor_min) // Constants.height
def startEngine(sms): Helper.writeLog('#Begin: StartEngine function') Helper.writeLog('-Password in sms is '+sms.password) if Password == SavedPassword and SavedPassword != 0 : Helper.writeLog('-In Start engine Condition') GPSLat = getGPSLocation('Lat') Helper.writeLog('-Latitude= '+GPSLat) GPSLon = getGPSLocation('Lon') Helper.writeLog('-Longitude= '+GPSLon) GPIO.setIOvalue(8,1) Helper.writeLog('-Before Sending the SMS') SMSHandler.sendSMS(Number,'Your car now is ready to start at this location http://maps.google.com/?q='+GPSLat.rstrip().lstrip()+','+GPSLon.rstrip().lstrip()) Helper.writeLog('-Deleting SMS') SMSHandler.deleteSMS(MessageIndex,'STRT') else : Helper.writeLog('-Deleting SMS') SMSHandler.deleteSMS(MessageIndex,'STRT 2')
def SW_IGN_Status(): # This function reads the status of the event triggers, then toggles GPIO2 in response to signal the MCU that we received the information. # We are reading the MCU's signaling because it can poll and latch the states more accurately than directly reading in the python flow. # This allows less errors when reading the states in real time as well as catching a wake up event. # Arguments: # none # # Returns: # 0: Pass, Switch is triggered # 1: Pass, Ignition is triggered # 2: Pass, BOTH are triggered # -1: Exception # -2: Pass, Neither is triggered tmpReturn = -1 try: #GPIO.getIOvalue(GPIOnumber) # 7 - IIC SDA/IGNITION : Utilizing this as Event Ignition Flag, active LOW # 8 - IIC SCL/SWITCH : Utilizing this as Event N/O Switch Flag, active LOW #GPIO.setIOvalue(GPIOnumber, value) # 10 - GPIO2 : Utilizing this as the event received verification, active HIGH IgnRead = GPIO.getIOvalue(7) SwitchRead = GPIO.getIOvalue(8) if (IgnRead == 0 and SwitchRead == 1): #Ignition Active, based on signal from MCU res = GPIO.setIOvalue(10, 1) tmpReturn = 1 elif (IgnRead == 1 and SwitchRead == 0): #Switch Active, based on signal from MCU res = GPIO.setIOvalue(10, 1) tmpReturn = 0 elif (IgnRead == 0 and SwitchRead == 0): #Both Active, based on signal from MCU res = GPIO.setIOvalue(10, 1) tmpReturn = 2 elif (IgnRead == 1 and SwitchRead == 1): #Neither Active, based on signal from MCU tmpReturn = -2 if (tmpReturn != -1): res = GPIO.setIOvalue(10, 0) #Reset the GPIO signaling except: printException("SW_IGN Exception") JANUS_SER.sendUART("SW_IGN Exception \r\n") #Return value of GPIO get return tmpReturn
def startSuspend(self): bText = self.startSuspendButton.text() if bText == '开始' or bText == '继续': self.timer = QTimer(self) self.timer.timeout.connect(self.operate) self.timer.start(1000) self.startSuspendButton.setText('暂停') GPIO.setup() GPIO.loop() elif bText == '暂停': self.timer.deleteLater() self.startSuspendButton.setText('继续') GPIO.destroy()
import MOD import GPIO import MDM import GPS import AVL try: AVL.Mainloop() MDM.send('AT#REBOOT\r',0) except (Exception, StandardError, SystemError, RuntimeError): b = GPIO.setIOvalue(11, 0) MOD.sleep(10) print "exception in main"
SER.send('Mode is: %s\n' % Config.Mode) if Config.Mode == 'Active': transmitMessage(message) elif Config.Mode == 'Passive': storeMessage(message) elif Config.Mode == 'Buffered': SER.send('Buffered mode, todo!\n') endTime = MOD.secCounter() timeSpend = endTime - startTime sleepTime = Config.Interval - timeSpend SER.send("Spend: %s, Interval: %s, Sleep: %s\n" % (timeSpend, Config.Interval, sleepTime)) SER.send("GPIO: %s, RTS: %s\n" % (GPIO.getIOvalue(2), SER.getRTS())) # Sleep, but only if the emergency button isn't set. if sleepTime > 2 and GPIO.getIOvalue(2) == 0: SER.send('Going into powerSaving.\n') MOD.powerSaving(sleepTime) reason = MOD.powerSavingExitCause() SER.send("Woke up! Reason (0=ext,1=time): %s\n" % reason) if reason == 0: MOD.sleep(20) elif sleepTime > 0: SER.send('Idle sleep.\n') MOD.sleep(10 * sleepTime) else:
def init(inSLED): # This function initializes the IO # Arguments: # inSLED : Stat LED. Pass in either 'ON' or 'OFF' # OFF - LED always OFF # ON - LED follows registration status # # # Returns: # 0: Pass # -1: Exception #GPIO Connections: # 1 - Do not utilize (Required by GPS) # 2 - IGNITION, LOW when ignition is active # 3 - N/O Switch, HIGH when the switch is closed # 4 - Do not utilize (Required by GPS) # 5 - GPS LED (User LED) # 6 - Auto ON Control, pulse HIGH to toggle the MCU's operative state. use GPIO1 to verify the state # 7 - IIC SDA : Utilizing this as Wake up Event Ignition Flag. Pulled high externally # 8 - IIC SCL : Utilizing this as Wake up Event N/O Switch Flag. Pulled high externally # 9 - GPIO1 : Utilizing this for Auto-On Verification FROM the MCU, 1 for auto-on enabled, 0 for auto-on disabled # 10 - GPIO2 : Utilizing this for Wake up Event verification TO the MCU, 1 if Event has been seen/recorded, otherwise 0. tmpReturn = -1 try: #Set Stat LED to default value, 0 for OFF, 2 for ON if (inSLED == 'ON'): res = GPIO.setSLED(2, 10, 90) else: res = GPIO.setSLED(0, 10, 90) if (res == -1): #Errored out, 1 if no error -1 if error return tmpReturn #Now set all used GPIO to proper states. #GPIO.setIOvalue(GPIOnumber, value) #We do not need the above command, setIODir works best for this. #GPIO.setIOdir(number, value, direction) a = GPIO.setIOdir(2, 0, 0) #Input b = GPIO.setIOdir(3, 0, 0) #Input c = GPIO.setIOdir(5, 0, 1) #Output, LOW (LED OFF) d = GPIO.setIOdir(6, 1, 0) #Output, LOW (Auto-on OFF during INIT, taken care of in the command flow) e = GPIO.setIOdir(7, 0, 0) #Input f = GPIO.setIOdir(8, 0, 0) #Input g = GPIO.setIOdir(9, 0, 0) #Input h = GPIO.setIOdir(10, 0, 1) #Output, LOW (Wake up Event verification default sate, event NOT found) if ( a == -1 or b == -1 or c == -1 or d == -1 or e == -1 or f == -1 or g == -1 or h == -1 ): return tmpReturn #Errored out, 1 if no error -1 if error tmpReturn = 0 except: printException("IO_init") JANUS_SER.sendUART("IO Init exception. \r\n") return tmpReturn
def AutoONControl(inCommand, inSelection): # This function sends a signal to MCU to tell it whether or not to handle Auto On, # waits for response on GPIO1 to verify the MCU is in the proper state. # Arguments: # inCommand - Select what to do, enter 'READ' or 'SET'. # READ - Checks the MCU signal to verify the mode # SET - Utilizes inSelection to change the mode. # inSelection - Select to have the MCU run Auto-On or not, enter 'ON' or 'OFF. # OFF - Auto-On is Disabled # ON - Auto-On is Enabled # # Returns: # InCommand: READ # 0: Pass, Auto-on OFF # 1: Pass, Auto-on ON # -1: Exception # -2: Time out # InCommand: SET # 0: Pass, Auto-on OFF # 1: Pass, Auto-on ON # -1: Exception # -2: Time out tmpReturn = -1 try: #GPIO.getIOvalue(GPIOnumber) #MOD.sleep(20) #Delay # 9 - GPIO1 : Used as MCU signal verification if (inCommand == 'READ'): res = GPIO.getIOvalue(9) return res #GPIO.setIOvalue(GPIOnumber, value) # 6 - Auto ON Control # 9 - GPIO1 : Used as MCU signal verification if (inSelection == 'ON'): res = GPIO.setIOvalue(6, 1) #Set a Timer for a quick loop to verify, we do this because it's a "just in case" breakout as opposed to a simple delay and check. timerA = timers.timer(0) timerA.start(5) #5 seconds is MORE than enough. IoVal = GPIO.getIOvalue(9) #JANUS_SER.sendUART("Value from MCU: " + str(IoVal) + "\r\n") while (IoVal != 1): IoVal = GPIO.getIOvalue(9) if timerA.isexpired(): return (-2) #Time out while finding the signal res = GPIO.setIOvalue(6, 0) #End the HIGH pulse, MCU only toggles on a high signal return IoVal #Return the read value elif (inSelection == 'OFF'): res = GPIO.setIOvalue(6, 1) #Set a Timer for a quick loop to verify, we do this because it's a "just in case" breakout as opposed to a simple delay and check. timerA = timers.timer(0) timerA.start(5) #5 seconds is MORE than enough. IoVal = GPIO.getIOvalue(9) JANUS_SER.sendUART("Value from MCU: " + str(IoVal) + "\r\n") while (IoVal != 0): IoVal = GPIO.getIOvalue(9) if timerA.isexpired(): return (-2) #Time out while finding the signal res = GPIO.setIOvalue(6, 0) #End the HIGH pulse, MCU only toggles on a high signal return IoVal #Return the read value except: printException("SW_IGN Exception") JANUS_SER.sendUART("SW_IGN Exception \r\n") #Return Error value return tmpReturn