Page 1 of 1

GBZ w/ BlackberryTrackball --> ScummVM

Posted: Sun Oct 30, 2016 3:11 pm
by dezent
Hi everyone

using the D-pad in ScummVM is just pain, that was the reason for implementing a blackberry trackball (~5€@ebay as breakout).
The device itselfe works fine just a bit "unsmooth", but much better than D-pad controlls.

Teensy Code with "up, down esc, enter" for easier retropie menu navigation and mouse control.
Moving the trackball turns on the LED light (RGB+white).

The code is still beta, but works perfectly fine for me. A mixure of wermys code and tennsy example.

Code: Select all

#include <Bounce.h>

#define NUM_KEYS 12
const int moveDistance = 15;  // how much to move the mouse on each button press
const int redPin =  23;
const int bluePin =  22;
const int greenPin =  21;
const int whitePin =  20;
int j = 1;
float k = 0; 

struct Key {
  int keycode;
  Bounce* bounce;
};


// 2 mouseknöpfe clicks
Bounce mbuttonl = Bounce(13, 10); // pin 13 click
Bounce mbuttonr = Bounce(14, 10); // pin 14 right click (not used yet)

// 4 richtungen
Bounce mup = Bounce(19, 10);  // UP
Bounce mdown = Bounce(16, 10); // DOWN
Bounce mleft = Bounce(15, 10); // LEFT
Bounce mright = Bounce(18, 10); // RIGHT


Key keys[NUM_KEYS];

Key key(int keycode, int pin) {
  Key *ret = new Key;
  ret->keycode = keycode;
  ret->bounce = new Bounce(pin, 10);
  pinMode(pin, INPUT_PULLUP);
  return *ret;
}

void setupKeys() {
  keys[0] = key(KEY_LEFT_ARROW, 0);
  keys[1] = key(KEY_UP_ARROW, 1);
  keys[2] = key(KEY_DOWN_ARROW, 2);
  keys[3] = key(KEY_RIGHT_ARROW, 3);
  keys[4] = key('z', 4);
  keys[5] = key('x', 5);
  keys[6] = key(KEY_ESC, 6);
  keys[7] = key(KEY_RETURN, 7);
  keys[8] = key(KEY_F5, 8);
  keys[9] = key('o', 9);
  keys[10] = key('q',10);
  keys[11] = key('e',11);
  }

void setup() {
  setupKeys();
   // maus setup
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(whitePin, OUTPUT);


  //Mouse.screenSize(1920, 1080);
  Mouse.screenSize(320, 240);
  
  Keyboard.begin();
  //  pinMode(0, INPUT_PULLUP);
}

void loop() {
  j = j + 1;
  for (int i = 0; i < NUM_KEYS; i++) {
    keys[i].bounce->update();
    if (keys[i].bounce->fallingEdge()) {
      Keyboard.press(keys[i].keycode);
    } else if (keys[i].bounce->risingEdge()) {
      Keyboard.release(keys[i].keycode);
    }
  }
  // mouse

  // LED wieder ausschlaten
  k = j % 30000;
  if (k == 0 ){
    j = 1;
        digitalWrite(whitePin, LOW);
        digitalWrite(bluePin, LOW);
        digitalWrite(greenPin, LOW);
        digitalWrite(redPin, LOW);

    } 
    
  mup.update();
  mdown.update();
  mleft.update();
  mright.update();
  mbuttonl.update();
  mbuttonr.update();
    //digitalWrite(whitePin, LOW);
    //digitalWrite(bluePin, LOW);
    //digitalWrite(redPin, LOW);
    //digitalWrite(greenPin, LOW);


   if (mleft.fallingEdge()) {
    Mouse.move(-moveDistance, 0); // move Left
    digitalWrite(redPin, HIGH);
  }
  if (mright.fallingEdge()) {
    Mouse.move(moveDistance, 0);  // move Right
    digitalWrite(greenPin, HIGH);

  }
  if (mup.fallingEdge()) {
    Mouse.move(0, -moveDistance); // move Up
    digitalWrite(bluePin, HIGH);

  }
  if (mdown.fallingEdge()) {
    Mouse.move(0, moveDistance);  // move Down
    digitalWrite(whitePin, HIGH);

  }


 // For the mouse buttons, we must detect both the falling and rising edges,
  // to press the mouse button when the button on our digital pin is pressed,
  // and to later release it when the physical button releases (the pin rises
  // from low back to high, thanks to INPUT_PULLUP).

 if (mbuttonl.fallingEdge()) {
    Mouse.press(MOUSE_LEFT);
  }
  if (mbuttonl.risingEdge()) {
    Mouse.release(MOUSE_LEFT);
  }
 if (mbuttonr.fallingEdge()) {
    Mouse.press(MOUSE_RIGHT);
  }
  if (mbuttonr.risingEdge()) {
    Mouse.release(MOUSE_RIGHT);
  }
   
 
}

Re: GBZ w/ BlackberryTrackball --> ScummVM

Posted: Sun Oct 30, 2016 3:48 pm
by ABH
That's awesome , Thanks for shearing :)

Re: GBZ w/ BlackberryTrackball --> ScummVM

Posted: Sun Oct 30, 2016 7:17 pm
by Jace055
This is a very cool idea. Do you have any other information? Which trackball did you use? There are dozens of different parts on eBay and it seems some of them are just the ball and not the encoder. How did you wire it?

Re: GBZ w/ BlackberryTrackball --> ScummVM

Posted: Mon Oct 31, 2016 12:46 am
by dezent
I have used this one.


ICSH044A icstation Blackberry Trackball Breakout Board
http://s.aliexpress.com/yuyIriuy

Power comes from teensyLC Pin 17 (the one on the oposite side of USB Port) ground is also connected to teensy.

Mouse directions are connected to Pin 15,16,18,19.
Left
Mouse Click is Pin 13

Pins 20,21,22,23 are used for the Trackball LEDs

They glow for around 1 second after Last Input.

Re: GBZ w/ BlackberryTrackball --> ScummVM

Posted: Tue Nov 15, 2016 6:55 pm
by Live2slay
Nice! Really cool build.

Re: GBZ w/ BlackberryTrackball --> ScummVM

Posted: Wed Nov 16, 2016 5:03 am
by Muon
Genius! :D

Re: GBZ w/ BlackberryTrackball --> ScummVM

Posted: Thu Nov 24, 2016 3:26 pm
by Billy Blaze
this is fantastic!

can you give us a video working example of how this looks in action please?! this'd be so helpful.
likewise I'd be thankful about a short review concerning the responsiveness and accuracy of this device. is it possible to navigate diagonal? and does your code provide an option of switching off the LEDs entirely?

I'm really curious about this idea. planing to implement a similar workaround myself. thought it'd be nice to have the trackball just on the backside of the GBZ to keep the front "clean".