Skip to content

Commit

Permalink
feat: finished serial?
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueGlassBlock committed Jan 4, 2024
1 parent 4343515 commit d1dbbfd
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build and Upload Artifacts

on:
push:

jobs:
build:
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Make Dist Directory
shell: powershell
run: |
mkdir dist
- name: Build - Mercury API v1
shell: powershell
run: |
$env:MERCURY_IO_API_VERSION = 1
cargo build
cargo build --release
cp target/debug/toucca.dll dist/toucca-debug-v1.dll
cp target/release/toucca.dll dist/toucca-release-v1.dll
- name: Upload v1 artifacts
uses: actions/upload-artifact@v4
with:
name: API v1
path: |
target/release/toucca.*
target/debug/toucca.*
- name: Build Debug - Mercury API v256
shell: powershell
run: |
$env:MERCURY_IO_API_VERSION = 256
cargo build
cargo build --release
cp target/debug/toucca.dll dist/toucca-debug-v256.dll
cp target/release/toucca.dll dist/toucca-release-v256.dll
- name: Upload v256 artifacts
uses: actions/upload-artifact@v4
with:
name: API v256
path: |
target/release/toucca.*
target/debug/toucca.*
- name: Upload Dist Directory
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/**/*
4 changes: 2 additions & 2 deletions toucca-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct TouccaConfig {
}

impl TouccaTouchConfig {
pub unsafe fn load(filename: &HSTRING) -> Self {
pub(crate) unsafe fn load(filename: &HSTRING) -> Self {
let divisions = GetPrivateProfileIntW(h!("touch"), h!("divisions"), 8, filename) as usize;
if !(4..=20).contains(&divisions) {
panic!("Invalid touch divisions");
Expand Down Expand Up @@ -183,7 +183,7 @@ impl TouccaTouchConfig {
}

impl TouccaConfig {
pub unsafe fn load(filename: &HSTRING) -> Self {
pub(crate) unsafe fn load(filename: &HSTRING) -> Self {
let mut cells = [0; 240];
for i in 0..240 {
cells[i] = GetPrivateProfileIntW(
Expand Down
11 changes: 5 additions & 6 deletions toucca-lib/src/serial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct TouccaState {
hwnd: Option<HWND>,
}

// FIXME: the cell mapping reversed in L-R, and serial isn't working until serial test (expecting touch pack on init?)
// FIXME: section is sometimes off

impl TouccaState {
#[instrument]
Expand All @@ -36,7 +36,7 @@ impl TouccaState {
.expect("Failed to open COM6");
info!("Opened serial ports");
Self {
ports: [com_l, com_r],
ports: [com_r, com_l],
startup_complete: false,
touch_areas: Default::default(),
hwnd: None,
Expand All @@ -61,7 +61,7 @@ impl TouccaState {
constant::NEXT_READ => {
debug!("NEXT_READ");
let mut buf: Option<Vec<u8>> = None;
match data.get(2).unwrap_or(&0) {
match data.get(3).unwrap_or(&0) {
0x30 => {
debug!("READ_1");
buf = Some(constant::READ_1.as_bytes().into());
Expand Down Expand Up @@ -111,7 +111,6 @@ impl TouccaState {
debug!("START_AUTO_SCAN");
startup_complete = Some(true);
resp_data = Some(constant::DATA_201.into());
// "start touch thread"
}
constant::BEGIN_WRITE => debug!("BEGIN_WRITE"),
constant::NEXT_WRITE => debug!("NEXT_WRITE"),
Expand All @@ -131,7 +130,7 @@ impl TouccaState {
continue;
}
let mut buf = vec![0; to_read];
port.read(&mut buf)?;
port.read_exact(&mut buf)?;
let (startup_complete, resp) = Self::make_resp(side, &buf);
if let Some(startup_complete) = startup_complete {
if self.startup_complete != startup_complete {
Expand Down Expand Up @@ -196,4 +195,4 @@ impl TouccaState {
pub fn start_serial() -> JoinHandle<()> {
let mut state = TouccaState::new();
std::thread::spawn(move || unsafe { state.cycle() })
}
}
2 changes: 1 addition & 1 deletion toucca-lib/src/serial/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn prepare(mut pack: Pack) -> Pack {
pack[0] = 129;
pack[34] += 1;
pack[35] = 128;
pack[35] = super::pack::checksum(&pack);
pack[35] = checksum(&pack);
if pack[34] > 127 {
pack[34] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion toucca-lib/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn get_window_handle(proc_id: u32) -> Option<HWND> {
if let Some(hwnd) = hwnd {
debug!("Get window handle of {}: {:?}", proc_id, hwnd);
}
return hwnd;
hwnd
}
}

Expand Down
4 changes: 2 additions & 2 deletions toucca/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static mut TRACING_INIT: bool = false;
#[no_mangle]
pub extern "system" fn mercury_io_get_api_version() -> u16 {
unsafe {
if TRACING_INIT == false {
if !TRACING_INIT {
log::init_log();
TRACING_INIT = true;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ static mut _HWND: HWND = HWND(0);
#[no_mangle]
pub extern "system" fn mercury_io_touch_init() -> HRESULT {
unsafe {
if _TOUCH_INIT == false {
if !_TOUCH_INIT {
let proc_id = GetCurrentProcessId();
if let Some(handle) = get_window_handle(proc_id) {
_HWND = handle;
Expand Down

0 comments on commit d1dbbfd

Please sign in to comment.