Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an enclosure service for Picroft #122

Open
wants to merge 3 commits into
base: buster
Choose a base branch
from

Conversation

penrods
Copy link
Contributor

@penrods penrods commented Nov 13, 2019

Now a my_enclosure.py gets installed as part of the setup. Specific supported hardware
includes a custom enclosure (e..g AIY, ReSpeaker Mic Array and Matrix) or a generic
enclosure is installed with support for specific GPIOs. All support at least a generic button
and some LED indicators.

The code is in /opt/mycroft/enclosure/my_enclosure.py and auto-launches from auto_run.sh as
a root process. A soft link is created from the home directory, as ~/my_enclosure.py. Changes

The basic hierarchy is:
EnclosureGeneric
Picroft_Enclosure
AIY_Enclosure
Generic_Enclosure
Matrix_Enclosure
ReSpeaker_Enclosure

The Picroft_Enclosure contains most of the heavy lifting, with just a little
in the subclasses to tie to the special cases.

The GPIO_Button and GPIO_LED also implement must of the Raspberry Pi behavior.
The Button generates actions for Press, Release, Hold and Double Click. The
GPIO_LED is a very simple LED which can turn on, off or flash automatically.

Also fixes the typo mentioned in Issue #125
to the enclosure will also be automatically reloaded.

Additionally, logging in to TTY sessions automatically enters the venv now.

The code in ~/enclosure/PicroftEnclosure auto-launches from auto_run.sh and
also automatically reloads when the code is changed on disk.  Currently it
handles the shutdown and reboot messages.

Also auto-enter the mycroft environment before jumping to the command line on
the additional TTY sessions.
Revamped the layout of enclosures on the Picroft image
* Code now lives under /opt/mycroft/enclosure instead of ~/enclosure
* Setup copies appropriate template to /opt/mycroft/enclosure/my_enclosure.py
* A soft link is created to my_enclosure.py in the home directory
* Enclosure is run as root
* Added basic LED indicator or the Pixel Ring for a Seeed ReSpeaker Mic Array
* Add support for a simple button

TODO: Enhance Matrix pixel ring support
This revamps how code is structured for enclosures.  Rather than repeating
code in several places, it now uses objects and inheritance.  The original
attempted to keep all the logic in a single file, but the GPIO objects
already added the need for a user to understand object oriented, so this
step seems reasonable.

The basics heirarchy is:
    Enclosure
        Picroft_Enclosure
            AIY_Enclosure
            Generic_Enclosure
            Matrix_Enclosure
            ReSpeaker_Enclosure

The Picroft_Enclosure contains most of the heavy lifting, with just a little
in the subclasses to tie to the special cases.

The GPIO_Button and GPIO_LED also implement must of the Raspberry Pi behavior.
The Button generates actions for Press, Release, Hold and Double Click.  The
GPIO_LED is a very simple LED which can turn on, off or flash automatically.

Also fixes the typo mentioned in Issue #125
@tuetschek
Copy link

Thanks for this! I just tested it on my RPi4 + Respeaker 2-mic HAT and it works fine... just needed two tiny fixes. I guess the easiest option is to just paste them here:

diff --git a/opt/mycroft/enclosure/lib/gpio_button.py b/opt/mycroft/enclosure/lib/gpio_button.py
index 17764b6..2db0c15 100644
--- a/opt/mycroft/enclosure/lib/gpio_button.py
+++ b/opt/mycroft/enclosure/lib/gpio_button.py
@@ -42,7 +42,7 @@ class GPIO_Button:

         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.button_bcm, GPIO.IN, pull_up_down=GPIO.PUD_UP)
-        GPIO.add_event_detect(23, GPIO.BOTH, self._on_gpio_button)
+        GPIO.add_event_detect(self.button_bcm, GPIO.BOTH, self._on_gpio_button)
         self.__timer = None
         self.__timer2 = None
         self.__last_press = 0
diff --git a/opt/mycroft/enclosure/lib/picroft_enclosure.py b/opt/mycroft/enclosure/lib/picroft_enclosure.py
index 7d214bb..ddb240a 100644
--- a/opt/mycroft/enclosure/lib/picroft_enclosure.py
+++ b/opt/mycroft/enclosure/lib/picroft_enclosure.py
@@ -63,7 +63,7 @@ class Picroft_Enclosure(EnclosureGeneric):
         self.bus.on("mycroft.skill.handler.complete", self.indicate_thinking_done)

         # Visual indication that system is booting
-        self.bus.on("mycroft.skills.initialized", self.on_ready)
+        self.bus.on("mycroft.skills.initialized", self.indicate_booting)

         # Setup to support a button on a GPIO -- default is GPIO23
         if button_gpio_bcm:

j1nx added a commit to j1nx/MycroftOS-Enclosure that referenced this pull request Apr 2, 2020
This to be inline with the start of PR of Steve Penrods
MycroftAI/enclosure-picroft#122
@@ -380,7 +396,7 @@ function setup_wizard() {

# Flash latest Seeed firmware
echo "Downloading and flashing latest firmware from Seeed..."
sudo /home/pi/mycroft-core/.venv/bin/pip install pyusb click
sudo /home/pi/mycroft-core/.venv/bin/pip3 install pyusb click

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that on systems with python2 AND python3, this might be needed .. BUT, afaict, since we should be within the picroft venv ... shouldn't technically be required; and anyway pip and pip3 are the same on picroft venv systems

(.venv) pi@picroft:~ $ diff /home/pi/mycroft-core/.venv/bin/pip /home/pi/mycroft-core/.venv/bin/pip3ip3
(.venv) pi@picroft:~ $ 

(.venv) pi@picroft:~ $ which pip
/home/pi/mycroft-core/.venv/bin/pip

(.venv) pi@picroft:~ $ ll /home/pi/mycroft-core/.venv/bin/ | grep pip
-rwxr-xr-x 1 pi pi   243 Jun 20 02:19 pip
-rwxr-xr-x 1 pi pi   243 Jun 20 02:19 pip3
-rwxr-xr-x 1 pi pi   243 Jun 20 02:19 pip3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants