omriharel / deej

Set app volumes with real sliders! deej is an Arduino & Go project to let you build your own hardware mixer for Windows and Linux

Home Page:https://deej.rocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Having deej open instantly wakes PC from sleep.

askolds11 opened this issue · comments

Hello!
I have an issue where having deej open instantly wakes my PC from sleep, having the Arduino plugged in doesn't matter.

From what I've read from previous threads(#17 and #21) this is what you might need:
Power options
image
Time it takes to wake after sleeping - about 2 seconds after everything turns off.
Chipset - not sure what this means, but the motherboard is a ASRock Z97 Anniversary, the wake is from

   Instance Path: PCI\VEN_8086&DEV_8CB1&SUBSYS_8CB11849&REV_00\3&11583659&0&A0
    Friendly Name: Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)
    Description: USB xHCI Compliant Host Controller
    Manufacturer: Generic USB xHCI Host Controller

And the deej is plugged into a USB 2 port.

Everything's running and an Arduino Leonardo clone, and I have 6 potentiometers, although I'm not sure that matters, as having the program closed doesn't wake the PC.

Hi there @askolds11, thanks for writing.

I have heard some (relatively scarce) reports of this before, but I was never able to replicate the issue in a way that lets me dive into it more closely.

Would you be able to share a screenshot of this same panel with the rest of the settings expanded, such as "USB settings" (but not only that)? I'm sure there's a less awkward way to share this information, but I don't know what it is yet :)

Also: you mentioned that "having the Arduino plugged in doesn't matter" - can you expand on that point? Do you mean that even if you unplug your deej hardware after the deej executable has connected and continued to run in the background, that still prevents your PC from sleeping until you close deej?

Thanks!

About the Arduino not being plugged in - sorry, I mixed that up, since deej doesn't launch if the Arduino isn't plugged in, what I meant is that having the Arduino plugged in, but deej not open doesn't wake the pc.
Forgot to mention, I'm on Windows 11.

Here are all the power options:
image
image
image
image

I just changed the COM port in config to a different one, that isn't an Arduino (COM1, it's always there, I don't know what is is) and the computer sleeps as normal with deej open.

Hey @askolds11, thanks for the update.

Would you be able to try with the "USB selective suspend setting" disabled?

As a side note: COM1 is a reserved port for the system, and I don't think deej does any meaningful interaction with it so that's likely not a great indicator for us. If you had a different board that you could try (a non-Leonardo, for example) that would probably provide us with a better distinction point - at least across the hardware side of things.

Changing the USB selective suspend setting did nothing.
However, I tried an Arduino Uno and that seemed to fix the sleep problem. I uploaded the sketch and verified deej was getting info to it by jumping an analog pin to GND and checking it changed the volume.
Further testing showed that an Arduino Pro Micro from AliExpress (I think it's a smaller Leonardo, based on ATmega32U4) does have the sleep issue, also verified that it's working by jumping analog to ground.
An Arduino Nano from AliExpress (old bootloader) also didn't have the sleep problem, also checked that it was working.
I've got an ATTINY85, but I haven't worked with it yet, so I'm not sure if I need a programmer for it or not and also haven't looked up the analog pins for it, so I can't test with it.

Hey @askolds11,

It seems based on what you're reporting that this issue is heavily hardware-dependent. This likely means that a difference in driver implementations for the various boards is responsible for the wake behavior you're experiencing.

Unfortunately, I'm not sure that this is something we're able to solve on the client side. You may want to experiment with doing some de-noising on the Arduino side and only sending a new line when a slider is moved - deej's client side would be able to handle that gracefully, assuming that the serial connection remains alive.

Please let me know if you have any questions!

Thank you for the answer!

I added code to check if the potentiometers have changed and if they have only then send data, and also divided and multiplied the analogRead by 2 to de-noise I guess, and that seems to have worked, as the computer goes to sleep normally and if I move a potentiometer it wakes up the PC.

Unsure how long the connection stays alive, if it has a limit, I only tried going to sleep for about 2 minutes and then waking it up.

EDIT: Seems like 2 is too little, but if I just reduce the resolution enough, I guess it'll be fine.
EDIT 2: Dividing and multiplying seems to work fine, just had to add an additional check if the value is 1020, then set it to 1023, so, in my case, the volume could be set to 0.

Another approach for de-noising on the arduino side without losing resolution would be taking a rolling average of the last N readings (say 10). You can also de-noise on the hardware itself by adding in some capacitors, but this may be overkill for a project like deej.

@askolds11 - did you get to test this further? Does the hardware-side solution work for your needs?

Yes it works, I haven't tried the rolling average, which would be a better way, but the dividing the readings by 10 and multiplying them again works, although I imagine it could be an issue if the reading is 119 or 120 and it fluctuates, as that would be a change and it would send data, but that's a rare enough case currently. The volume moves up/down by 4, but I think the default moved it by 3, it isn't much of an issue to me.

I'll try to make the rolling average sometime, but I currently don't have the time.

Okay, I'll close the issue. Feel free to add anything you want below for anyone else reading this in the future (if you do make further changes). Thanks!

So the division by 10 and multiplication by 10 wasn't the ideal solution, I tried the rolling average, but it didn't work as well as the previous solution and also added a delay.

Currently I seem to have fully solved the issue by sending the previously mentioned sending only when changed, but I also added a check to make sure that the values have changed by at least 3 before changing.

For anyone wondering about the code:
The checking if changed part:
Declare a variable oldValues at the start: String oldValues;
In sendSliderValues() add an if to check if the values have changed and also assign the current values (builtString) to oldValues:
if(oldValues != builtString) Serial.println(builtString); oldValues = builtString;

The change by at least 3 part(could be done without an extra array, but it works fine for me):
Declare a new array at the start: int oldAnalogSliderValues[NUM_SLIDERS];
Assign it values at setup: oldAnalogSliderValues[i] = analogSliderValues[i] = analogRead(analogInputs[i]);
Check if the change is less or equal to 2, and if it is, change the values to the old ones: if(abs(oldAnalogSliderValues[i] - analogSliderValues[i]) <= 2) analogSliderValues[i] = oldAnalogSliderValues[i];
Assign the new values to the old values after the check: oldAnalogSliderValues[i] = analogSliderValues[i];