OpenNeptune3D / display_connector

An integral part of the OpenNeptune project, this is the missing link between open source Klipper/Moonraker services & TJC/Nextion touch-screen displays. Specifically tailored to support the Neptune 4 Series 3D Printers.
GNU General Public License v3.0
23 stars 8 forks source link

Loading page after initiating host Shutdown / Reboot from Display #12

Closed halfmanbear closed 6 months ago

halfmanbear commented 8 months ago

The Elegoo loading spiral page after initiating host shutdown/reboot would be nice, just so the user is aware they have pressed it.

halfmanbear commented 8 months ago

noticed the code is present for some feedback after action in show_shutdown_screens although this doesn't appear to work for me

halfmanbear commented 8 months ago

putting self.display.show_shutdown_screens() within a self._loop.create_task allows it to run (probably because it's a async method?).

           elif action == "shutdown_host":
            logger.info("Shutting down Host")
            self._loop.create_task(self.display.show_shutdown_screens())  
            self._loop.create_task(self._send_moonraker_request("machine.shutdown"))

It also appears using delay confuses the Nextion connector. It assumes the connection is lost as the display is storing and delaying the remaining serial instructions for 10s without responding.

    async def show_shutdown_screens(self):
        await self.write("cls 44637")
        await self.write("xstr 8,220,256,20,1,54151,44637,1,1,1,\"Please wait while your printer\"")
        await self.write("xstr 24,240,224,20,1,54151,44637,1,1,1,\"shuts down.\"")
        await self.write("delay=10000")
        await self.write("cls BLACK")
        await self.write("xstr 24,220,224,20,1,54150,0,1,1,1,\"It's now safe to turn off\"")
        await self.write("xstr 24,240,224,20,1,54150,0,1,1,1,\"your printer.\"")

It might be required to change bkcmd=3 to bkcmd=0 to allow for the lack of response or find a way of preventing it trying reconnect?

 2024-03-31 11:42:05,936 - DEBUG - Navigating to shutdown_dialog
138 133
(24, 104, 248, 154)
2024-03-31 11:42:06,735 - INFO - Shutting down Host
Command "delay=10000" timeout.
Connection lost
Command "bkcmd=3" timeout.
Command "get sleep" timeout.
Connection lost
Command "bkcmd=3" timeout.
Command "get sleep" timeout.
Connection lost
2024-03-31 11:42:16,797 - INFO - Reconnected to Display
Task exception was never retrieved
future: <Task finished name='Task-226' coro=<DisplayController.display_event_handler() done, defined at /home/mks/display_connector/display.py:732> exception=AttributeError("'DisplayController' object has no attribute 'initialize_display'")>
Traceback (most recent call last):
  File "/home/mks/display_connector/display.py", line 745, in display_event_handler
    self.initialize_display()
    ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DisplayController' object has no attribute 'initialize_display'
phillipthelen commented 7 months ago

The idea for this code was the following:

  1. connector sends all commands to the display including the delay (This is the first issue you noted. with it being an async method, the script doesn't wait until all commands are actually sent before it continues
  2. script issues shutdown command to host
  3. display shows the "it's safe to turn off power" message after the delay

So the delay is there to communicate to the user that the host system should now be shut down and it's safe to cut power. The connector shouldn't attempt to reconnect because right after sending the commands it should be killed by the host shutting down. At least that is the idea :D I will take a look into why that is not correctly working.