I don’t know if I can explain it properly in fewer words.
A power button press (more than 3 seconds but shorter than 5 seconds) or an power off signal via the remote control do the same:
- initiate a timed shutdown immediately. This will happens without any software at operating system level or KODI. It’s programmed in the MCU firmware. This process gives a limit of 10 seconds until the power to the RPi4 will be cut and the LED goes off (no power )
- this happens ever, independing if the KODI addon or other service exists
Parallel to that started timeout of 10 seconds, the MCU usually signals to the RPi4 via GPIO pin, that a hard shutdown is initiated. This is the signal which the KODI addon or an alternative service tries to listen for and inform KODI to shutdown properly. Now the time ticks and KODI must stop all running threads before the 10 seconds are timed out. Please note the operating system must also do some things during shut down like unmounting local storages or network file systems.
This is the reason to use v1.1.4/1.1.5 with gpiod, to ensure KODI have a chance to do that in time.
One of the technical problems is, the MCU should normally not cut the power after 10 seconds. Instead it should wait until the pin of UART is going down and extend the timeout until then. Because I doesn’t have an oscilloscope I can’t 100 percent be sure, that the pin not accidentally flaps and irritates the MCU. At software site it looks like all things are right, but firmware or hardware bug at RPi4 could also be a cause.
It seems that sometimes the MCU does not recognize that the UART pin has dropped and then the LED stays on because the RPi4 has not been disconnected from power. Additionally, you can get the MCU into trouble if you use the i2cdump command or another process sends a specific/critical command to the MCU via I2C.
If you skip the hardware button option (means especially the power button of the remote control as well) and navigate via cursor to the power menu of KODI, using the command line or something else to inform LE about a shut down, another workflow is starting.
This works only if the addon is working right or an alternative services do the right things. The MCU must be informed that it should cut off the power, because it doesn’t know about that operating system event. The addon installs a shutdown script which is in use as long the KODI process is running. If you stopped KODI via systemctl before it’s possible that it skipped - but this is not the normal use case of LE I think.
The shutdown script informs the MCU via I2C to cut the power after the UART pin is falling down. Like mentioned above the 10 second limit starts just at the moment as the shutdown script is called and MCU starts to observe the UART pin. This is later in the shutdown process and therefore more controllable by software than the hardware button events.
Possible technical issues: The MCU isn’t available via I2C at this time or the UART pin is accidentally floating afterwards. Then the power cut will not work properly and the LED may light up.
At my installation I could reproduce in the past, that the MCU isn’t available during shutdown if the MCU was going stuck because of i2cdump usage or if the shutdown was already initiated via the hardware events. But since version 0.0.12a it shouldn’t be a generic issue of the addon themself anymore. Recently I could identifiy that the default available Python modules for the GPIO control in LE12+ was the root cause for an additional race condition. If the addon can not switch to the gpiod module, KODI will take 30 seconds to kill the python thread of the addon (because of a bug in the used default modules), so the via hardware button events intiated 10 second limit in the MCU is exceeded every time.
Regarding the IR signal:
It’s received by 2 components at the same time. The MCU is connected in parallel to the IR receiver to be able to detect everytime the “power button” sequence of the remote control. The second component is gpio-ir driver at pin 23 of the RPi4 if enabled in config.txt.
If the “power sequence” is catched by the observing addon thread fast enough, than you shouldn’t have the opportunity to navigate in KODI afterwards. Usually you should get only a freezed screen with a wheel/or not or grayed out power off dialog. If that fail/is disturbed because of any kind of possible issue (the addon isn’t installed, maybe a self configured lirc settings, the addon thread crashed or was killed in background) you can navigate further until the power cut is executed after the round about 10 second limit.