-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = ["copper", "copper_derive", "copper_derive_test", "examples/pluginload", "examples/v4lsrc"] | ||
members = ["copper", "copper_derive", "copper_derive_test", "examples/pluginload", "examples/simplelogger", "examples/v4lsrc"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "simplelogger" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
copper = { path = "../../copper" } | ||
v4lsrc = { path = "../v4lsrc" } | ||
serde = { version = "1.0.202", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use copper::config::NodeConfig; | ||
use copper::cutask::{CuResult, CuSinkTask}; | ||
use v4lsrc::ImageMsg; | ||
|
||
struct SimpleLogger { | ||
path: String, | ||
log_file: Option<File>, | ||
} | ||
|
||
impl CuSinkTask for SimpleLogger { | ||
type Input = ImageMsg; | ||
|
||
fn new(config: NodeConfig) -> CuResult<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
let path = (*config.get("path").unwrap()).clone().into(); | ||
Ok(SimpleLogger { | ||
path, | ||
log_file: None, | ||
}) | ||
} | ||
|
||
fn start(&mut self) -> CuResult<()> { | ||
let log_file = File::create(&self.path).unwrap(); | ||
self.log_file = Some(log_file); | ||
Ok(()) | ||
} | ||
|
||
fn stop(&mut self) -> CuResult<()> { | ||
Ok(()) | ||
} | ||
|
||
fn process(&mut self, input: &Self::Input) -> CuResult<()> { | ||
let log_file = self.log_file.as_mut().unwrap(); | ||
for line in input.buffer.iter() { | ||
log_file.write_all(line).unwrap(); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
// ignore this test because it requires a camera to be connected to the computer | ||
// it is still runnable if specifically called with `cargo test emulate_runtime` | ||
#[ignore] | ||
#[test] | ||
fn emulate_runtime() -> CuResult<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "camreader" | ||
name = "v4lsrc" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters