First commit.
[temp2RGB.git] / src / a770.rs
1 // use windows::{
2 // core::w,
3 // Win32::{self, Storage::FileSystem},
4 // };
5 // use netcorehost::{nethost, pdcstr};
6
7 // pub fn set_rgb(r: u8, g: u8, b: u8) {
8 // unsafe {
9 // let lib = libloading::Library::new("IntelOCWrapper.dll").unwrap();
10
11 // let fun: libloading::Symbol<unsafe extern fn(u8, u8, u8, u8) -> bool> = lib.get(b"SetLEDColor").unwrap();
12 // let ctlInit: libloading::Symbol<unsafe extern fn(u32) -> std::ffi::c_void> = lib.get(b"ctlInit").unwrap();
13 // let ctlInit: libloading::Symbol<unsafe extern "C++" fn(u32) -> std::ffi::c_void> = lib.get(b"SetLEDColor").unwrap();
14 // println!("ok");
15 // }
16
17 // let hostfxr = nethost::load_hostfxr().unwrap();
18 // let context = hostfxr.initialize_for_dotnet_command_line(pdcstr!("IntelOCWrapper.dll")).unwrap();
19 // let result = context.run_app().value();
20
21 // unsafe {
22 // let handle = FileSystem::CreateFileW(
23 // // w!("\\\\.\\Intel_NF_I2C"),
24 // w!("\\\\.\\VIDEO\\INTC_I2C"),
25 // // w!("\\\\.\\WinRing0_1_2_0"),
26 // 3221225472,
27 // FileSystem::FILE_SHARE_MODE(0),
28 // None,
29 // FileSystem::FILE_CREATION_DISPOSITION(3),
30 // FileSystem::FILE_FLAGS_AND_ATTRIBUTES(1073741824),
31 // Win32::Foundation::HANDLE::default(),
32 // );
33
34 // println!("handle: {:?}", handle);
35 // }
36
37 //"\\\\.\\Intel_NF_I2C"
38 // }
39
40 // internal static \u0024ArrayType\u0024\u0024\u0024BY08E \u003FA0x171ed149\u002E\u003FprevData\u0040\u003F1\u003F\u003FSetLEDBehavior\u0040CVGAAdaptor\u0040\u0040UEAA_NEEEEEEEEE\u0040Z\u00404PAEA;
41 // public static __FnPtr<_ctl_result_t (_ctl_init_args_t*, _ctl_api_handle_t**)> __m2mep\u0040\u003FctlInit\u0040\u0040\u0024\u0024J0YA\u003FAW4_ctl_result_t\u0040\u0040PEAU_ctl_init_args_t\u0040\u0040PEAPEAU_ctl_api_handle_t\u0040\u0040\u0040Z;
42
43 use std::{
44 io::prelude::*,
45 net::TcpStream,
46 process::{Child, Command},
47 };
48
49 pub struct A770 {
50 process: Child,
51 stream: TcpStream,
52 }
53
54 impl A770 {
55 pub fn new() -> Self {
56 A770 {
57 process: Command::new(r"IntelOC.exe")
58 .spawn()
59 .expect("failed to execute process"),
60 stream: TcpStream::connect("127.0.0.1:6577").unwrap(),
61 }
62 }
63
64 pub fn set_color(&mut self, r: u8, g: u8, b: u8) {
65 let buffer: [u8; 3] = [r, g, b];
66 self.stream.write(&buffer).unwrap();
67 }
68 }
69
70 impl Drop for A770 {
71 fn drop(&mut self) {
72 self.process.kill().unwrap();
73 }
74 }