-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from nullstalgia/drawsome
Drawsome Tablet
- Loading branch information
Showing
8 changed files
with
289 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
examples/Drawsome Tablet/Drawsome_DebugPrint/Drawsome_DebugPrint.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters