Compare commits
No commits in common. "d1660bb6fd78ff4bf062a8cc3c22e51ca005b303" and "afecfe58901f3a8e8f5b3e0e3764d9ec36f4edf3" have entirely different histories.
d1660bb6fd
...
afecfe5890
|
@ -1,6 +1,3 @@
|
||||||
[submodule "libs/hidapi"]
|
[submodule "libs/hidapi"]
|
||||||
path = libs/hidapi
|
path = libs/hidapi
|
||||||
url = ssh://git@git.betalupi.com:33/mirrors-libs/hidapi.git
|
url = ssh://git@git.betalupi.com:33/mirrors-libs/hidapi.git
|
||||||
[submodule "libs/spdlog"]
|
|
||||||
path = libs/spdlog
|
|
||||||
url = ssh://git@git.betalupi.com:33/Reflector/spdlog.git
|
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -25,8 +25,7 @@ libs: $(BUILD_DIR)/hid.o
|
||||||
CPPFLAGS := -MMD -MP \
|
CPPFLAGS := -MMD -MP \
|
||||||
-Wall \
|
-Wall \
|
||||||
-I src \
|
-I src \
|
||||||
-I libs/hidapi/hidapi \
|
-I libs/hidapi/hidapi
|
||||||
-I libs/spdlog/include
|
|
||||||
|
|
||||||
# udev: required by hidapi
|
# udev: required by hidapi
|
||||||
LDFLAGS := -l fftw3 -l udev
|
LDFLAGS := -l fftw3 -l udev
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 6c95f4c8168401badff89d0c16e3887ea91ea9ad
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "ergodox.hpp"
|
#include "ergodox.hpp"
|
||||||
|
|
||||||
|
|
||||||
Ergodox::Ergodox(
|
Ergodox::Ergodox(
|
||||||
unsigned short vendor_id,
|
unsigned short vendor_id,
|
||||||
unsigned short product_id,
|
unsigned short product_id,
|
||||||
|
@ -101,21 +102,18 @@ bool Ergodox::try_connect() {
|
||||||
|
|
||||||
#define MAX_STR 255
|
#define MAX_STR 255
|
||||||
wchar_t wstr[MAX_STR];
|
wchar_t wstr[MAX_STR];
|
||||||
char nstr[MAX_STR];
|
|
||||||
|
|
||||||
|
|
||||||
spdlog::info("Connected to device!");
|
wprintf(L"\nConnected to device!\n");
|
||||||
|
|
||||||
// Read metadata
|
// Read metadata
|
||||||
wstr[0] = 0x0000;
|
wstr[0] = 0x0000;
|
||||||
hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
||||||
misc::to_narrow(wstr, nstr, MAX_STR);
|
wprintf(L"Manufacturer String: %ls\n", wstr);
|
||||||
spdlog::info("Manufacturer String: {0}", nstr);
|
|
||||||
|
|
||||||
wstr[0] = 0x0000;
|
wstr[0] = 0x0000;
|
||||||
hid_get_product_string(handle, wstr, MAX_STR);
|
hid_get_product_string(handle, wstr, MAX_STR);
|
||||||
misc::to_narrow(wstr, nstr, MAX_STR);
|
wprintf(L"Product String: %ls\n", wstr);
|
||||||
spdlog::info("Product String: {0}", nstr);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
connected = false;
|
connected = false;
|
||||||
|
@ -170,7 +168,7 @@ bool Ergodox::write(uint8_t cmd, const uint8_t* data, uint8_t data_len) {
|
||||||
res = hid_write(handle, packet, packet_size + 1);
|
res = hid_write(handle, packet, packet_size + 1);
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
spdlog::info("Lost device, disconnecting.");
|
wprintf(L"Lost device, disconnecting.\n");
|
||||||
disconnect();
|
disconnect();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +194,7 @@ bool Ergodox::read() {
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
return false;
|
return false;
|
||||||
} else if (res < 0) {
|
} else if (res < 0) {
|
||||||
spdlog::info("Lost device, disconnecting.");
|
wprintf(L"Lost device, disconnecting.\n");
|
||||||
disconnect();
|
disconnect();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +204,7 @@ bool Ergodox::read() {
|
||||||
// If keyboard sends a state packet, parse it.
|
// If keyboard sends a state packet, parse it.
|
||||||
case CMD_SEND_STATE:
|
case CMD_SEND_STATE:
|
||||||
if (animation_mode != read_buf[1]) {
|
if (animation_mode != read_buf[1]) {
|
||||||
spdlog::info("Mode set to {0:x}", read_buf[1]);
|
wprintf(L"Mode set to 0x%02X\n", read_buf[1]);
|
||||||
animation_mode = read_buf[1];
|
animation_mode = read_buf[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +223,7 @@ void Ergodox::test_connection() {
|
||||||
|
|
||||||
// Block until a connection is established.
|
// Block until a connection is established.
|
||||||
void Ergodox::connect_loop() {
|
void Ergodox::connect_loop() {
|
||||||
spdlog::info("Trying to connect...");
|
wprintf(L"Trying to connect...\n");
|
||||||
while (!connected) {
|
while (!connected) {
|
||||||
try_connect();
|
try_connect();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(RECONNECT_SLEEP_MS));
|
std::this_thread::sleep_for(std::chrono::milliseconds(RECONNECT_SLEEP_MS));
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "hidapi.h"
|
#include "hidapi.h"
|
||||||
#include "utility/misc.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
|
|
50
src/main.cpp
50
src/main.cpp
|
@ -5,9 +5,6 @@
|
||||||
// For reading FIFO
|
// For reading FIFO
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
// For sleep
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
// Local files
|
// Local files
|
||||||
#include "utility/bitmap.hpp"
|
#include "utility/bitmap.hpp"
|
||||||
|
@ -17,8 +14,6 @@
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
|
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
//
|
//
|
||||||
|
@ -36,7 +31,7 @@
|
||||||
// Keyboard interface:
|
// Keyboard interface:
|
||||||
// Frame rate limit
|
// Frame rate limit
|
||||||
// Clean up reconnect code
|
// Clean up reconnect code
|
||||||
// Better log messages, compiled spdlog
|
// Better log messages
|
||||||
//
|
//
|
||||||
// Get parameters from keyboard (width, height, etc)
|
// Get parameters from keyboard (width, height, etc)
|
||||||
//
|
//
|
||||||
|
@ -52,8 +47,6 @@ const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
spdlog::set_level(spdlog::level::info);
|
|
||||||
|
|
||||||
// buffer size for waveform:
|
// buffer size for waveform:
|
||||||
// (44100 / fps * 10), make 10 bigger for slower scrolling
|
// (44100 / fps * 10), make 10 bigger for slower scrolling
|
||||||
//
|
//
|
||||||
|
@ -85,42 +78,29 @@ int main(int argc, char *argv[]) {
|
||||||
Dox.connect_loop();
|
Dox.connect_loop();
|
||||||
|
|
||||||
|
|
||||||
// Frame rate limiter
|
|
||||||
std::chrono::time_point<
|
|
||||||
std::chrono::steady_clock,
|
|
||||||
std::chrono::nanoseconds
|
|
||||||
> t = std::chrono::steady_clock::now();
|
|
||||||
//t += std::chrono::milliseconds(30);
|
|
||||||
//this_thread::sleep_until(t);
|
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
if (Dox.is_connected()) {
|
if (Dox.is_connected()) {
|
||||||
if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) {
|
if (Dox.get_animation_mode() == 0x02) {
|
||||||
if (Dox.get_animation_mode() == 0x02) {
|
buf.update();
|
||||||
buf.update();
|
fft.update(buf);
|
||||||
fft.update(buf);
|
|
||||||
|
|
||||||
hid_buf[0] = CMD_ANIM_DATA_fft;
|
hid_buf[0] = CMD_ANIM_DATA_fft;
|
||||||
for (size_t i = 0; i < 10; i++) {
|
for (size_t i = 0; i < 10; i++) {
|
||||||
// Get height from fft, apply bottom_skip
|
// Get height from fft, apply bottom_skip
|
||||||
ssize_t h = fft.get_output()[i] - BOTTOM_SKIP;
|
ssize_t h = fft.get_output()[i] - BOTTOM_SKIP;
|
||||||
|
|
||||||
// Enforce max and min
|
// Enforce max and min
|
||||||
// max implicitly enforces top_skip
|
// max implicitly enforces top_skip
|
||||||
h = h>KB_RESOLUTION ? KB_RESOLUTION : h;
|
h = h>KB_RESOLUTION ? KB_RESOLUTION : h;
|
||||||
h = h<0 ? 0 : h;
|
h = h<0 ? 0 : h;
|
||||||
|
|
||||||
hid_buf[i + 1] = h;
|
hid_buf[i + 1] = h;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
|
|
||||||
|
|
||||||
t = std::chrono::steady_clock::now();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
|
||||||
|
|
||||||
// Dox.write might detect that we've been disconnected,
|
// Dox.write might detect that we've been disconnected,
|
||||||
// and Dox.read will fail if we are.
|
// and Dox.read will fail if we are.
|
||||||
// This check prevents it from doing that, and instead jumps to reconnect.
|
// This check prevents it from doing that, and instead jumps to reconnect.
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace misc {
|
|
||||||
size_t to_narrow(const wchar_t * src, char * dest, size_t dest_len) {
|
|
||||||
size_t i;
|
|
||||||
wchar_t code;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
while (src[i] != '\0' && i < (dest_len - 1)) {
|
|
||||||
code = src[i];
|
|
||||||
if (code < 128) {
|
|
||||||
dest[i] = char(code);
|
|
||||||
} else {
|
|
||||||
dest[i] = '?';
|
|
||||||
if (code >= 0xD800 && code <= 0xD8FF) {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
dest[i] = '\0';
|
|
||||||
return i - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
namespace misc {
|
|
||||||
size_t to_narrow(const wchar_t * src, char * dest, size_t dest_len);
|
|
||||||
}
|
|
Loading…
Reference in New Issue