Hello Xenoamor
> I like the idea of being able to choose which HIDs you want but this issue is they need to be set as compiler flags as they get compiled before your program does.
This is not correct.
I studied the Teensy code.
It would be possible to build the HID descriptor dynamically in C code.
In the file usb_dev.c you find a function
void usb_setup(void)
It would be possible to build the descriptor dynamically instead of using hardcoded descriptors.
For example the hardcoded switches NUM_ENDPOINTS and NUM_INTERFACE could be set by C code dynamically depending on the amount of devices to be added.
You define a struct and set the values according to devices to be included.
A new function could be written that adds only the HID devices that the user wants be included.
But to obtain this flexibility you would have to rewrite everything.
____________________________________
> Having a settings.h breaks away from the Arduino flow and make it's complicated for newbies who remain within the environment.
I agree with you.
An additional problem for newbies that must not be forgotten is this:
Windows stores the USB devices in the Registry.
When you change the composition of the HID devices in the descriptor (for example using touchscreen2 instead of touchscreen1) and reconnect the Teensy, Windows will not recognize the changes because they are stored only in the Registry when the device is connected for the first time.
You must uninstall the device before making changes.
Or you must use another ProductID for each configuration.
In my current code on Codeproject I use
0x048A for Keyboard/Mouse/Touchscreen1
0x048B for Serial/Keyboard/Mouse/Touchscreen1
0x048C for Keyboard/Mouse/Touchscreen2
0x048D for Serial/Keyboard/Mouse/Touchscreen2
0x048E for Keyboard/Mouse/Touchscreen3
0x048F for Serial/Keyboard/Mouse/Touchscreen3
This allows to change the composition of the HID descriptor without having to uninstall the driver.
The joystick is disabled, because I don't need it, but it can easily be enabled.
My proposal for the final solution is to use one product ID and put ALL possible devices into it.
For example:
0x0491: Serial + Keyboard + Mouse + Touchscreen1 + Joystick.
0x0492: Serial + Keyboard + Mouse + Touchscreen2 + Joystick.
0x0493: Serial + Keyboard + Mouse + Touchscreen3 + Joystick.
If the user does not need Serial or Joystick it will be present in the descriptor but he simply does not use it and it makes no harm.
The switching between the 3 touchscreens can then either be done in the menu of the Ardiono compiler or in a compiler switch.
_______________________________________
And there is another thing that must not be forgotten:
If a settings file is used, the Teensy installer must not overwrite the user's changes.
This can easily be done by calulating a CRC of the entire file and when it differs, a message box is shown:
"You have modified the file settings.h. Your old file has been stored as settings.bak. Please adjust the new file with your desired settings."
This is also not very user friendly, but the current solution (having a hardcoded menu in the Arduino compiler) is very inflexible.
_______________________________________
It seems the perfect solution does not exist.
At the end Paul has to decide how to make it user friendly and at the same time more flexible for future device additions.
_______________________________________
P.D.
Paul has implemented a workaround for Macintosh that adds a border of 7.5% around the usable area.
if (mac) {
// ugly workaround for Mac's HID coordinate scaling:
//
http://lists.apple.com/archives/usb/2011/Jun/msg00032.html
usb_mouse_offset_x += 161061273ul;
usb_mouse_offset_y += 161061273ul;
usb_mouse_scale_x = (1825361101ul + (width >> 1)) / width;
usb_mouse_scale_y = (1825361101ul + (height >> 1)) / height;
}
I suppose that this workaround can now be removed with the new touchscreen descriptos.
Someone has to test that on a Macintosh.
_______________________________________
P.D.D:
Please note that I completely rewrote the Mouse class.
1.) The code is cleaned up (cryptic stuff like the above lines has been replaced with understandable code)
2.) The Mouse.moveTo() command allows to pass either absolute coordinates in percent values (0.00% ... 100.00%) or in screen coordinates.
3.) The Mouse.move() command allows relative coordinates of 16 bit. (movements of -127 ... +127 in the current mouse class is not enough for many cases)
Elmü