18 This module provides basic "state" for the visual representation associated 19 with this Mycroft instance. The current states are: 20 ActiveSkill - The skill that last interacted with the display via the 23 Currently, a wakeword sets the ActiveSkill to "wakeword", which will auto 24 clear after 10 seconds. 26 A skill is set to Active when it matches an intent, outputs audio, or 27 changes the display via the EnclosureAPI() 29 A skill is automatically cleared from Active two seconds after audio 30 output is spoken, or 2 seconds after resetting the display. 32 So it is common to have '' as the active skill. 36 from threading
import Thread, Timer
46 """ Writes the dictionary of state data to the IPC directory. 49 dictionary (dict): information to place in the 'disp_info' file 54 path = os.path.join(managerIPCDir,
"disp_info")
55 permission =
"r+" if os.path.isfile(path)
else "w+" 57 if permission ==
"w+" and os.path.isdir(managerIPCDir)
is False:
58 os.makedirs(managerIPCDir)
59 os.chmod(managerIPCDir, 0o777)
62 with open(path, permission)
as dispFile:
65 if os.stat(str(dispFile.name)).st_size != 0:
66 data = json.load(dispFile)
70 LOG.info(
"Display Manager is creating " + dispFile.name)
72 for key
in dictionary:
73 data[key] = dictionary[key]
76 dispFile.write(json.dumps(data))
81 except Exception
as e:
83 LOG.error(
"Error found in display manager file, deleting...")
89 """ Writes the dictionary of state data from the IPC directory. 91 dict: loaded state information 95 path = os.path.join(managerIPCDir,
"disp_info")
96 permission =
"r" if os.path.isfile(path) else "w+"
98 if permission ==
"w+" and os.path.isdir(managerIPCDir)
is False:
99 os.makedirs(managerIPCDir)
103 with open(path, permission)
as dispFile:
105 if os.stat(str(dispFile.name)).st_size != 0:
106 data = json.load(dispFile)
108 except Exception
as e:
117 """ The Display manager handles the basic state of the display, 118 be it a mark-1 or a mark-2 or even a future Mark-3. 124 """ Sets skill name as active in the display Manager 128 name = skill_name
if skill_name
is not None else self.
name 132 """ Get the currenlty active skill from the display manager 134 string: The active skill's name 139 if "active_skill" in data:
140 active_skill = data[
"active_skill"]
145 """ Clears the active skill """ 146 LOG.debug(
"Removing active skill...")
151 """ Connects the display manager to the messagebus """ 152 LOG.info(
"Connecting display manager to messagebus")
157 should_remove = [
True]
159 def check_flag(flag):
161 display_manager.remove_active()
163 def set_delay(event=None):
164 should_remove[0] =
True 165 Timer(2, check_flag, [should_remove]).start()
167 def set_remove_flag(event=None):
168 should_remove[0] =
False 173 def remove_wake_word():
175 if "active_skill" in data
and data[
"active_skill"] ==
"wakeword":
176 display_manager.remove_active()
178 def set_wakeword_skill(event=None):
179 display_manager.set_active(
"wakeword")
180 Timer(10, remove_wake_word).start()
183 bus.on(
'recognizer_loop:audio_output_end', set_delay)
184 bus.on(
'recognizer_loop:audio_output_start', set_remove_flag)
185 bus.on(
'recognizer_loop:record_begin', set_wakeword_skill)
187 event_thread = Thread(target=connect)
188 event_thread.setDaemon(
True)
def _write_data(dictionary)
def init_display_manager_bus_connection()
def set_active(self, skill_name=None)
def __init__(self, name=None)
def get_ipc_directory(domain=None)