1 import RPi.GPIO as GPIO
2 from RPLCD.gpio import CharLCD
7 from signal import signal, SIGINT
9 import gaugette.rotary_encoder
11 import gaugette.switch
20 timeout=time.localtime()
22 lcd = CharLCD(cols=40, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23], numbering_mode=GPIO.BOARD)
25 gpio = gaugette.gpio.GPIO()
26 encoder = gaugette.rotary_encoder.RotaryEncoder(gpio, A_PIN, B_PIN)
28 switch = gaugette.switch.Switch(gpio, SW_PIN)
30 sw = gaugette.switch.Switch(gpio, SW_PIN)
31 last_state = sw.get_state()
33 def handler(signal_received, frame):
35 print('SIGINT or CTRL-C detected. Exiting gracefully')
38 def get_ip_address(ifname):
39 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
40 return socket.inet_ntoa(fcntl.ioctl(
43 struct.pack('256s', ifname[:15])
48 lcd.write_string("IP Address:")
49 lcd.cursor_pos = (1, 0)
50 lcd.write_string(get_ip_address('eth0'))
52 def display_time(lcd):
54 lcd.write_string("Time: %s" %time.strftime("%H:%M:%S"))
55 lcd.cursor_pos = (1, 0)
56 lcd.write_string("Date: %s" %time.strftime("%m/%d/%Y"))
58 def display_reboot(lcd):
60 lcd.write_string("Reboot?")
62 def display_blank(lcd):
64 lcd.write_string("Dynamic screen status")
66 if __name__ == '__main__':
67 signal(SIGINT, handler)
69 delta = encoder.get_cycles()
70 state = sw.get_state()
71 if state != last_state:
72 print "switch %d" % state
76 lcd.write_string("Rebooting!!!")
78 os.system("sudo reboot")
98 #print "rotate %d" % delta
102 if timeout!=time.localtime():
104 timeout=time.localtime()