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

problems with TrinketKeyboard.print & TrinketKidCombo.print #12

Open
ElectricRCAircraftGuy opened this issue Dec 25, 2015 · 4 comments
Open

Comments

@ElectricRCAircraftGuy
Copy link

In the code below, notice these lines:

  //test prints
  uint8_t buttonLEDstate = TrinketKeyboard.getLEDstate();
  TrinketKeyboard.print(buttonLEDstate,BIN); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.print("test"); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.println();

The buttonLEDstate only prints the first time. The subsequent 2 attempts at printing it do not work. There is an issue with the print and println commands. It is present with the TrinketHidCombo library too. Here is the output:

0, 
test, 

0, 
test, 

0, 
test, 

0, 
test, 

0, 
test, 

Here's the full code sample:

/*
readCapsLockState
-get the digispark to press the Windows shortcut key
Gabriel Staples
http://www.electricrcaircraftguy.com/
Written: 24 Dec. 2015 
Updated: 25 Dec. 2015
*/

//Includes
//For Trinket Keyboard & Mouse Combo functionality
//-Trinket Keyboard Help: https://learn.adafruit.com/trinket-usb-keyboard?view=all
//-NB: The poll function must be called at least once every 10 ms, or you must command a keystroke.
//--Otherwise, the computer may think that the device has stopped working, and give errors. Hence, DO NOT USE DELAY()!
//-Note: "HID" or "Hid" stands for "Human Interface Device." It is a well-defined USB standard. See here: https://en.wikipedia.org/wiki/Human_interface_device
#include <cmdline_defs.h>
#include <TrinketKeyboard.h>
#include <TrinketKeyboardC.h>
#include <usbconfig.h>

//#defines
#define KEY_CAPS_LOCK 0x39
#define TrinketHidReleaseKeys() TrinketKeyboard.pressKey(0,0)

//Global vars & consts
const byte LED_PIN = 1; //for my digisparks; other digisparks may use 0 as the LED pin

void setup()
{
  TrinketKeyboard.begin();
  pinMode(LED_PIN, OUTPUT);
}

void loop()
{
//  //blink LED; use fast blink to indicate error state/disconnect of digispark as HID device
//  static unsigned long t_start = millis();
//  static unsigned int blinkDelay = 1000; //ms
//  static boolean ledState = LOW;
//  if (millis() - t_start >= blinkDelay)
//  {
//    ledState = !ledState;
//    digitalWrite(LED_PIN,ledState);
//  }
//  if (TrinketKeyboard.isConnected()==true)
//    blinkDelay = 1000; //ms
//  else
//    blinkDelay = 50; //ms; fast blink to indicate error/disconnect of digispark as HID device

  //The poll function must be called at least once every 10 ms, or you must command a keystroke.
  //Otherwise, the computer may think that the device has stopped working, and give errors.
  TrinketKeyboard.poll();

////  TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_GUI,KEYCODE_R); //press the Windows Key + R (open "run" command box)
//  TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_GUI,0); //press the Windows Key
//  TrinketHidReleaseKeys();

  TrinketHidCompatibleDelay(1000);

  //test prints
  uint8_t buttonLEDstate = TrinketKeyboard.getLEDstate();
  TrinketKeyboard.print(buttonLEDstate,BIN); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.print("test"); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.println();

  //light up onboard LED when Caps Lock is on
  digitalWrite(LED_PIN, (TrinketKeyboard.getLEDstate()&KB_LED_CAPS)?HIGH:LOW);  

} //end of loop

//this is a USB-compatible delay, so that the 10ms max time between poll calls is not exceeded
void TrinketHidCompatibleDelay(unsigned int desiredDelay)
{
  unsigned long t_start = millis(); //ms
  while (millis()-t_start<desiredDelay)
  {
    TrinketKeyboard.poll();
  }
}
@ElectricRCAircraftGuy
Copy link
Author

Also, TrinketHidCombo.getLEDstate() is broken, but it works fine for the TrinketKeyboard library. See issue here: #8

@ElectricRCAircraftGuy
Copy link
Author

ElectricRCAircraftGuy commented Jul 19, 2016

TrinketHidCombo.print and TrinketHidCombo.println are still broken.

@ElectricRCAircraftGuy
Copy link
Author

Bump. TrinketHidCombo.print and TrinketHidCombo.println are still broken.

@ElectricRCAircraftGuy
Copy link
Author

cancel that. They seem to be ok. It's a factor of having the device type into Notepad++, which has built-in autocomplete. The autocomplete throws it off. My bad. I think this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant