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

Drawsome Tablet #57

Merged
merged 10 commits into from
May 25, 2020
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ script:
- buildExampleFolder Nunchuk
- buildExampleFolder "SNES Mini"
- buildExampleFolder "uDraw Tablet"
- buildExampleFolder "Drawsome Tablet"

notifications:
email:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ Plug in your controller, upload the example to your board, and have fun!
### Wii
* Nunchuk
* Classic Controller

### Wii Instruments
* Guitar Hero Guitar
* Guitar Hero World Tour Drums
* DJ Hero Turntable

### Wii Drawing Tablets
* uDraw Tablet
* Drawsome Tablet

### Mini Console
* NES Mini Controller
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Project Nintendo Extension Controller Library
* @author nullstalgia
* @link github.com/dmadison/NintendoExtensionCtrl
* @license LGPLv3 - Copyright (c) 2018 David Madison
*
* This file is part of the Nintendo Extension Controller Library.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Example: Drawsome_DebugPrint
* Description: Connect to a Drawsome Tablet and continuously print
* its control data, nicely formatted for debugging, over
* the serial bus.
*/

#include <NintendoExtensionCtrl.h>

DrawsomeTablet tablet;

void setup() {
Serial.begin(115200);
tablet.begin();

while (!tablet.connect()) {
Serial.println("Drawsome Tablet not detected!");
delay(1000);
}
}

void loop() {
boolean success = tablet.update(); // Get new data from the tablet

if (success == true) { // We've got data!
tablet.printDebug(); // Print all of the values!
}
else { // Data is bad :(
Serial.println("Tablet Disconnected!");
delay(1000);
tablet.connect();
}
}
83 changes: 83 additions & 0 deletions examples/Drawsome Tablet/Drawsome_Demo/Drawsome_Demo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Project Nintendo Extension Controller Library
* @author nullstalgia
* @link github.com/dmadison/NintendoExtensionCtrl
* @license LGPLv3 - Copyright (c) 2018 David Madison
*
* This file is part of the Nintendo Extension Controller Library.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Example: Drawsome_Demo
* Description: Connect to a Drawsome Tablet and demonstrate all of
* the avaiable control data functions.
*/

#include <NintendoExtensionCtrl.h>

DrawsomeTablet tablet;

void setup() {
Serial.begin(115200);
tablet.begin();

while (!tablet.connect()) {
Serial.println("Drawsome Tablet not detected!");
delay(1000);
}
}

void loop() {
Serial.println("----- Drawsome Tablet Demo -----"); // Making things easier to read

boolean success = tablet.update(); // Get new data from the tablet

if (!success) { // Ruh roh
Serial.println("Controller disconnected!");
delay(1000);
tablet.connect();
}
else {
// Is the pen near the drawing surface?
boolean detected = tablet.penDetected();

if (detected == true) {
Serial.print("The pen is detected! It's currently at ");

// Read the X/Y coordinates (0-65535)
uint16_t xCoordinate = tablet.penX();
Serial.print("X: ");
Serial.print(xCoordinate);

uint16_t yCoordinate = tablet.penY();
Serial.print(" Y: ");
Serial.print(yCoordinate);

Serial.println();
}
else if (detected == false) {
Serial.println("The pen is too far away!");
}

// Read the Pressure (0-4095)
uint16_t pressure = tablet.penPressure();

Serial.print("The current pressure is ");
Serial.println(pressure);

// Print all the values!
tablet.printDebug();
delay(100);
}
}
1 change: 1 addition & 0 deletions src/NintendoExtensionCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "controllers/DrumController.h"
#include "controllers/DJTurntable.h"
#include "controllers/uDrawTablet.h"
#include "controllers/DrawsomeTablet.h"

// Mini Controllers
/* (included with ClassicController.h) */
Expand Down
74 changes: 74 additions & 0 deletions src/controllers/DrawsomeTablet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Project Nintendo Extension Controller Library
* @author nullstalgia
* @link github.com/dmadison/NintendoExtensionCtrl
* @license LGPLv3 - Copyright (c) 2018 David Madison
*
* This file is part of the Nintendo Extension Controller Library.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "DrawsomeTablet.h"

