Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue #1295 "leonardo as keyboard does not wake windows 7 from sleep" #1488

Closed
wants to merge 9 commits into from

Conversation

@nospam2000
Copy link

@nospam2000 nospam2000 commented Jun 29, 2013

This adds a new feature to fix issue #1295 "leonardo as keyboard does not wake windows 7 from sleep"

It makes it possible to wake up the PC when it is in standby mode. Use the following code in the Sketch:
USBDevice.wakeupHost();

Another feature has been added to send the PC to sleep mode:
Keyboard.systemControl(SYSTEM_CONTROL_SLEEP);

See also the discussion in the forum http://forum.arduino.cc/index.php?topic=150157

Tested by me on
Mac OSX (on a MacBook Pro)
Windows 7 (on a MacBook Pro)
Windows 8 (on a Wetab)

@yahesh
Copy link

@yahesh yahesh commented Jul 18, 2013

The Keyboard.pressRaw() and Keyboard.releaseRaw() are redundant to #1391 where I rewrote the whole methods to handle some other issues as well.

@nospam2000
Copy link
Author

@nospam2000 nospam2000 commented Jul 18, 2013

Hi Kenneth,

On 18.07.2013, at 09:49, Kenneth Newwood notifications@github.com wrote:

The Keyboard.pressRaw() and Keyboard.releaseRaw() are redundant to #1391 where I rewrote the whole methods to handle some other issues as well.

Thanks, I haven't seen that and will remove it from my patch.

One issue still remains: the HID report defines only usages and a logical maximum of 0x65, so the usages above 0x65 (e.g. KEYCODE_POWER) can not be used. I changed this also in my patch in HID.cpp:

  • 0x25, 0x65, // LOGICAL_MAXIMUM (101)
  • 0x26, 0xDF, 0x00, // LOGICAL_MAXIMUM (239)
  • 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
  • 0x29, 0xDF, // USAGE_MAXIMUM (Left Control - 1)

Be careful: the logic maximum is a signed integer, therefore it needs a 16-bit integer for the value 239 instead of the 8-bit value.

With Best Regards,

Michael
…ontained in the fix for issue #1391 and the code was redundant
nospam2000 added 2 commits Jul 18, 2013
… as requested in issue #1417.

all parameters have the range of -32768 to 32767 and must be scaled to screen pixels
some examples:
  x=0, y=0 is the middle of the screen
  x=-32768, y=-32768 is the top left corner
  x=32767, y=-32768 is the top right corner
  x=32767, y=32767 is the bottom right corner
  x=-32768, y=32767 is the bottom left corner
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Jan 8, 2014
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Jan 8, 2014
This functionality originated in pull request:
arduino#1488

