Commit Graph

236 Commits (a1fdae3415e9d3006e6a4348468058232bc13db0)

Author SHA1 Message Date
Åke Forslund 09b1deb511 Add possibility for notification hooks for services
- skills
- audio
- speech client
- messagebus service
- enclosure

The main functions now accepts the arguments ready_hook and error_hook
allowing a service or runner script to catch these states and perform
actions accordingly.

This is useful for things like systemd or a desktop launcher.

Fix audio service startup
2020-07-22 10:52:27 +02:00
Bart Ribbers 531f78c499
Move requirements.txt to a new requirements folder and add optional deps
Some dependencies aren't actually required but can be optionally
installed for extra functionality.

The Chromecast is an optional audio backend
VLC is an optional audio backend
pyalsaaudio is only used by the mark1 enclosure
google-api-python-client is an optional STT backend, by default Mycroft
uses the Mycroft servers
2020-05-11 15:31:10 +02:00
Åke Forslund 6d13872638 Cleanup of the enclosure entrypoint
- split out enclosure determination code
- Add docstrings
- Increase logging
2020-04-16 10:58:07 +02:00
Åke Forslund 290d950424 Fix shutdown of enclosure process
Previously it would always be killed, now it exits smoothly.
2020-04-16 09:47:53 +02:00
Åke Forslund b7cf8e755e Remove origin check from gui websocket
This allows simple websocket clients to connect as well.
2020-04-04 09:15:47 +02:00
Åke Forslund 4f65591c21 Simplify the GUI websocket code
Use a single websocket but don't send data from clients to other
clients.
2020-04-04 09:13:51 +02:00
jarbasal 9d712a898f Update docstrings 2020-03-30 12:05:58 +02:00
jarbasal efc9af558a Read mark1 eye color 2020-03-30 12:05:49 +02:00
Åke 05cae9d319
Merge pull request #2429 from MycroftAI/bug/mark1_faceplate
mark1/fix display big images
2020-03-06 18:10:40 +01:00
Åke Forslund 2070e9aac9 Bump enclosure version 2020-03-02 15:25:22 +01:00
JarbasAI 46af6fcff2
mark1/fix display big images
https://github.com/MycroftAI/enclosure-mark1/blob/master/protocols.txt#L141

