def safety_callback(channel): open(config.get('task', 'lock_file'), 'w').close() message = {'type': '', 'code': ''} write_emergency(json.dumps(message)) su = SerialUtils() GPIO_STATUS=GPIO.input(2) type="emergency" if(GPIO_STATUS == 0): su.sendGCode('M730') reply = su.getReply() #print ">>>> ", reply if(reply != ''): decodedReply = decodeReply(reply) if decodedReply != None : special_codes = [110, 120, 121] if(decodedReply in special_codes): if decodedReply == 110: type="alert" su.flush() su.sendGCode('M999') elif decodedReply == 120 or decodedReply == 121: if(settings['bothy'] == 'Shutdown' or settings['bothz'] == 'Shutdown'): call (['sudo php /var/www/fabui/application/modules/controller/ajax/shutdown.php'], shell=True) GPIO.cleanup() #we can disable GPIO as we are rebooting the system. message = {'type': type, 'code': str(decodedReply)} ws.send(json.dumps(message)) write_emergency(json.dumps(message)) su.flush() su.close() GPIO_STATUS=GPIO.HIGH if os.path.isfile(config.get('task', 'lock_file')): os.remove(config.get('task', 'lock_file'))
def safety_callback(channel): open(config.get('task', 'lock_file'), 'w').close() message = {'type': '', 'code': ''} write_emergency(json.dumps(message)) su = SerialUtils() GPIO_STATUS = GPIO.input(2) type = "emergency" if (GPIO_STATUS == 0): su.sendGCode('M730') reply = su.getReply() #print ">>>> ", reply if (reply != ''): decodedReply = decodeReply(reply) if decodedReply != None: special_codes = [110, 120, 121] if (decodedReply in special_codes): if decodedReply == 110: type = "alert" su.flush() su.sendGCode('M999') elif decodedReply == 120 or decodedReply == 121: if (settings['bothy'] == 'Shutdown' or settings['bothz'] == 'Shutdown'): call([ 'sudo php /var/www/fabui/application/modules/controller/ajax/shutdown.php' ], shell=True) GPIO.cleanup( ) #we can disable GPIO as we are rebooting the system. message = {'type': type, 'code': str(decodedReply)} ws.send(json.dumps(message)) write_emergency(json.dumps(message)) su.flush() su.close() GPIO_STATUS = GPIO.HIGH if os.path.isfile(config.get('task', 'lock_file')): os.remove(config.get('task', 'lock_file'))
class SerialFactory(): def __init__(self): self.serial = SerialUtils(debug=False) self.reply = None self.command = None self.response = {} def get_eeprom(self): self.response = self.serial.eeprom() self.output() def restore_eeprom(self): self.send('M502', False) self.send('M500', False) self.output() def send(self, codes, output = True): codes = codes.split('-') replies = [] for code in codes: self.serial.sendGCode(code) replies.append(self.serial.getReply()) time.sleep(0.2) self.command = codes self.reply = replies if(output): self.output() def output(self): object = { 'response' : self.response, 'command' : self.command, 'reply' : self.reply } print json.dumps(object)
class SerialFactory(): def __init__(self): self.serial = SerialUtils(debug=False) self.reply = None self.command = None self.response = {} def get_eeprom(self): self.response = self.serial.eeprom() self.output() def restore_eeprom(self): self.send('M502', False) self.send('M500', False) self.output() def send(self, codes, output=True): codes = codes.split('-') replies = [] for code in codes: self.serial.sendGCode(code) replies.append(self.serial.getReply()) time.sleep(0.2) self.command = codes self.reply = replies if (output): self.output() def output(self): object = { 'response': self.response, 'command': self.command, 'reply': self.reply } print json.dumps(object)