This is my first time modifying a Arduino library.
I am trying to add a simple function to the Arduino Keyboard library, but get a compile error.
I am probably doing it wrong. My attempt is listed below.
I added function declaration for "getModifiers()"
Arduino\hardware\arduino\cores\arduino\USBAPI.h
class Keyboard_ : public Print
{
private:
KeyReport _keyReport;
void sendReport(KeyReport* keys);
public:
Keyboard_(void);
void begin(void);
void end(void);
virtual size_t write(uint8_t k);
virtual size_t press(uint8_t k);
virtual size_t release(uint8_t k);
virtual void releaseAll(void);
uint8_t getModifiers(); //I added this line
};
extern Keyboard_ Keyboard;
I added function definition for "getModifiers()"
Arduino\hardware\arduino\avr\cores\arduino\HID.cpp
uint8_t Keyboard_::getModifiers()
{
return _keyReport.modifiers;
}
This is the test sketch
void setup()
{
}
void loop()
{
Keyboard.write("\nKEY_LEFT_SHIFT=");
Keyboard.write(KEY_LEFT_SHIFT);
Keyboard.write(" not shifted modifiers=");
Keyboard.write(Keyboard.getModifiers());
Keyboard.press(MODIFIER_LEFT_SHIFT);
Keyboard.write(" shifted modifiers=");
Keyboard.write(Keyboard.getModifiers());
while(true) { }
}
I restarted Arduino IDE and get this compile error:
C:\Program Files (x86)\arduino-1.6.4/hardware/tools/avrteensy/bin/avr-g++ -c -Os -g -Wall -ffunction-sections -fdata-sections -MMD -fno-exceptions -felide-constructors -std=c++0x -mmcu=atmega32u4 -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DUSB_HID -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\arduino-1.6.4\hardware\teensy\avr\cores\teensy C:\Users\wolf\AppData\Local\Temp\build1030473635684301006.tmp\Keyboard_pressShifted.cpp -o C:\Users\wolf\AppData\Local\Temp\build1030473635684301006.tmp\Keyboard_pressShifted.cpp.o
Keyboard_pressShifted.ino: In function 'void loop()':
Keyboard_pressShifted.ino:8:34: warning: large integer implicitly truncated to unsigned type [-Woverflow]
Keyboard_pressShifted.ino:11:29: error: 'class usb_keyboard_class' has no member named 'getModifiers'
Keyboard_pressShifted.ino:13:20: error: 'MODIFIER_LEFT_SHIFT' was not declared in this scope
Keyboard_pressShifted.ino:16:29: error: 'class usb_keyboard_class' has no member named 'getModifiers'
'class usb_keyboard_class' has no member named 'getModifiers'
I am running Arduino 1.6.4 and Teensyduino 1.23 for Teensy 2.0.
I read the "How to write libraries for the Arduino?" on Arduino Playground - Library Tutorial
Suggestions are appreciated.