You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kaleidoscope/plugins/Kaleidoscope-Hardware-Ploop.../examples/PloopyMini/PloopyMini.ino

101 lines
2.0 KiB

// -*- mode: c++ -*-
#include "Kaleidoscope.h"
#include "Kaleidoscope-FocusSerial.h"
#include "Kaleidoscope-EEPROM-Settings.h"
#include "Kaleidoscope-EEPROM-Keymap.h"
#include "Kaleidoscope-MouseKeys.h"
#include "Kaleidoscope-Macros.h"
#include "kaleidoscope/driver/sensor/ADNS5050.h"
struct PTBMProps : kaleidoscope::driver::sensor::ADNS5050BaseProps {
struct pin {
static constexpr uint8_t SCLK = PIN_B7;
static constexpr uint8_t SDIO = PIN_C6;
static constexpr uint8_t NCS = PIN_B4;
};
};
typedef kaleidoscope::driver::sensor::ADNS5050<PTBMProps> SensorT;
SensorT Sensor;
KEYMAPS(
[0] = KEYMAP(M(0), M(1), M(2), Key_D, Key_E, Key_NoKey),
);
void deltaX() {
uint8_t dx = Sensor.readRegister(Sensor.Register::DELTA_X);
Serial.print("dx = ");
Serial.println(dx);
}
void deltaY() {
uint8_t dy = Sensor.readRegister(Sensor.Register::DELTA_Y);
Serial.print("dy = ");
Serial.println(dy);
}
void getPID() {
uint8_t pid = Sensor.readRegister(Sensor.Register::PRODUCT_ID);
uint8_t rid = Sensor.readRegister(Sensor.Register::REVISION_ID);
uint8_t pid2 = Sensor.readRegister(Sensor.Register::PRODUCT_ID2);
Focus.send("pid=", pid, "rid=", rid, "pid2=", pid2, "\n");
}
const macro_t *macroAction(uint8_t macro_id, KeyEvent &event) {
if (!keyToggledOn(event.state)) {
return MACRO_NONE;
}
switch (macro_id) {
case 0:
deltaX();
break;
case 1:
deltaY();
break;
case 2:
getPID();
break;
}
return MACRO_NONE;
}
KALEIDOSCOPE_INIT_PLUGINS(
Focus,
EEPROMSettings,
EEPROMKeymap,
MouseKeys,
Macros
);
void setup() {
Kaleidoscope.setup();
EEPROMKeymap.setup(5);
Sensor.setup();
}
void loop() {
SensorT::Report report;
Kaleidoscope.loop();
report = Sensor.readReport();
if (report.dx != -1) {
Serial.print("dx = ");
Serial.print(report.dx);
Serial.print(" ");
}
if (report.dy != -1) {
Serial.print("dy = ");
Serial.print(report.dy);
}
if (report.dy != -1 || report.dx != -1) {
Serial.println();
}
}