tstrausb / XKeys-Library-for-Arduino

A library to allow use of an X-Keys device on an Arduino microcontroller (used in conjunction with Circuits at Home USB Host Shield 2.0)
GNU General Public License v2.0
4 stars 3 forks source link

No Backlight #3

Open Samlmdg opened 8 years ago

Samlmdg commented 8 years ago

I try your library whith the example scripts. With a Xkey 128 i have no backlight. I don't know where the problem is ... Can you help me ?

here is my code :

#include "usbhid.h"
#include "hiduniversal.h"
#include "Usb.h"

#include <SPI.h>
#include <hidxkeysrptparser.h>

uint8_t counter = 0; 
uint8_t color = BL_BLUE;
uint8_t mode = MODE_ON;

/******************************************************************************
  Create a subclass of the XkeysReportParser and override the OnKey methods 
  to handle the key reports when they are received.
******************************************************************************/
class XKeys : public XkeysReportParser
{

public:
        XKeys();
protected:
  virtual void OnKeyUp(uint8_t keyId); 
  virtual void OnKeyDown(uint8_t keyId);
};

XKeys::XKeys() : XkeysReportParser() {}

XKeys XKs;

void XKeys::OnKeyDown(uint8_t keyId)
{
    Serial.print("Key down: ");
    Serial.println(keyId, DEC);
}

void XKeys::OnKeyUp(uint8_t keyId)
{
    Serial.print("Key Up: ");
    Serial.println(keyId, DEC);
}

void setup()
{
  /****Define your device details here.****/
  XKs.STICK = 0; // 0 for pad, 1 for stick
  XKs.PADSIZE = 128; // number of keys on your device
  /****************************************/

  Serial.begin( 115200 );
  while(!Serial); // waiting for serial port to connect
/******************************************************************************
    If you are running on boards like the Ethernet you might need 
    set the pin modes and write them to high to get the SPI bus to
    allow the USB Host Shield to work. You may also have to rewire 
    the USB host shield to use pin 7 instead of 10 for SPI. 
    Procedure on Circuits@Home's website.
******************************************************************************/
  pinMode(10, OUTPUT);
  //pinMode(4, OUTPUT);
  digitalWrite(10, HIGH);
  //digitalWrite(4, HIGH);

  Serial.println("Start");

  XKs.init();

  /*Place commands here to put your XKeys device into its desired initial state.*/
  /*************my particular example***************/
  for(uint8_t i = 0; i < 8; i++) {
    XKs.setRowBL((i + 1), BL_RED, MODE_OFF); // turning off all red backlighting for initial state on an XK24
  }
  for(uint8_t i = 0; i < 8; i++) {
    XKs.setRowBL((i + 1), BL_BLUE, MODE_OFF); // turning off all blue backlighting for initial state on an XK24
  }

}

void loop()
{
    // Excutes the USB.init() function to receive reports This MUST stay here!

   XKs.runLoop();
    XKs.indexSetBL(counter, color, mode);
    counter++;
    if(counter == 6) {
      counter = 8;
    }
    if(counter == 14) {
      counter = 16;
    }
    if(counter == 22) {
      counter = 24;
    }
    if((counter == 30) && (color == BL_BLUE) && (mode == MODE_ON)) {
      color = BL_RED;
      counter = 0;
    }
    if((counter == 30) && (color == BL_RED) && (mode == MODE_ON)) {
      mode = MODE_OFF;
      color = BL_BLUE;
      counter = 0;
    }
    if((counter == 30) && (color == BL_BLUE) && (mode == MODE_OFF)) {
      color = BL_RED;
      counter = 0;
    }
    if((counter == 30) && (color == BL_RED) && (mode == MODE_OFF)) {
      mode = MODE_ON;
      color = BL_BLUE;
      counter = 0;
    }
}
tstrausb commented 8 years ago

Hi Sam,

A few questions: with this sketch, does the pad function? Do you see key up and down messages in the serial monitor? Do all backlights initially go out? How new is the pad?

Thanks, Tom

On Sep 2, 2016, at 8:15 AM, Samlmdg notifications@github.com<mailto:notifications@github.com> wrote:

I try your library whith the example scripts. With a Xkey 128 i have no backlight. I don't know where the problem is ... Can you help me ?

here is my code :

include "usbhid.h"

include "hiduniversal.h"

include "Usb.h"

include

include

uint8_t counter = 0; uint8_t color = BL_BLUE; uint8_t mode = MODE_ON;

/** Create a subclass of the XkeysReportParser and override the OnKey methods to handle the key reports when they are received. **/ class XKeys : public XkeysReportParser {

public: XKeys(); protected: virtual void OnKeyUp(uint8_t keyId); virtual void OnKeyDown(uint8_t keyId); };

XKeys::XKeys() : XkeysReportParser() {}

XKeys XKs;

void XKeys::OnKeyDown(uint8_t keyId) { Serial.print("Key down: "); Serial.println(keyId, DEC); }

void XKeys::OnKeyUp(uint8_t keyId) { Serial.print("Key Up: "); Serial.println(keyId, DEC); }

