Detect sleeping computer

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
efc
 
Posts: 16
Joined: Sat Nov 20, 2021 11:00 am

Detect sleeping computer

Post by efc »

I have a RP Pico connected to my Mac using USB and I am able to use CircuitPython's USB HID to send keystrokes to the Mac. However, in my case I want to _avoid_ waking up the computer if it is asleep. Sending a keystroke to the computer wakes it up, which I do not want to do.

Is there any way to detect whether the computer is asleep via the USB connection so that I could avoid sending keystrokes while the computer is asleep?

Alternatively, is there a way to configure USB HID so that the keyboard does not wake the computer from sleep?

User avatar
sj_remington
 
Posts: 1021
Joined: Mon Jul 27, 2020 4:51 pm

Re: Detect sleeping computer

Post by sj_remington »

If the Mac displays something like the "breathing" power LED indicator while in sleep mode, that could be detected by an optical sensor.

User avatar
danhalbert
 
Posts: 4688
Joined: Tue Aug 08, 2017 12:37 pm

Re: Detect sleeping computer

Post by danhalbert »

supervisor.runtime.usb_available should be false when usb is suspended, which is what happens when the computer sleeps. See if that works for you.

https://docs.circuitpython.org/en/lates ... _connected

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”