Add test program

This commit is contained in:
akiroz 2022-02-05 04:54:43 +08:00
parent 72545139b5
commit 93c464518e
No known key found for this signature in database
GPG Key ID: 8A5957C4A2F68ACC
3 changed files with 56 additions and 11 deletions

BIN
Tasoller Slider.dsl Normal file

Binary file not shown.

View File

@ -9,7 +9,8 @@ pub fn build(b: *std.build.Builder) void {
lib.setTarget(target);
lib.install();
// const exe = b.addExecutable("tasoller_test", "src/main.zig");
// exe.setTarget(target);
// exe.install();
const exe = b.addExecutable("tasoller_test", "src/main.zig");
lib.setBuildMode(b.standardReleaseOptions());
exe.setTarget(target);
exe.install();
}

View File

@ -40,6 +40,52 @@ const Config = struct {
coin_key: i32,
};
pub fn main() !void {
var ground = usb_out[4*3 .. 29*3];
var left = usb_out[32*3 .. 56*3];
var right = usb_out[56*3 .. 80*3];
var i: u32 = 0;
while(i < 32) : (i += 1) {
if(i < ground.len/3) {
ground[i*3 + 1] = 0x13;
ground[i*3 + 0] = 0x7a;
ground[i*3 + 2] = 0x5f;
if(i % 2 == 0) {
ground[i*3 + 1] = 0x66;
ground[i*3 + 0] = 0xee;
ground[i*3 + 2] = 0xab;
}
if(i % 4 == 0) {
ground[i*3 + 1] = 0xe1;
ground[i*3 + 0] = 0x28;
ground[i*3 + 2] = 0x85;
}
}
if(i < left.len/3) {
left[i*3 + 1] = 0x13;
left[i*3 + 0] = 0x7a;
left[i*3 + 2] = 0x5f;
}
if(i < right.len/3) {
right[i*3 + 1] = 0x13;
right[i*3 + 0] = 0x7a;
right[i*3 + 2] = 0x5f;
}
}
try tasoller_init();
while(true) {
if(WinUsb_WritePipe(tasoller, 0x03, @ptrCast(*u8, &usb_out), usb_out.len, &i, null) == 0) {
std.log.warn("[chuniio] WinUsb_WritePipe: {any}", .{GetLastError()});
}
if(WinUsb_ReadPipe(tasoller, 0x84, @ptrCast(*u8, &usb_in), usb_in.len, &i, null) == 0) {
std.log.warn("[chuniio] WinUsb_ReadPipe: {any}", .{GetLastError()});
}
std.time.sleep(100_000_000);
}
}
// MAIN DRIVER ======================================================================================================
var cfg: ?Config = null;
var thread_op = std.Thread.Mutex{};
var slider_active = false;
@ -128,11 +174,13 @@ fn input_thread_proc() void {
fn slider_thread_proc(callback: chuni_io_slider_callback_t) void {
var pressure = std.mem.zeroes([32]u8);
while(slider_active) {
// Tasoller order: top->bottom, left->right
// Chunithm order: top->bottom, right->left
for(usb_in[4..]) |val, i| pressure[if(i%2 == 0) 30-i else 32-i] = val;
for(usb_in[4..]) |byte, i| {
// Tasoller order: top->bottom, left->right
// Chunithm order: top->bottom, right->left
pressure[if(i%2 == 0) 30-i else 32-i] = byte;
}
callback.?(&pressure);
std.time.sleep(1_000_000); // 1ms
std.time.sleep(1_000_000); // 1ms, limit reporting to 1kHz max
}
}
@ -217,8 +265,4 @@ export fn chuni_io_slider_set_leds(rgb: ?[*]u8) void {
if(WinUsb_WritePipe(tasoller, 0x03, @ptrCast(*u8, &usb_out), usb_out.len, &n, null) == 0) {
std.log.warn("[chuniio] WinUsb_WritePipe: {any}", .{GetLastError()});
}
}
pub fn main() !void {
try tasoller_init();
}