Jesse can attest to the functionality (tested on OS X 10.8, 10.9, and
Windows 7 but doesn't have the background to verify the implementation
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Jan 8, 2014
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Jan 13, 2014
This functionality originated in pull request:
arduino#1488

Jesse can attest to the functionality (tested on OS X 10.8, 10.9, and
Windows 7 but doesn't have the background to verify the implementation
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Jan 13, 2014
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Jan 13, 2014
as requested in issue arduino#1417.

All parameters have the range of -32768 to 32767 and must be scaled
to screen pixels some examples: x=0, y=0 is the middle of the screen
x=-32768, y=-32768 is the top left corner x=32767, y=-32768 is the
top right corner x=32767, y=32767 is the bottom right corner x=-32768,
y=32767 is the bottom left corner.

Based on commit 7b77d1e from
arduino#1488

Code slightly massaged by Jesse Vincent to remove overzealous #ifdefs
@ffissore ffissore added New and removed New labels Feb 27, 2014
@jBachalo

This comment has been minimized.

Copy link

@jBachalo jBachalo commented on 7b77d1e Jul 30, 2014

No matter what permutation I use using the native map method, can't quite get this to work.

This comment has been minimized.

Copy link
Owner Author

@nospam2000 nospam2000 replied Aug 2, 2014

I was using the following sketch for testing a year ago (I don't have an Arduino Leonardo right now to test it):

include "Platform.h"

// all of the screen_res constants must be !=0 to avoid division by zero
const int16_t screen_res_x = 1920; // must match the screen x resolution
const int16_t screen_res_y = 1280; // must match the screen y resolution
const int16_t screen_res_wheel = 1000; // is scaled from -1000 to 1000

// when you use it on a Mac, set border to 15%

if 1

// for Windows use a border of 0%
const int32_t borderPercent = 0L;

else

// for Max OSX use a border of 15%
// this is for solving the Max OSX border issue
const int32_t borderPercent = 15L;

endif

const int32_t minVal = -32768L; // must match the value of Logical Minimum in the mouse absolute descriptor in HID.cpp
const int32_t maxVal = 32767L; // must match the value of Logical Maximum in the mouse absolute descriptor in HID.cpp
const int32_t borderVal = ((maxVal - minVal + 1) * borderPercent / 200L);
uint32_t g_prevTime;

void setup()
{
Serial.begin(9600);

// initialize control over the mouse:
Mouse.begin();

g_prevTime = millis();
delay(10000);
}

void loop()
{
u32 m = millis();
u32 tDiff = m - g_prevTime;
if(tDiff >= 10) // one step each 10 ms
{
g_prevTime = m;

static float pos;
pos += TWO_PI / 1000.0f;
if(pos > TWO_PI)
  pos = 0.0f;
uint16_t x_screen = ((sin(pos) + 1.0f) / 2.0f) * screen_res_x;
uint16_t y_screen = ((cos(pos) + 1.0f) / 2.0f) * screen_res_y;

moveMouseAbsScreen(x_screen, y_screen, 0);

}
}

// translate screen coordinates to absolute mouse coordinates and move the mouse to that position
void moveMouseAbsScreen(int16_t x_screen, int16_t y_screen, int16_t wheel_screen)
{
int16_t x = map(x_screen, 0, screen_res_x - 1, minVal + borderVal, maxVal - borderVal);
int16_t y = map(y_screen, 0, screen_res_y - 1, minVal + borderVal, maxVal - borderVal);
int16_t wheel = map(wheel_screen, -screen_res_wheel, screen_res_wheel, minVal, maxVal);
Mouse.moveAbs(x, y, wheel);
}

@ArduinoBot
Copy link
Contributor

@ArduinoBot ArduinoBot commented Aug 22, 2014

Can I build this pull request?

obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Dec 1, 2014
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Dec 1, 2014
This functionality originated in pull request:
arduino#1488

Jesse can attest to the functionality (tested on OS X 10.8, 10.9, and
Windows 7 but doesn't have the background to verify the implementation
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Dec 1, 2014
obra added a commit to keyboardio/Arduino-Upstream that referenced this pull request Dec 1, 2014
as requested in issue arduino#1417.

All parameters have the range of -32768 to 32767 and must be scaled
to screen pixels some examples: x=0, y=0 is the middle of the screen
x=-32768, y=-32768 is the top left corner x=32767, y=-32768 is the
top right corner x=32767, y=32767 is the bottom right corner x=-32768,
y=32767 is the bottom left corner.

Based on commit 7b77d1e from
arduino#1488

Code slightly massaged by Jesse Vincent to remove overzealous #ifdefs
@ArduinoBot
Copy link
Contributor

@ArduinoBot ArduinoBot commented Dec 4, 2014

Can one of the admins verify this patch?

@NicoHood
Copy link
Contributor

@NicoHood NicoHood commented Oct 6, 2015

This may be closed now with the new pluggable USB core.

@facchinm
Copy link
Member

@facchinm facchinm commented Oct 7, 2015

Right! 👍

@facchinm facchinm closed this Oct 7, 2015
@ffissore ffissore modified the milestone: Release 1.6.6 Oct 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.