15 from .display_manager
import DisplayManager
20 API for the functions that affect the Mark I device. 21 NOTE: current state management is poorly implemented, 22 will be changed in the future. 28 This API is intended to be used to interface with the hardware 29 that is running Mycroft. It exposes all possible commands which 30 can be sent to a Mycroft enclosure implementation. 32 Different enclosure implementations may implement this differently 33 and/or may ignore certain API calls completely. For example, 34 the eyes_color() API might be ignore on a Mycroft that uses simple 35 LEDs which only turn on/off, or not at all on an implementation 36 where there is no face at all. 45 """Registers a skill as active. Used for speak() and speak_dialog() 46 to 'patch' a previous implementation. Somewhat hacky. 49 self.display_manager.set_active(self.
name)
51 self.display_manager.set_active(skill_name)
54 """The enclosure should restore itself to a started state. 55 Typically this would be represented by the eyes being 'open' 56 and the mouth reset to its default (smile or blank). 58 self.bus.emit(
Message(
"enclosure.reset"))
61 """The enclosure hardware should reset any CPUs, etc.""" 62 self.bus.emit(
Message(
"enclosure.system.reset"))
65 """Mute (turn off) the system speaker.""" 66 self.bus.emit(
Message(
"enclosure.system.mute"))
69 """Unmute (turn on) the system speaker.""" 70 self.bus.emit(
Message(
"enclosure.system.unmute"))
73 """The 'eyes' should blink the given number of times. 75 times (int): number of times to blink 77 self.bus.emit(
Message(
"enclosure.system.blink", {
'times': times}))
80 """Illuminate or show the eyes.""" 81 self.bus.emit(
Message(
"enclosure.eyes.on"))
84 """Turn off or hide the eyes.""" 85 self.bus.emit(
Message(
"enclosure.eyes.off"))
88 """Make the eyes blink 90 side (str): 'r', 'l', or 'b' for 'right', 'left' or 'both'
92 self.bus.emit(Message("enclosure.eyes.blink", {'side': side}))
94 def eyes_narrow(self):
95 """Make the eyes look narrow, like a squint"""
96 self.bus.emit(Message("enclosure.eyes.narrow"))
98 def eyes_look(self, side):
99 """Make the eyes look to the given side
101 side (str): '
r' for right 107 self.bus.emit(Message("enclosure.eyes.look", {'side': side})) 109 def eyes_color(self, r=255, g=255, b=255): 110 """Change the eye color to the given RGB color
112 r (int): 0-255, red value
113 g (int): 0-255, green value
114 b (int): 0-255, blue value
116 self.bus.emit(Message("enclosure.eyes.color", 117 {'r': r, 'g': g, 'b': b}))
119 def eyes_setpixel(self, idx, r=255, g=255, b=255):
120 """Set individual pixels of the Mark 1 neopixel eyes
122 idx (int): 0-11 for the right eye, 12-23 for the left
123 r (int): The red value to apply
124 g (int): The green value to apply
125 b (int): The blue value to apply
127 if idx < 0 or idx > 23:
128 raise ValueError('idx ({}) must be between 0-23'.format(str(idx)))
129 self.bus.emit(Message("enclosure.eyes.setpixel",
130 {'idx': idx, '
r': r, 'g': g, 'b': b}))
132 def eyes_fill(self, percentage):
133 """Use the eyes as a type of progress meter
135 amount (int): 0-49 fills the right eye, 50-100 also covers left
137 if percentage < 0 or percentage > 100:
138 raise ValueError('percentage ({}) must be between 0-100'.
139 format(str(percentage)))
140 self.bus.emit(Message("enclosure.eyes.fill",
141 {'percentage': percentage}))
143 def eyes_brightness(self, level=30):
144 """Set the brightness of the eyes in the display.
146 level (int): 1-30, bigger numbers being brighter
148 self.bus.emit(Message("enclosure.eyes.level", {'level': level}))
150 def eyes_reset(self):
151 """Restore the eyes to their default (ready) state."""
152 self.bus.emit(Message("enclosure.eyes.reset"))
155 """Make the eyes 'roll'
157 self.bus.emit(Message("enclosure.eyes.spin"))
159 def eyes_timed_spin(self, length):
160 """Make the eyes 'roll' for the given time.
162 length (int): duration in milliseconds of roll, None = forever
164 self.bus.emit(Message("enclosure.eyes.timedspin",
167 def eyes_volume(self, volume):
168 """Indicate the volume using the eyes
170 volume (int): 0 to 11
172 if volume < 0 or volume > 11:
173 raise ValueError('volume ({}) must be between 0-11'.
175 self.bus.emit(Message("enclosure.eyes.volume", {'volume': volume}))
177 def mouth_reset(self):
178 """Restore the mouth display to normal (blank)"""
179 self.bus.emit(Message("enclosure.mouth.reset"))
180 self.display_manager.set_active(self.name)
182 def mouth_talk(self):
183 """Show a generic 'talking' animation for non-synched speech"""
184 self.bus.emit(Message("enclosure.mouth.talk"))
185 self.display_manager.set_active(self.name)
187 def mouth_think(self):
188 """Show a 'thinking' image or animation"""
189 self.bus.emit(Message("enclosure.mouth.think"))
190 self.display_manager.set_active(self.name)
192 def mouth_listen(self):
193 """Show a 'thinking' image or animation"""
194 self.bus.emit(Message("enclosure.mouth.listen"))
195 self.display_manager.set_active(self.name)
197 def mouth_smile(self):
198 """Show a 'smile' image or animation"""
199 self.bus.emit(Message("enclosure.mouth.smile"))
200 self.display_manager.set_active(self.name)
202 def mouth_viseme(self, start, viseme_pairs):
203 """ Send mouth visemes as a list in a single message.
206 start (int): Timestamp for start of speech
207 viseme_pairs: Pairs of viseme id and cumulative end times
211 0 = shape for sounds like 'y' or 'aa'
212 1 = shape for sounds like 'aw'
213 2 = shape for sounds like 'uh' or '
r' 214 3 = shape for sounds like
'th' or 'sh' 215 4 = neutral shape
for no sound
216 5 = shape
for sounds like
'f' or 'v' 217 6 = shape
for sounds like
'oy' or 'ao' 219 self.bus.emit(Message("enclosure.mouth.viseme_list", 220 {"start": start, "visemes": viseme_pairs})) 222 def mouth_text(self, text=""): 223 """Display text (scrolling
as needed)
225 text (str): text string to display
227 self.display_manager.set_active(self.name) 228 self.bus.emit(Message("enclosure.mouth.text", {'text': text})) 230 def mouth_display(self, img_code="", x=0, y=0, refresh=True): 231 """Display images on faceplate. Currently supports images up to 16x8,
232 or half the face. You can use the
'x' parameter to cover the other
233 half of the faceplate.
235 img_code (str): text string that encodes a black
and white image
236 x (int): x offset
for image
237 y (int): y offset
for image
238 refresh (bool): specify whether to clear the faceplate before
239 displaying the new image
or not.
240 Useful
if you
'd like to display multiple images 241 on the faceplate at once. 243 self.display_manager.set_active(self.name) 244 self.bus.emit(Message('enclosure.mouth.display', 245 {'img_code': img_code, 248 'clearPrev': refresh})) 250 def mouth_display_png(self, image_absolute_path, 251 invert=False, x=0, y=0, refresh=True): 252 """ Send an image to the enclosure.
255 image_absolute_path (string): The absolute path of the image
256 invert (bool): inverts the image being drawn.
257 x (int): x offset
for image
258 y (int): y offset
for image
259 refresh (bool): specify whether to clear the faceplate before
260 displaying the new image
or not.
261 Useful
if you
'd like to display muliple images 262 on the faceplate at once. 264 self.display_manager.set_active(self.name) 265 self.bus.emit(Message("enclosure.mouth.display_image", 266 {'img_path': image_absolute_path, 270 'clearPrev': refresh})) 272 def weather_display(self, img_code, temp): 273 """Show a the temperature
and a weather icon
276 img_code (char): one of the following icon codes
285 temp (int): the temperature (either C
or F,
not indicated)
287 self.display_manager.set_active(self.name) 288 self.bus.emit(Message("enclosure.weather.display", 289 {'img_code': img_code, 'temp': temp})) 291 def activate_mouth_events(self): 292 """Enable movement of the mouth with speech
""" 293 self.bus.emit(Message('enclosure.mouth.events.activate')) 295 def deactivate_mouth_events(self): 296 """Disable movement of the mouth with speech
""" 297 self.bus.emit(Message('enclosure.mouth.events.deactivate'))
def eyes_blink(self, side)
def register(self, skill_name="")
def system_blink(self, times)
def __init__(self, bus, name="")