1#!/usr/bin/python2 2 3import sys 4import time 5from time import sleep 6import util 7import it6803 8 9usage = """\ 10Usage: 11 cec_service -- print command usage 12 cec_service start -- run cec service 13""" 14 15powerOn = True 16 17def main(cmdline): 18 args = [''] * 4 19 for i, x in enumerate(cmdline): 20 args[i] = x 21 cmd = args[1] 22 23 if cmd == '': cmd = 'help' 24 fname = 'cmd_' + cmd 25 26 if fname in globals(): 27 if args[2] == '': 28 globals()[fname]() 29 else: 30 globals()[fname](args[2]) 31 else: 32 print 'Unknown command', cmd 33 34def cmd_start(): 35 it6803.cec_open() 36 it6803.cec_init() 37 while True: 38 code = it6803.cec_msg_receive() 39 if code is not None: 40 if code == 0x36: 41 handle_standBy() 42 elif code == 0x04: 43 handle_imageOn() 44 elif code == 0x8F: 45 handle_powerStatus() 46 else: 47 print 'Unknow command' 48 it6803.cec_close() 49 return 50 51def handle_standBy(): 52 global powerOn 53 powerOn = False 54 return 55 56def handle_imageOn(): 57 global powerOn 58 powerOn = True 59 return 60 61def handle_powerStatus(): 62 global powerOn 63 print 'power status: {}'.format(powerOn) 64 if powerOn: 65 it6803.cec_msg_poweron() 66 else: 67 it6803.cec_msg_poweroff() 68 it6803.cec_transmit() 69 return 70 71 72if __name__ == '__main__': 73 main(sys.argv) 74