project-owner / Peppy

Peppy Player Repository
GNU General Public License v3.0
72 stars 14 forks source link

Power off #42

Closed AlexPtushkin closed 1 year ago

AlexPtushkin commented 1 year ago

Good afternoon, I assembled a shutdown circuit and it worked with the kandinsky-headless.img.xz variant. When I connected the display, the circuit does not work. On gpio 24 the state changes to low, but pi4 does not turn off. There is no information in the log about reading gpio24.

/boot/config.txt

hdmi_mode=1 hdmi_mode=87 hdmi_cvt 480 320 60 6 0 0 0 hdmi_drive=2

dtoverlay=gpio-poweroff,active_low,gpiopin=4

/home/pi/Peppy/config.txt

[gpio] use.player.buttons = False button.type = GPIO use.menu.buttons = True use.rotary.encoders = False rotary.encoder.volume.up = 16 rotary.encoder.volume.down = 26 rotary.encoder.volume.mute = 13 rotary.encoder.navigation.left = 6 rotary.encoder.navigation.right = 12 rotary.encoder.navigation.select = 5 rotary.encoder.jitter.filter = 1 button.left = button.right = button.up = button.down = button.select = button.volume.up = button.volume.down = button.mute = button.play.pause = button.next = button.previous = button.home = button.poweroff = 22 button.menu.1 = button.menu.2 = button.menu.3 =

GPIO24 uses a LCD display. I took gpio 22, but the program needs to be adjusted to 5v. Shutdown doesn't work Shutting down from the browser works.

Have a good day

project-owner commented 1 year ago

Hi, what do you mean - but the program needs to be adjusted to 5v? Are you sure that GPIO22 is not used by display? Try to use either GPIO20 or GPIO26. You can also add logging - logging.debug("some message") to the following functions: https://github.com/project-owner/Peppy/blob/c4b55544bbaca5930f74c2d609bc285bc47d7629/event/dispatcher.py#L374 https://github.com/project-owner/Peppy/blob/c4b55544bbaca5930f74c2d609bc285bc47d7629/peppy.py#L2874

Best regards

AlexPtushkin commented 1 year ago

I'm 59 years old and I'm still learning. GPIO22 is not used by the display photo_2023-09-26_23-31-20 I realized that I need to add the line: def handle_poweroff(self, event): logging.debug("handle_poweroff")

def shutdown(self, event=None): logging.debug("shutdown")

Peppy stopped working :(

I'm downloading a new version. Will I feel better?

project-owner commented 1 year ago

My bad, I didn't explain you that Python is sensitive to spaces/tabs. It doesn't accept tabs only spaces. And all lines should be aligned with previous lines. It should be something like this:

    def shutdown(self, event=None):
        """ System shutdown handler

        :param event: the event
        """
        logging.debug("in shutdown")
        self.pre_shutdown()

        if self.config[LINUX_PLATFORM]:
            if not self.config[USAGE][USE_DESKTOP]:
                logging.debug("calling poweroff")
                subprocess.call("sudo poweroff", shell=True)
            else:
                os._exit(0)
        else:
            self.shutdown_windows()
project-owner commented 1 year ago

Also please make sure that you don't confuse connector pin numbers and GPIO numbers, they are different. For example GPIO22 is connector pin 15.

dadr commented 1 year ago

Would it be better to connect a Normally Open, momentary contact switch (i.e. push button) between pins 5 & 6, which are GPIO 3 and Ground? I think that this arrangement allows the push button to both halt and wake the Pi from halt.

See explanation here: https://elinux.org/RPI_safe_mode#Wake_from_Halt.5B1.5D

project-owner commented 1 year ago

It's saying at the top:

EDIT: This feature is removed from default firmware as of 18th March 2014.
dadr commented 1 year ago

I'm not sure whether that means that the safe mode is no longer available when you leave the pins shorted, or something else. I am running Peppy Klimt release with a HiFiBerry DAC+ overlay. On this system, shorting pins 5-6 does not shutdown; however, if I shutdown using the power button on the screen, then shorting these two pins definitely starts the machine again.

project-owner commented 1 year ago

OK, the power management system described here: https://github.com/project-owner/Peppy.doc/wiki/Power-OnOff should do both shudown and start. Well, if it's soldered correctly, configured properly and there is no pin conflicts :)

AlexPtushkin commented 1 year ago

Hello! Based on Your recommendation, I took GPIO26 (37 PIN). Made changes to the file:

def shutdown(self, event=None): """ System shutdown handler

    :param event: the event
    """
    logging.debug("in shutdown")
    self.pre_shutdown()

    if self.config[LINUX_PLATFORM]:
        if not self.config[USAGE][USE_DESKTOP]:
            logging.debug("calling poweroff")
            subprocess.call("sudo poweroff", shell=True)
        else:
            os._exit(0)
    else:
        self.shutdown_windows()

On GPIO26 the level changes from 5 -> 0, the power does not turn off. There is nothing in the logs. Such implication that it is not analyzed by GPIO26 config.txt

project-owner commented 1 year ago

Could you use this function with additional logging? https://github.com/project-owner/Peppy/blob/c4b55544bbaca5930f74c2d609bc285bc47d7629/event/dispatcher.py#L374

    def handle_poweroff(self, event):
        """ Handle poweroff hardware button

        :param event: event object
        """
        if event.type == USER_EVENT_TYPE and hasattr(event, "action") and event.action == pygame.KEYUP:
            logging.debug("user event")
            k = getattr(event, "keyboard_key", None)
            if k and k == kbd_keys[KEY_END]:
                logging.debug("key end")
                if self.poweroff_flag == 1:
                    logging.debug("shutdown")
                    self.shutdown(event)
                else:
                    logging.debug("flag = 1")
                    self.poweroff_flag = 1
            else:
                logging.debug("flag = 0")
                self.poweroff_flag = 0

        logging.debug("in handle")

        if event.type == pygame.MOUSEBUTTONUP:
            logging.debug("flag = 0")
            self.poweroff_flag = 0
AlexPtushkin commented 1 year ago

I made your changes, rebooted, the log is empty. We need to look at what it reads from GPIO26 Screenshot_2

project-owner commented 1 year ago

Did you push the button?

AlexPtushkin commented 1 year ago

Yes, I pressed it. At GPIO26 the level changes

AlexPtushkin commented 1 year ago

Everything worked. Screenshot_3 It's not mentioned in the description Best regards