according to the spec there is a bug
2019-12-17 01:34:08 +00:00
Åke Forslund 04e9812992 Asyncio updates for gui connections
- Workaround, ensure asyncio event loop is launched on each thread.
2019-11-26 14:21:49 +01:00
Chris Veilleux 0bde1bc9df Refactor skill service (#2220)
Major refactoring of the skills startup sequence
- Restructure to a less nested structure
- Remove usage of globals by wrapping a lot of state variables into a class this allows for things like caching a negative pairing status throughout the startup process
2019-07-26 08:53:27 +02:00
Chris Veilleux d8f3095d40 Rename the message bus client and abstract config loading
Message bus config loading is now shared by service and client.

messagebus.client.ws file is still available in case skills are using it. It is a backport that inherits from the new MessageBusClient class. Adds depreciation warning.
2019-07-19 08:16:54 +02:00
Åke 6357513970 GUI updates (#2114)
* Catch the new system.gui.user.interaction

This will in turn trigger the gui.page_interaction similar to the page flip but page_number will be None

* Fix issue when adding pages

Seems like appending would fail at times

* Add lock around namespace modifications

* Improve argument description for override_idle
2019-05-31 03:44:09 -05:00
Åke 566630d9e3 Fix infinily adding pages to existing namespace (#2093)
Update the local representation with the new pages when appending pages to an existing namespace.
2019-04-11 13:24:43 -05:00
Åke feb82a2bb1 Add the SkillGUI method send_event() (#2057)
* Add the SkillGUI method send_event()

Sends raw mycroft.events.triggered messages to the gui for the skills namespace.

Example usage:
  self.gui.send_event('event_name' {'param1': 12, 'param2': 'abc'})
2019-03-27 01:22:05 -05:00
Åke Forslund 3d366013b9 Activate/deactivate visemes on command
When showing text the visemes would overwrite it. This inhibits the visemes when mouth events are turned off and reenables them when activated.
2019-02-28 16:04:43 +01:00
Åke d3e6a10ecc GUI Remove pages/namespaces (#2002)
* Add remove page methods

* Implement SkillGUI.clear()

The method will now remove the namespace entirely from the gui.

This adds the message gui.clear.namespace

* Remove debug prints from SkillGUI

* Correcting docstring

* More docstring changes

* Remove whitespace added by Github webUI
2019-02-28 00:21:08 -06:00
Åke 267c7bf571 Single viseme message (#1973)
* Add new api command to send visemes as single list.  This allows more efficient use of the messagebus and gives implementors flexibility in how they handle the visualization.

* Switch mark1 to use viseme_list
2019-01-31 00:37:55 -06:00
Åke 9ef95506d0 GUI update number 6 (#1964)
* Add communication from GUI to skills

- "set" events from Qt will set/update a variable in the skills .gui member
- It's possible to add general event handlers using self.gui.register_handler()
- Moved registration of skill_id to just after skill init

* Ensure that simultaneously writes doesn't occur

Wrap WebSocketHandler.write_message() with a lock in an attempt to handle "buffererror: existing exports of data: object cannot be re-sized."

* Add better logging to help debug disconnect issue

* Allow overriding the idle page

SkillGUI.show_page() and SkillGUI.show_pages() now takes an optional
override_idle parameter. This is used as a hint by the mark-2 skill
and if possible the idle screen will not be shown.

* Improve debugging using Logger

* Raise exception when sending a non-existing gui page

* Restore running state to new connections

When a GUI is connected data and running namespaces are synchronised and
shown.

This refactors the code quite a bit moving the GUI state from the GUIConnection
object to the Enclosure.

The GUIConnection object does the handles the sync in the on_connection_open()
method.

* Add gui.page_interaction message

Currently triggered on page change on the display.

* Handle message when gui changes sessionData

* Check if socket exists on gui before sending data

* Increase port on each failure and retry
2019-01-22 08:45:19 -06:00
Åke Forslund 38701a9790 Remove inheritance from object
Inheriting from object isn't necessary in python3.
2019-01-11 09:24:21 +01:00
Åke fa5c9abd78 GUI Cleanup (#1939)
* Try to improve stability

- Remove sync_active
- Update the way variables are sent to the gui

* Do not show full path for pages

The cli now shows the basename of the current page to make it easier to
determine if the correct page is displayed.

* Make elements in loaded list named tuples

This makes the intent of the code a bit cleaner.
2019-01-09 20:09:21 -06:00
Åke 2e9d764d36 GUI update (#1922)
Several additions to the GUI protocol support

These changes allow switching between pages successfully with the current
mycroft-gui widget:
* Optimized commands to handle the active skill list
* MycroftSkill.gui.show_pages(list, idx) allows multiple-pages to be displayed
  at a time starting with the given index visible.
* Merge SkillGUI.show_page with show_pages
  This limits code duplication and makes things a bit more maintainable.
* Do not reload on changed .qmlc files
* Make EnclosureGeneric derive from Enclosure
* Update show function to match mycroft-gui-app
  - adds internal representation of all loaded skills
  - uses new commands to switch between pages and namespaces
* Add Extra debug output in enclosure
  - Log if starting websocket fails
  - Log the sending of page info in more detail
* Update GUI Debug client in CLI
  - The CLI GUI now handles the new messages for switching pages
  - Handle different data types better by using format instead of string concatenation
* Disable syncing code.
  The sync code at startup outdated and needs to be reworked. Disabling it for now
  to allow better interaction.
* Minor cleanups
  - do not inherit from object
  - use format instead of string concatenations
  - remove duplicated self.loaded
  - correct private member access
* Refactor GUIConnection.show()
   Move the actions into separate methods for better overview of the logic
* Flipped "valid_file" to become "ignored_file"
2018-12-29 21:35:48 -06:00
Åke Forslund f95ff0a2f3 Remove extra except.
except except Exception -> except Exception
2018-12-05 12:36:53 +01:00
Steve Penrod 1e5ff1392f Feedback from code review
Several small changes based on the code review feedback:
* Drop '_' from classes like Enclosure_Mark1
* Adopt Python 3 style for class definitions and don't explicitly list '(object)'
* Slightly better documentation
* Moved MycroftSkill.show_html() to SkillGUI, resulting in code like self.gui.show_page('Weather.qml')
* Renamed SkillGUI.__dict to SkillGUI.__session_data.  This better reflects the
  how values are accessed in the QML.
2018-12-05 01:40:43 -06:00
Åke Forslund 70655bd9b6 Handle missing "enclosure" section in system config
Default to empty dict instead of None if the "enclosure" section is missing
2018-12-05 07:53:35 +01:00
Steve Penrod 07bd6ef7af Code cleanup
Fixing PEP8 and such before merging into 'dev' branch.
2018-12-03 17:33:26 -06:00
Steve Penrod 0ff744529b * Add tracking of the active namespaces for the GUI. Currently the namespace list
is kept in order, but old namespaces/skills are never culled.
* The active namespace list is synced on a GUIConnection level
* QML display requests now are sent as a list instead of a single entry, i.e.
  with "gui_urls" instead of "gui_url".  Currently a skill can only send a single
  QML, however.
* Change CLI GUI client to handle "gui_urls" instead of "gui_url"
2018-11-30 03:04:53 -06:00
Steve Penrod b9fb463727 Fleshing out GUI mechanisms, CLI "GUI"
Further fleshing out of the GUI mechanisms
* Support for data and page from Mycroft -> GUIConnection
* Add a 'reconnecting' event for the messagebus
* Add MycroftSkill.show_url()
* Plumb MycroftSkill.gui into the messagebus
* Implement MycroftSkill.gui dictionary

CLI extensions for the GUI:
* Can now act as a simple GUIConnection
* Minor revamp of messagebus connection, provides kinder handling when
  messagebus isn't found or ready.
* BUGFIX: An empty filter would filter ALL messages
* BUGFIX: Input wider than the screen would cause a crash
* BUGFIX: "filter" or "find" with no param would filer "filter" or find "find"
2018-11-21 02:05:28 -06:00
Steve Penrod dbd3675156 Fixing a few bugs and adding test code to fire up a weather skill visualization upon GUI connection.
Still very much a work in progress.

For understand and testing, here is the sequence:

STEP 1:  GUI announces itself
* Connect to the main Mycroft messagebus
* Send:  "mycroft.gui.connected" with data { "gui_id": XXX } where XXX is a uniq ID (uuid)

STEP 2:  Mycroft creates GUI socket
* Mycroft extracts the gui_id
* Mycroft prepares a socket and announces its availability on the Mycroft messagebus with:
        self.bus.emit(Message("mycroft.gui.port",
                              {"port": self.GUIs[gui_id].port,
                               "gui_id": gui_id}))

STEP 3:  GUI connects
In python, a very minimal test socket handler on the GUI side would look like this

  from websocket import create_connection

  port = 18181 (from the message above)
     ws = create_connection("ws://0.0.0.0:"+port+"/gui")

  ws.send("Hello, World")
  print("Sent")
  print("Receiving...")
  result =  ws.recv()
  print("Received '%s'" % result)
  ws.close()
2018-11-07 11:06:57 -06:00
Steve Penrod aede71db86 First pass at support for the Qt/QML display:
Enclosures
* Create a mechanism to instantiate unique Enclosure classes, depending on the platform found in the SYSTEM mycroft.conf
* Implement a generic Enclosure, which support the new GUI protocol
* Implement a Mark 1 Enclosure (expects the serial connection to an Arduino)
* Implement the start of a Mark II enclosure
* Implement a generic enclosure (no screen)
* Implement the GUI announcement and protocol basics

MycroftSkill
* Implement the basis of the GUI-controlling interfaces.  Namely:
  - MycroftSkill.show_text()
  - MycroftSkill.show_image()
  - MycroftSkill.show_html()
  - MycroftSkill.show_page()
  - MycroftSkill.gui to set values for page displays.

Configuration
* Add "gui_websocket" to the mycroft.config.py
2018-11-06 01:48:16 -06:00
Dominik de0bf7d0fd Fix for broken communication with Arduino 2018-09-03 14:50:51 +02:00
Åke Forslund a86359da7f Fix Åkeisms in the code
Updated renamed variables reference everywhere where they were used
2018-08-30 17:10:17 +02:00
Åke 80a37ec46a Move Mark-1 specific image code from api to mark-1 enclosure (#1767)
* Fix removing of the active user

* Move image drawing routines to enclosure client
2018-08-28 14:50:03 -05:00
Åke 85ae69597b Separate enclosure api from enclosure client (#1760)
This is a step towards abstracting the idea of an Enclosure which ties Mycroft to the hardware that is running Mycroft.

- Move the enclosure API to mycroft.enclosure.api (previously was mycroft.client.enclosure.api)
- Move display_manager out of enclosure client to mycroft.enclosure.display_manager
- Merge EnclosureWeather into EnclosureMouth
- Wrap display manager in a class
2018-08-27 13:44:12 -05:00
Åke 64476eb143 Replace emitter/ws with bus (#1757)
Makes the code a bit more understandable
2018-08-21 20:50:50 -05:00
Åke Forslund a66e23d8ab start processess using python -m
- rename process main.py to __main__.py
- update start-mycroft.sh/stop-mycroft.sh scripts to reflect the change
2018-08-16 15:21:22 +02:00
Steve Penrod 2e873e43bf Change to the supported wait_while_speaking() (#1743)
Code was using the deprecated version from mycroft.util instead of
the mycroft.audio version.
2018-08-15 10:35:50 +02:00
Steve Penrod 17aab53fae Enhance the behavior of the Mark 1 button (#1668)
The Mark 1 button press can now be "consumed" when a skill handles
the Stop command.  When this happens, the button press will not
trigger listening mode.  An additional press would be needed to
trigger listening.

This introduces the "mycroft.stop.handled" messagebus message.  It
carries a data field called "by" which identifies who handled it.
Currently the values are "TTS" for when speaking ends or the name
of a skill which implements Stop and returns True from the call.

Also fixed a potential bug when the flag to clear queued visemes
was left set after a button press.
2018-07-05 20:56:54 +02:00
Åke d63a747b9f
Enforce integer for positions in mouth display (#1588)
In python 3 these would default to floats, which trips up the arduino
2018-05-14 11:48:27 +02:00
Åke Forslund 79d183d59f Bump enclosure version to 1.4.0 2018-05-11 14:26:06 +02:00
Åke Forslund bf404b0bbc Fix python3 issues in serial transmission
Added basic conversion between string and bytes for sending data on the serial line.
2018-05-04 11:42:05 +02:00
Åke Forslund a2993e4ba6 Remove backwards compatibility with python 2.7 2018-04-27 08:51:47 -05:00
Matthew D. Scholefield 5c8cf053a0 Remove code that waits for websocket to open
This is unnecessary now that WebsocketClient does this automatically
2018-03-28 19:19:56 -05:00
Steve Penrod ead38602cb
Add interface to Mark 1 faceplate capabilities (#1424)
* Add interface to Mark 1 faceplace capabilities

This adds API interfaces for two Mark 1 faceplace capabilities to the
mycroft.client.enclosure.EnclosureAPI()

EnclosureAPI.setpixel(index, r,g,b)
- Set individual eye pixels to any color.  The indices go from 0-23 with
  the 0-12 corresponding to the right eye and 11-23 to the left.

EnclosureAPI.fill(percentage)
- Fill the eyes to a percentage, for use in meters or countdowns.  The
  right eye is 0-50%, the left eye also fills if going up to 100%.
2018-02-15 12:29:35 -06:00
Åke Forslund 44387522a6 Move docstring, correct typos 2018-02-15 09:10:39 +01:00
penrods 2af217bed0 Wrote and cleaned up more docstrings
Made docstrings more consistent with the preferred 'Google Style Docstring'
standard:
http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
2018-02-14 17:25:57 -06:00
penrods c68ad44b1c Internal documentation, typos, remove misleading message
* Made MycroftSkill.remove_event() return a bool, preventing unnecessary/misleading message from being posted by MycroftSkill.cancel_scheduled_event()
* More doc and several minor renames around intent processing
* Several minor typo and doc corrections
2018-02-13 02:54:12 -06:00
penrods 26444c9c5f Tweak UI for NTP checking
Withe the NTP checks in place, the sequence of visual and audio queues
was a little clunky.  This refines it slightly for normal use and to
play better with the pairing process.
2018-01-18 14:44:53 -06:00