gamebridge: Twitch Control #2
|
@ -1,22 +1,17 @@
|
||||||
use log::{debug, info, warn};
|
use anyhow::{anyhow, Result};
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
str::from_utf8,
|
str::from_utf8,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> Result<()> {
|
||||||
pretty_env_logger::try_init()?;
|
pretty_env_logger::try_init()?;
|
||||||
let mut controller_data = [0; 4];
|
let mut controller_data = [0; 4];
|
||||||
|
|
||||||
let mut vblank = File::open("vblank")?;
|
let mut vblank = File::open("vblank")?;
|
||||||
let mut input = OpenOptions::new().write(true).open("input")?;
|
let mut input = OpenOptions::new().write(true).open("input")?;
|
||||||
let mut demofile = File::open("demo.m64")?;
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut buf = [0; 1024];
|
|
||||||
demofile.read(&mut buf)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("ready");
|
info!("ready");
|
||||||
|
|
||||||
|
@ -26,11 +21,17 @@ fn main() -> anyhow::Result<()> {
|
||||||
vblank.read(&mut data)?;
|
vblank.read(&mut data)?;
|
||||||
let str = from_utf8(&data)?;
|
let str = from_utf8(&data)?;
|
||||||
debug!("got data: {}", str);
|
debug!("got data: {}", str);
|
||||||
if str == "BYE" {
|
|
||||||
warn!("asked to exit by the game");
|
match str {
|
||||||
return Ok(());
|
"OK\n" => input.write(&controller_data)?,
|
||||||
}
|
"BYE" => {
|
||||||
demofile.read(&mut controller_data)?;
|
warn!("asked to exit by the game");
|
||||||
input.write(&controller_data)?;
|
return Ok(());
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
error!("got unknown FIFO data {}", str);
|
||||||
|
return Err(anyhow!("unknown FIFO data received"));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue