Basically a push button enables a virtual serial device on the Digispark, and my USB hub sends a wake-up command and the kernel wakes up the computer. The wake-up flag on my USB hub is set using udev.
More details in project log.
A wired remote control device that can wake up a computer so the computer can wake from sleep by the time you walk to it.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
Basically a push button enables a virtual serial device on the Digispark, and my USB hub sends a wake-up command and the kernel wakes up the computer. The wake-up flag on my USB hub is set using udev.
More details in project log.
50-wake-on-device.rulesUdev rules to make sure the computer wake for Linux (maybe works on Mac OS?) You will need to find the id of the usb controller as discussed in the guide and edit that in here.rules - 178.00 bytes - 07/06/2020 at 01:16 |
|
|
app.inoFinal Digispark codex-arduino - 516.00 bytes - 07/06/2020 at 01:10 |
|
Not much here. I just soldered a cable connecting to a push button between 5v and pin 5 and a pull-down resistor to pin 5.
USB setup:
Disclaimer:
What I tried:
I thought it would be as simple as asking the Digispark keyboard library to type something when the button press was detected.
That didn't end up working out because the Digispark keyboard library doesn't have ( as I discovered later after a lot of wasted time and effort) a wake-up flag which means the Linux kernel never considers it to be a device that can wake up the computer.
After that, I tried the DigiCDC library, which can emulate (from what I understand) more low-level USB functionality. I realized that I could just start a serial connection with the SerialUSB.begin() command, and it would (from what I understand) basically act as if a device was just plugged in. This seemed perfect because a device being plugged in seemed exactly like the sort of thing that the kernel would consider waking up the computer for.
After figuring out what wake-up flags were (the capibality of a device to wake up a computer or not) I realized that my USB hub that enabled and it issued a wake-up request when a USB device was plugged in. Perfect! So any time a button was pressed, I issued these commands
SerialUSB.begin();
SerialUSB.delay(6000);
SerialUSB.end();
Looking at dmesg with `dmesg -w`, it seemed like the device was being unplugged each time this was happening. After that,
I sent
echo enabled > /sys/bus/usb/devices/1-3/power/wakeup
I had previously figured out that 1-3 was my usb hub by looking at lsusb and seeing
Bus 004 Device 004: ID 05e3:0749 Genesys Logic, Inc.
Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
Bus 004 Device 002: ID 05e3:0626 Genesys Logic, Inc. USB3.1 Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 007: ID 8087:0a2b Intel Corp.
Bus 001 Device 006: ID 06cb:0081 Synaptics, Inc.
Bus 001 Device 004: ID 04f2:b61e Chicony Electronics Co., Ltd Integrated Camera
Bus 001 Device 032: ID 046d:c534 Logitech, Inc. Unifying Receiver
Bus 001 Device 038: ID 16d0:087e MCS USB2.1 Hub
Bus 001 Device 030: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I figured that MCS USB was my Digispark because that showed up every time the Digispark's SerialUSB was activated. Also, the Logitech reciever was the only other thing plugged into that particular hub so it made sense that they would be devices 30 and 3[1-9]. Then, I had to investigate a bit to find out how to relate the numbers in /sys to these ID's but it worked out by `grep . /sys/bus/usb/devices/*/idProduct`.
I set up a systemd action to do this on each boot,
And it works!!!!!!
.
.
.
Not so easily, I realized after a few hours and my USB hub being unplugged once for unrelated reasons, each time the USB hub is unplugged, these settings reset themselves. Thankfully though, on my adventures across the internet search for what would end up being the wake-up flag, I had learned about udev. Basically, udev is a utility that does stuff when any peripheral is plugged in (read the Arch wiki page for more info). So, I set up a udev command that whenever the usb device '05e3:0610' is plugged in,
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="0610",
udev sets its wake-up attribute to enabled.
ATTR{power/wakeup}="enabled"
And it works!!!! (As of writing this I haven't rebooted my computer after making this change so I don't know if it will persist yet. In principle this should be pretty robust.)
This will explain the why of things. To see just the final product look at the build instructions.
Digispark:
This was an obvious choice since I had it lying around and am mostly familliar with it's USB functionality (or at least I thought so before I started this project). It is small in size and has a few IO pins in case I need to add more functionality in the future.
Ethernet:
Used it in case I need to add more buttons in the future and because I had some partly broken ethernet cable lying around. Could be replaced with any 2 wire cable.
Pushbutton:
No rationale just a generic push button.
Set up the Digispark environment with instructions from http://digistump.com/wiki/digispark/tutorials/connecting
Upload the code in the attached ino file to the Digispark.
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M ID 1d6b:0002 Linux Foundation 2.0 root hub |__ Port 3: Dev 40, If 0, Class=Hub, Driver=hub/4p, 480M ID 05e3:0610 Genesys Logic, Inc. 4-port hub |__ Port 4: Dev 42, If 1, Class=Human Interface Device, Driver=usbhid, 12M ID 046d:c534 Logitech, Inc. Unifying Receiver |__ Port 4: Dev 42, If 0, Class=Human Interface Device, Driver=usbhid, 12M ID 046d:c534 Logitech, Inc. Unifying Receiver
I figured that since the Logitech reciever was plugged into the same hub I was going to use for my Digispark, 'ID 05e3:0610 Genesys Logic, Inc. 4-port hub' is probably the target USB hub. As far as I know if the target USB hub is an external USB to USB hub, it probably won't be a top-level (or root) device. The ID 05e3:0610 is the main takeaway from this step.
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More