def process(self, item): '''Socket command handler that blocks while perfroming rgbmatrix actions''' #set pixel command: 127 X Y R G B # 0 1 2 3 4 5 cmd = item.command addr = item.addr if len(cmd) == 0: return #must be invalid datacmd = cmd[0] dataarg = '' if len(cmd) > 1: dataarg = cmd[1:] logging.debug('handling cmd ' + str(ord(datacmd)) + ' [' + str(dataarg) + '] for ' + str(addr)) if ord(datacmd) == 126: logging.info('Clearing screen') self.parent.queue.append( SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.Clear)) elif ord(datacmd) == 127 and len(cmd) == 6: x, y, r, g, b = ord(dataarg[0]), ord(dataarg[1]), ord( dataarg[2]), ord(dataarg[3]), ord(dataarg[4]) logging.info('Setting matrix pixel at x=' + str(x) + ' y=' + str(y) + ' to color r=' + str(r) + ',g=' + str(g) + ',b=' + str(b)) self.parent.queue.append( SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.SetPixel, x, y, r, g, b)) elif ord(datacmd) == 128: logging.info('Displaying image') self.parent.queue.append( SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.SetMatrixFromImgBase64, dataarg)) elif ord(datacmd) == 129: filepath = '/home/pi/wav/' + dataarg if not os.path.exists(filepath): logging.info('(Play wav) File does not exist: ' + filepath) return logging.info('Playing wav file with audio visualizer:' + filepath) self.parent.queue.append( SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.AudioVisualize, filepath)) elif ord(datacmd) == 130: #stop playing wav file logging.info('Attempting to stop audio thread') #self.queue.append(SerializableQueueItem(self.rgbm.StopAudioVisualize)) #will not work because the queuehandler is waiting for is_idle if self.parent.rgbm.is_audiovisualizing(): self.parent.rgbm.StopAudioVisualize() elif ord(datacmd) == 131: #remote queue item transfer logging.info( 'Attempting to translate received queue item into a reference') open('/tmp/remotecmddata.txt', 'w').write(dataarg) queueitem = SerializableQueueItem.__fromstr__(dataarg) self.parent.queue.append(queueitem) else: logging.warn('Unknown command, not doing anything')
def GET(self, filename): SharedQueue = self.currentInstance.queue rgbm = self.currentInstance.rgbm if not filename: logging.warn( 'WebService_PlayWav_And_State_JSONP missing filename argument') return 'WebService_PlayWav_And_State_JSONP missing filename argument' # this will in turn cause an exception in JS.. desired? IDK filepath = '/home/pi/wav/' + filename # TODO: get this path from config if not os.path.exists(filepath): logging.info( 'WebService_PlayWav_And_State_JSONP File path does not exist: ' + filepath) return 'WebService_PlayWav_And_State_JSONP File path does not exist: ' + filepath # if rgbm.is_audiovisualizing(): # not sure if this will work properly - it did not, we got idle state with music playing # rgbm.StopAudioVisualize() logging.info( 'WebService_PlayWav_And_State_JSONP Playing wav file with audio visualizer:' + filepath) SharedQueue.append( SerializableQueueItem('LEDMatrixCore', rgbm.AudioVisualize, filepath)) time.sleep( 0.2 ) # give the main loop time to fetch this item (alternatively, can we push it directly to the SM?) return rgbm.get_json_state()
def GET(self, imageb64data): SharedQueue = self.currentInstance.queue rgbm = self.currentInstance.rgbm if not imageb64data: logging.warn('WebService_ImageSetBase64Data_And_State_JSONP missing imageb64data argument') #could switch this for a json error object? raise BaseException('WebService_ImageSetBase64Data_And_State_JSONP missing imageb64data argument') #this will in turn cause an exception in JS.. desired? IDK logging.info('Attempting to set image from base64 data - test') SharedQueue.append(SerializableQueueItem('LEDMatrixCore', rgbm.SetMatrixFromImgBase64, imageb64data)) return rgbm.get_json_state()
def GET(self, id, text): _id = 0 try: _id = int(id) except ValueError: pass logging.info('Cec set osd text on dev ' + id + ': ' + text) self.currentInstance.queue.append( SerializableQueueItem(HACec.__name__, self.currentInstance.cec_client_osd, _id, text)) return self.currentInstance.get_json_status()
def GET(self, id): _id = 0 try: _id = int(id) except ValueError: pass if 1: logging.info('Cec power on: ' + id) self.currentInstance.queue.append( SerializableQueueItem(HACec.__name__, self.currentInstance.cec_client_standby, _id)) return self.currentInstance.get_json_status()
def GET(self, imageb64data): if not imageb64data: logging.warn( 'WebService_ImageSetBase64Data_And_State_JSONP missing imageb64data argument' ) return 'WebService_ImageSetBase64Data_And_State_JSONP missing imageb64data argument' #this will in turn cause an exception in JS.. desired? IDK logging.info('Attempting to set image from base64 data') callback_name = web.input(callback='jsonCallback').callback web.header('Content-Type', 'application/javascript') queue.append( SerializableQueueItem(rgbm.SetMatrixFromImgBase64, imageb64data)) return '%s(%s)' % (callback_name, rgbm.get_json_state())
def process(self, item): '''Socket command handler that blocks while perfroming rgbmatrix actions''' #set pixel command: 127 X Y R G B # 0 1 2 3 4 5 cmd = item.command addr = item.addr if len(cmd) == 0: return #must be invalid datacmd = cmd[0] dataarg = '' if len(cmd) > 1: dataarg = cmd[1:] logging.debug('handling cmd ' + str(ord(datacmd)) + ' [' + str(dataarg) + '] for ' + str(addr)) if ord(datacmd) == 126: logging.info('Clearing screen') self.parent.queue.append(SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.Clear)) elif ord(datacmd) == 127 and len(cmd) == 6: x, y, r, g, b = ord(dataarg[0]), ord(dataarg[1]), ord(dataarg[2]), ord(dataarg[3]), ord(dataarg[4]) logging.info('Setting matrix pixel at x=' + str(x) + ' y=' + str(y) + ' to color r=' + str(r) + ',g=' + str(g) + ',b=' + str(b)) self.parent.queue.append(SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.SetPixel,x,y,r,g,b)) elif ord(datacmd) == 128: logging.info('Displaying image') self.parent.queue.append(SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.SetMatrixFromImgBase64,dataarg)) elif ord(datacmd) == 129: filepath = '/home/pi/wav/' + dataarg if not os.path.exists(filepath): logging.info('(Play wav) File does not exist: ' + filepath) return logging.info('Playing wav file with audio visualizer:' + filepath) self.parent.queue.append(SerializableQueueItem(self.parent.__class__.__name__, self.parent.rgbm.AudioVisualize,filepath)) elif ord(datacmd) == 130: #stop playing wav file logging.info('Attempting to stop audio thread') #self.queue.append(SerializableQueueItem(self.rgbm.StopAudioVisualize)) #will not work because the queuehandler is waiting for is_idle if self.parent.rgbm.is_audiovisualizing(): self.parent.rgbm.StopAudioVisualize() elif ord(datacmd) == 131: #remote queue item transfer logging.info('Attempting to translate received queue item into a reference') open('/tmp/remotecmddata.txt', 'w').write(dataarg) queueitem = SerializableQueueItem.__fromstr__(dataarg) self.parent.queue.append(queueitem) else: logging.warn('Unknown command, not doing anything')
def GET(self, filename): if not filename: logging.warn( 'WebService_PlayWav_And_State_JSONP missing filename argument') return 'WebService_PlayWav_And_State_JSONP missing filename argument' #this will in turn cause an exception in JS.. desired? IDK filepath = '/home/pi/wav/' + filename #TODO: get this path from config if not os.path.exists(filepath): logging.info( 'WebService_PlayWav_And_State_JSONP File path does not exist: ' + filepath) return 'WebService_PlayWav_And_State_JSONP File path does not exist: ' + filepath #if rgbm.is_audiovisualizing(): #not sure if this will work properly - it did not, we got idle state with music playing # rgbm.StopAudioVisualize() logging.info( 'WebService_PlayWav_And_State_JSONP Playing wav file with audio visualizer:' + filepath) queue.append(SerializableQueueItem(rgbm.AudioVisualize, filepath)) time.sleep( 0.2 ) #give the main loop time to fetch this item (alternatively, can we push it directly to the SM?) callback_name = web.input(callback='jsonCallback').callback web.header('Content-Type', 'application/javascript') return '%s(%s)' % (callback_name, rgbm.get_json_state())
def GET(self, id, state): _state = state.lower() == 'true' logging.info('WebService_SetLightState id ' + id + ' state ' + str(_state)) self.currentInstance.queue.append(SerializableQueueItem(HAPhilipsHue.__name__, self.currentInstance.set_light_state, id, _state)) # time.sleep(0.5) #let the state get updated.. or just set it in cache directly? return '{}' #no update.. self.currentInstance.get_json_status() #TODO: return cache + this change?