namespace NintendoExtensionCtrl {

constexpr CtrlIndex DrawsomeTablet_Shared::Maps::PenX_LSB;
constexpr CtrlIndex DrawsomeTablet_Shared::Maps::PenX_MSB;
constexpr CtrlIndex DrawsomeTablet_Shared::Maps::PenY_LSB;
constexpr CtrlIndex DrawsomeTablet_Shared::Maps::PenY_MSB;

constexpr CtrlIndex DrawsomeTablet_Shared::Maps::Pressure_LSB;
constexpr ByteMap DrawsomeTablet_Shared::Maps::Pressure_MSB;

constexpr BitMap DrawsomeTablet_Shared::Maps::Pen_Detected;

boolean DrawsomeTablet_Shared::specificInit() {
/* Two necessary register writes during initialization before the tablet
* will start sending data. See this for reference:
* https://www.raphnet.net/divers/wii_graphics_tablets/index_en.php
*/
return writeRegister(0xFB, 0x01) && writeRegister(0xF0, 0x55);
}

uint16_t DrawsomeTablet_Shared::penX() const {
return (getControlData(Maps::PenX_MSB) << 8) | getControlData(Maps::PenX_LSB);
}

uint16_t DrawsomeTablet_Shared::penY() const {
return (getControlData(Maps::PenY_MSB) << 8) | getControlData(Maps::PenY_LSB);
}

uint16_t DrawsomeTablet_Shared::penPressure() const {
return (getControlData(Maps::Pressure_MSB) << 8) | getControlData(Maps::Pressure_LSB);
}

boolean DrawsomeTablet_Shared::penDetected() const {
return getControlBit(Maps::Pen_Detected);
}

void DrawsomeTablet_Shared::printDebug(Print& output) const {
char buffer[60];

char penPrint = penDetected() ? 'Y' : 'N';

output.print("DrawsomeTablet - ");
sprintf(buffer,
"Pen:(%6u, %6u) | Pressure:%4u | Pen Detect:%c",
penX(), penY(), penPressure(), penPrint);

output.println(buffer);
}

} // End "NintendoExtensionCtrl" namespace
66 changes: 66 additions & 0 deletions src/controllers/DrawsomeTablet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Project Nintendo Extension Controller Library
* @author nullstalgia
* @link github.com/dmadison/NintendoExtensionCtrl
* @license LGPLv3 - Copyright (c) 2018 David Madison
*
* This file is part of the Nintendo Extension Controller Library.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef NXC_DrawsomeTablet_h
#define NXC_DrawsomeTablet_h

#include "internal/ExtensionController.h"

namespace NintendoExtensionCtrl {
class DrawsomeTablet_Shared : public ExtensionController {
public:
struct Maps {
constexpr static CtrlIndex PenX_LSB = 0;
constexpr static CtrlIndex PenX_MSB = 1;

constexpr static CtrlIndex PenY_LSB = 2;
constexpr static CtrlIndex PenY_MSB = 3;

constexpr static CtrlIndex Pressure_LSB = 4;
constexpr static ByteMap Pressure_MSB = ByteMap(5, 4, 0, 0);

constexpr static BitMap Pen_Detected = {5, 7};
};

DrawsomeTablet_Shared(ExtensionData &dataRef) :
ExtensionController(dataRef, ExtensionType::DrawsomeTablet) {}

DrawsomeTablet_Shared(ExtensionPort &port) :
DrawsomeTablet_Shared(port.getExtensionData()) {}

boolean specificInit(); // for required register writes at init

uint16_t penX() const; // 16 bits, 0-65535
uint16_t penY() const;

uint16_t penPressure() const; // 12 bits, 0-4095

boolean penDetected() const;

void printDebug(Print& output = NXC_SERIAL_DEFAULT) const;
};
}

using DrawsomeTablet = NintendoExtensionCtrl::BuildControllerClass
<NintendoExtensionCtrl::DrawsomeTablet_Shared>;

#endif
7 changes: 6 additions & 1 deletion src/internal/NXC_Identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum class ExtensionType {
GuitarController,
DrumController,
DJTurntableController,
uDrawTablet
uDrawTablet,
DrawsomeTablet
};

namespace NintendoExtensionCtrl {
Expand Down Expand Up @@ -71,6 +72,10 @@ namespace NintendoExtensionCtrl {
else if (idData[4] == 0x01 && idData[5] == 0x12) {
return ExtensionType::uDrawTablet;
}
// Drawsome Tablet Con. ID: 0x0013
else if (idData[4] == 0x00 && idData[5] == 0x13) {
return ExtensionType::DrawsomeTablet;
}
}

return ExtensionType::UnknownController; // No matches
Expand Down