void setup() { /*_Define your device details here.**_/ XKs.STICK = 0; // 0 for pad, 1 for stick XKs.PADSIZE = 128; // number of keys on your device /*****/

Serial.begin( 115200 ); while(!Serial); // waiting for serial port to connect /** If you are running on boards like the Ethernet you might need set the pin modes and write them to high to get the SPI bus to allow the USB Host Shield to work. You may also have to rewire the USB host shield to use pin 7 instead of 10 for SPI. Procedure on Circuits@Home's website. **/ pinMode(10, OUTPUT); //pinMode(4, OUTPUT); digitalWrite(10, HIGH); //digitalWrite(4, HIGH);

Serial.println("Start");

XKs.init();

/Place commands here to put your XKeys device into its desired initial state./ /****my particular example******/ for(uint8_t i = 0; i < 8; i++) { XKs.setRowBL((i + 1), BL_RED, MODE_OFF); // turning off all red backlighting for initial state on an XK24 } for(uint8_t i = 0; i < 8; i++) { XKs.setRowBL((i + 1), BL_BLUE, MODE_OFF); // turning off all blue backlighting for initial state on an XK24 }

}

void loop() { // Excutes the USB.init() function to receive reports This MUST stay here!

XKs.runLoop(); XKs.indexSetBL(counter, color, mode); counter++; if(counter == 6) { counter = 8; } if(counter == 14) { counter = 16; } if(counter == 22) { counter = 24; } if((counter == 30) && (color == BL_BLUE) && (mode == MODE_ON)) { color = BL_RED; counter = 0; } if((counter == 30) && (color == BL_RED) && (mode == MODE_ON)) { mode = MODE_OFF; color = BL_BLUE; counter = 0; } if((counter == 30) && (color == BL_BLUE) && (mode == MODE_OFF)) { color = BL_RED; counter = 0; } if((counter == 30) && (color == BL_RED) && (mode == MODE_OFF)) { mode = MODE_ON; color = BL_BLUE; counter = 0; } }

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/tstrausb/XKeys-Library-for-Arduino/issues/3, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AF1yvA-6URnIT4U-S_gX2Rc95ujHHEYjks5qmBNWgaJpZM4JzpdI.

Samlmdg commented 8 years ago

Hi Tom,

Everything is OK : I see each keydown & up, no problem. Just no backlight with the sketch (it works with the X-key software)... Strange ! The x-Key is brand new. I bought it in august. On start, nothing happen : The initial state of led is red... After that :

 for(uint8_t i = 0; i < 8; i++) {
    XKs.setRowBL((i + 1), BL_RED, MODE_OFF); // turning off all red backlighting for initial state on an XK24
  }
  for(uint8_t i = 0; i < 8; i++) {
    XKs.setRowBL((i + 1), BL_BLUE, MODE_OFF); // turning off all blue backlighting for initial state on an XK24
  }

It's red ... Thank you for your help

Sam

tstrausb commented 8 years ago

Hello again Sam,

So, initially all the red backlights are on. And the lines you cited below are not working. Let me take a look at the latest HID reports from Pi Engineering for this model. There could be some differences from the last time I updated this library. To be honest, I never tested with a 128 pad.

Thanks,

Tom


From: Samlmdg notifications@github.com Sent: Thursday, September 8, 2016 9:41 AM To: tstrausb/XKeys-Library-for-Arduino Cc: Thomas Strausbaugh; Comment Subject: Re: [tstrausb/XKeys-Library-for-Arduino] No Backlight (#3)

Hi Tom,

Everything is OK : I see each keydown & up, no problem. Just no backlight with the sketch (it works with the X-key software)... Strange ! The x-Key is brand new. I bought it in august. On start, nothing happen : The initial state of led is red... After that :

for(uint8_t i = 0; i < 8; i++) { XKs.setRowBL((i + 1), BL_RED, MODE_OFF); // turning off all red backlighting for initial state on an XK24 } for(uint8_t i = 0; i < 8; i++) { XKs.setRowBL((i + 1), BL_BLUE, MODE_OFF); // turning off all blue backlighting for initial state on an XK24 }

It's red ... Thank you for your help

Sam

You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/tstrausb/XKeys-Library-for-Arduino/issues/3#issuecomment-245600731, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AF1yvNzCVm9fX4TJEfExbW70exmoV4Erks5qoBCDgaJpZM4JzpdI.

Samlmdg commented 8 years ago

Thanks a lot for your help :)

Samlmdg commented 7 years ago

Hi Tom,

Hi Tom, Since september have you find time to see how to solve my issue ? thanks

Sam

tstrausb commented 7 years ago

Apologies Sam,

To be honest, I haven't yet gotten to this. I will try to get on it this week.

Sorry again,

Tom

On Oct 12, 2016, at 9:41 AM, Samlmdg notifications@github.com<mailto:notifications@github.com> wrote:

Hi Tom,

Hi Tom, Since september have you find time to see how to solve my issue ? thanks

Sam

You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/tstrausb/XKeys-Library-for-Arduino/issues/3#issuecomment-253216411, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AF1yvFCxkk4-FX-7zU5zbIsOj2QQ_g_lks5qzOOLgaJpZM4JzpdI.

Samlmdg commented 7 years ago

Hi Tom, Have you got some news ? Sam

tstrausb commented 6 years ago

Hi Sam,

As you can tell, this project pretty much fell off my radar! Found this message from you while cleaning out my mailbox. Did you ever get anywhere with this? I plan to revisit the project over the next couple of months. I know a major update is likely appropriate...

Tom

On Mar 24, 2017, at 4:04 PM, Samlmdg notifications@github.com<mailto:notifications@github.com> wrote:

Hi Tom, Have you got some news ? Sam

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/tstrausb/XKeys-Library-for-Arduino/issues/3#issuecomment-289129704, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AF1yvKMVrIm8fSUwj2aewB4nnrWwexM0ks5rpCHTgaJpZM4JzpdI.

Samlmdg commented 6 years ago

Hi Tom,

Thank you for your answer. my issue is still up to date ! I'm waiting for that major update :) Hope it will fix the backlight problem for the XK 128

Sam