gamebridge: Twitch Control #2

Merged
cadey merged 29 commits from gamebridge into master 2020-05-11 22:40:05 +00:00
1 changed files with 15 additions and 14 deletions
Showing only changes of commit 70338a9b47 - Show all commits

View File

@ -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" {
match str {
"OK\n" => input.write(&controller_data)?,
"BYE" => {
warn!("asked to exit by the game"); warn!("asked to exit by the game");
return Ok(()); return Ok(());
},
_ => {
error!("got unknown FIFO data {}", str);
return Err(anyhow!("unknown FIFO data received"));
} }
demofile.read(&mut controller_data)?; };
input.write(&controller_data)?;
} }
} }