-
Notifications
You must be signed in to change notification settings - Fork 0
/
maincontroler_class.py
100 lines (84 loc) · 3.45 KB
/
maincontroler_class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Raspberry Pi Main Controler class
#
# Copyright Julien Bellion 2014-2015 (https://github.com/neinoi)
#
# License: GNU V3, See https://www.gnu.org/copyleft/gpl.html
#
# Disclaimer: Software is provided as is and absolutly no warranties are
# implied or given.
# The authors shall not be liable for any loss or damage however caused.
#
import logging
from controlers.controler_base import Controler
from controlers.MenuPrincipal import MenuPrincipal
from encoders.encoder_class import Encoder
from controlers.MessageDisplay import MessageDisplay,ROTATING_DISPLAY
class MainControler(Controler):
currentControler = None
ready = False
startupSong = None
btVolumeDown = False
btTunerDown = False
def __init__(self, config, lcd, mpdService):
Controler.__init__(self, config, lcd, mpdService, None)
self.setControler(MenuPrincipal(config, lcd, mpdService, self))
# This is the callback routine to handle tuner events
def tuner_event(self, event):
logging.info('event')
if self.ready and self.currentControler is not None:
if event == Encoder.CLOCKWISE:
self.currentControler.tunerUp()
elif event == Encoder.ANTICLOCKWISE:
self.currentControler.tunerDown()
elif event == Encoder.BUTTONUP:
self.btTunerDown = False
self.currentControler.tunerClickUp()
elif event == Encoder.BUTTONDOWN:
self.btTunerDown = True
if self.btVolumeDown:
self.shutdown()
else:
self.currentControler.tunerClickDown()
# This is the callback routine to handle volume events
def volume_event(self, event):
logging.info('event')
if self.ready and self.currentControler is not None:
if event == Encoder.CLOCKWISE:
self.currentControler.volumeUp()
elif event == Encoder.ANTICLOCKWISE:
self.currentControler.volumeDown()
elif event == Encoder.BUTTONUP:
self.btVolumeDown = False
self.currentControler.volumeClickUp()
elif event == Encoder.BUTTONDOWN:
self.btVolumeDown = True
if self.btTunerDown:
self.shutdown()
else:
self.currentControler.volumeClickDown()
def shutdown(self):
self.setControler(MessageDisplay("", "Arret en cours", ROTATING_DISPLAY, self.lcd))
self.execCommand(self.config.getShutdownCommand())
self.execCommand("halt")
def setControler(self, newControler):
logging.debug('MainControler..current : {0}'.format(self.currentControler))
logging.debug('MainControler..new : {0}'.format(newControler))
if self.currentControler is not None:
self.currentControler.stop()
if newControler is not None:
self.currentControler = newControler
self.currentControler.refresh()
def setReady(self, isReady):
self.ready = isReady
self.startupSong = self.mpdService.getCurrentSong()
logging.debug('Startup song : {0}'.format(self.startupSong))
if isReady:
self.execCommand(self.config.getStartupCommand())
self.currentControler.setReady(True)
self.mpdService.run()
def stop(self):
pass
# End of MainControler class