diff --git a/Makefile b/Makefile index 46d6f13..258e4f1 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,16 @@ bench: cargo bench doc: - rm -rf doc + rm -rf docs rm -rf target/doc cargo doc --no-deps - cp -r target/doc . + mkdir -p docs + cp -r target/doc/* docs + echo "Adding index.html" + @echo "" > docs/index.html + @echo "" >> docs/index.html + @echo "" >> docs/index.html all: b15f test -.PHONY: all \ No newline at end of file +.PHONY: all diff --git a/doc/.lock b/doc/.lock deleted file mode 100644 index e69de29..0000000 diff --git a/doc/search-index.js b/doc/search-index.js deleted file mode 100644 index f8ad1b4..0000000 --- a/doc/search-index.js +++ /dev/null @@ -1,5 +0,0 @@ -var searchIndex = JSON.parse('{\ -"b15f":{"doc":"Driver code for the board 15","t":[2,0,14,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","digital_read","digital_write","discard","fmt","from","get_board_info","into","new","test_connection","test_int_conv","try_from","try_into","type_id","vzip"],"q":["b15f","","","b15f::b15f","","","","","","","","","","","","","","","",""],"d":["","This module contains all the structures and functions …","Builds a new request buffer from the given data","Structure representing the driver for the board 15","","","Reads the value of the specified port","Sets the value of the specified port","Clears data in the USART buffers on this device and on the …","","Returns the argument unchanged.","Yields information about the installed firmware on the B15","Calls U::from(self).","Creates a new instance of the B15","Tests the connetion to the B15","Test the integer conversion of the USART connection","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[1,[[3,[2,0]]]],[[1,2],[[3,[0]]]],[1,[[3,[0]]]],[[1,4],5],[[]],[1,[[3,[[7,[6]],0]]]],[[]],[[],[[3,[1,0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[[],3],[[],3],[[],8],[[]]],"p":[[3,"B15F"],[15,"u8"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\ -}'); -if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)}; -if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; diff --git a/doc/COPYRIGHT.txt b/docs/COPYRIGHT.txt similarity index 100% rename from doc/COPYRIGHT.txt rename to docs/COPYRIGHT.txt diff --git a/doc/FiraSans-LICENSE.txt b/docs/FiraSans-LICENSE.txt similarity index 100% rename from doc/FiraSans-LICENSE.txt rename to docs/FiraSans-LICENSE.txt diff --git a/doc/FiraSans-Medium.woff2 b/docs/FiraSans-Medium.woff2 similarity index 100% rename from doc/FiraSans-Medium.woff2 rename to docs/FiraSans-Medium.woff2 diff --git a/doc/FiraSans-Regular.woff2 b/docs/FiraSans-Regular.woff2 similarity index 100% rename from doc/FiraSans-Regular.woff2 rename to docs/FiraSans-Regular.woff2 diff --git a/doc/LICENSE-APACHE.txt b/docs/LICENSE-APACHE.txt similarity index 100% rename from doc/LICENSE-APACHE.txt rename to docs/LICENSE-APACHE.txt diff --git a/doc/LICENSE-MIT.txt b/docs/LICENSE-MIT.txt similarity index 100% rename from doc/LICENSE-MIT.txt rename to docs/LICENSE-MIT.txt diff --git a/doc/NanumBarunGothic-LICENSE.txt b/docs/NanumBarunGothic-LICENSE.txt similarity index 100% rename from doc/NanumBarunGothic-LICENSE.txt rename to docs/NanumBarunGothic-LICENSE.txt diff --git a/doc/NanumBarunGothic.ttf.woff2 b/docs/NanumBarunGothic.ttf.woff2 similarity index 100% rename from doc/NanumBarunGothic.ttf.woff2 rename to docs/NanumBarunGothic.ttf.woff2 diff --git a/doc/SourceCodePro-It.ttf.woff2 b/docs/SourceCodePro-It.ttf.woff2 similarity index 100% rename from doc/SourceCodePro-It.ttf.woff2 rename to docs/SourceCodePro-It.ttf.woff2 diff --git a/doc/SourceCodePro-LICENSE.txt b/docs/SourceCodePro-LICENSE.txt similarity index 100% rename from doc/SourceCodePro-LICENSE.txt rename to docs/SourceCodePro-LICENSE.txt diff --git a/doc/SourceCodePro-Regular.ttf.woff2 b/docs/SourceCodePro-Regular.ttf.woff2 similarity index 100% rename from doc/SourceCodePro-Regular.ttf.woff2 rename to docs/SourceCodePro-Regular.ttf.woff2 diff --git a/doc/SourceCodePro-Semibold.ttf.woff2 b/docs/SourceCodePro-Semibold.ttf.woff2 similarity index 100% rename from doc/SourceCodePro-Semibold.ttf.woff2 rename to docs/SourceCodePro-Semibold.ttf.woff2 diff --git a/doc/SourceSerif4-Bold.ttf.woff2 b/docs/SourceSerif4-Bold.ttf.woff2 similarity index 100% rename from doc/SourceSerif4-Bold.ttf.woff2 rename to docs/SourceSerif4-Bold.ttf.woff2 diff --git a/doc/SourceSerif4-It.ttf.woff2 b/docs/SourceSerif4-It.ttf.woff2 similarity index 100% rename from doc/SourceSerif4-It.ttf.woff2 rename to docs/SourceSerif4-It.ttf.woff2 diff --git a/doc/SourceSerif4-LICENSE.md b/docs/SourceSerif4-LICENSE.md similarity index 100% rename from doc/SourceSerif4-LICENSE.md rename to docs/SourceSerif4-LICENSE.md diff --git a/doc/SourceSerif4-Regular.ttf.woff2 b/docs/SourceSerif4-Regular.ttf.woff2 similarity index 100% rename from doc/SourceSerif4-Regular.ttf.woff2 rename to docs/SourceSerif4-Regular.ttf.woff2 diff --git a/doc/ayu.css b/docs/ayu.css similarity index 100% rename from doc/ayu.css rename to docs/ayu.css diff --git a/doc/b15f/all.html b/docs/b15f/all.html similarity index 100% rename from doc/b15f/all.html rename to docs/b15f/all.html diff --git a/doc/b15f/b15f/index.html b/docs/b15f/b15f/index.html similarity index 98% rename from doc/b15f/b15f/index.html rename to docs/b15f/b15f/index.html index 970e2d0..64ab8ea 100644 --- a/doc/b15f/b15f/index.html +++ b/docs/b15f/b15f/index.html @@ -1,4 +1,4 @@ -b15f::b15f - Rust

Module b15f::b15f

source · []
Expand description

This module contains all the structures and functions related to +b15f::b15f - Rust

Module b15f::b15f

source · []
Expand description

This module contains all the structures and functions related to interacting with the B15 on a high level. If you are writing code for the B15, this is the module you want to use.

Structs

Structure representing the driver for the board 15
\ No newline at end of file diff --git a/doc/b15f/b15f/sidebar-items.js b/docs/b15f/b15f/sidebar-items.js similarity index 100% rename from doc/b15f/b15f/sidebar-items.js rename to docs/b15f/b15f/sidebar-items.js diff --git a/doc/b15f/b15f/struct.B15F.html b/docs/b15f/b15f/struct.B15F.html similarity index 82% rename from doc/b15f/b15f/struct.B15F.html rename to docs/b15f/b15f/struct.B15F.html index 895d93e..01f005e 100644 --- a/doc/b15f/b15f/struct.B15F.html +++ b/docs/b15f/b15f/struct.B15F.html @@ -1,5 +1,5 @@ -B15F in b15f::b15f - Rust
pub struct B15F { /* private fields */ }
Expand description

Structure representing the driver for the board 15

-

Implementations

Creates a new instance of the B15

+B15F in b15f::b15f - Rust
pub struct B15F { /* private fields */ }
Expand description

Structure representing the driver for the board 15

+

Implementations

Creates a new instance of the B15

This function will establish a connection to a connected B15 and return a handle to interact with it. Only one such instance should exist per program; calling B15F::new() more than once might lead to unexpected @@ -14,8 +14,15 @@ established, or if testing of that connection fails.

use b15f::B15F;
  
 let drv = B15F::new().unwrap();
-

Sets the value of the specified port

+

Tries to reestablish a connection to the B15

+

Enables the self test mode of the B15

+

IMPORTANT: Nothing must be connected to the B15 during this self check +routine.

Errors
+

This function returns an error::Error when communication with +the board or the self check fails.

+

Sets the value of the specified port

+
Errors

PORT can either be 0 or 1, other values will cause a compile-time error. Otherwise an error::Error is generated if communication with the B15 fails.

@@ -32,8 +39,8 @@ with the B15 fails.

Ok(()) }
-

Reads the value of the specified port

-
Errors
+

Reads the value of the specified port

+
Errors

PORT can either be 0 or 1, other values will cause a compile-time error. Otherwise an error::Error is generated if communication with the B15 fails.

@@ -50,14 +57,30 @@ with the B15 fails.

Ok(()) }
-

Yields information about the installed firmware on the B15

+

Reads the value of the DIP switch (S7)

+
Returns
+

A bitfield representing the value of all 8 DIP switches. The least +significant bit represents switch 1.

+
Errors
+

When communication with the board fails an error::Error is returned.

+
Example
+
use b15f::B15F;
+ 
+fn main() -> Result<(), String> {
+	let mut drv = B15F::new()?;
+ 
+	println!("{}", drv.read_dip_switch()?);
+ 
+	Ok(())
+}
+

Yields information about the installed firmware on the B15

Returns an array of strings, where each string contains a piece of information stored on the B15

-
Returns
+
Returns

A list of strings where each string contains a piece of information about the board. What string contains what information is determined, but not explicitly listed.

-
Errors
+
Errors

An error::Error is generated if the communication with the board fails.

Examples
use b15f::B15F;
@@ -69,16 +92,16 @@ but not explicitly listed.

.unwrap() .iter() .for_each(|info| println!("{info}"));
-

Clears data in the USART buffers on this device and on the B15

-

Test the integer conversion of the USART connection

-
Errors
+

Clears data in the USART buffers on this device and on the B15

+

Test the integer conversion of the USART connection

+
Errors

If an error occurs in the conversion or the communication with the board, an error::Error will be returned.

-

Tests the connetion to the B15

+

Tests the connetion to the B15

To test the connection a Request::Test request will be sent to the board together with a randomly generated value. If the board returns that value the connection is working correctly.

-
Errors
+
Errors

An error::Error is returned if the test fails, or if the communication itself fails.

Examples
@@ -91,7 +114,7 @@ communication itself fails.

panic!("Connection is not working: {err}"); } }
-

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

+

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

diff --git a/doc/b15f/index.html b/docs/b15f/index.html similarity index 100% rename from doc/b15f/index.html rename to docs/b15f/index.html diff --git a/doc/b15f/macro.build_request!.html b/docs/b15f/macro.build_request!.html similarity index 100% rename from doc/b15f/macro.build_request!.html rename to docs/b15f/macro.build_request!.html diff --git a/doc/b15f/macro.build_request.html b/docs/b15f/macro.build_request.html similarity index 100% rename from doc/b15f/macro.build_request.html rename to docs/b15f/macro.build_request.html diff --git a/doc/b15f/sidebar-items.js b/docs/b15f/sidebar-items.js similarity index 100% rename from doc/b15f/sidebar-items.js rename to docs/b15f/sidebar-items.js diff --git a/doc/clipboard.svg b/docs/clipboard.svg similarity index 100% rename from doc/clipboard.svg rename to docs/clipboard.svg diff --git a/doc/crates.js b/docs/crates.js similarity index 100% rename from doc/crates.js rename to docs/crates.js diff --git a/doc/dark.css b/docs/dark.css similarity index 100% rename from doc/dark.css rename to docs/dark.css diff --git a/doc/down-arrow.svg b/docs/down-arrow.svg similarity index 100% rename from doc/down-arrow.svg rename to docs/down-arrow.svg diff --git a/doc/favicon-16x16.png b/docs/favicon-16x16.png similarity index 100% rename from doc/favicon-16x16.png rename to docs/favicon-16x16.png diff --git a/doc/favicon-32x32.png b/docs/favicon-32x32.png similarity index 100% rename from doc/favicon-32x32.png rename to docs/favicon-32x32.png diff --git a/doc/favicon.svg b/docs/favicon.svg similarity index 100% rename from doc/favicon.svg rename to docs/favicon.svg diff --git a/doc/help.html b/docs/help.html similarity index 100% rename from doc/help.html rename to docs/help.html diff --git a/doc/implementors/core/fmt/trait.Debug.js b/docs/implementors/core/fmt/trait.Debug.js similarity index 100% rename from doc/implementors/core/fmt/trait.Debug.js rename to docs/implementors/core/fmt/trait.Debug.js diff --git a/doc/implementors/core/marker/trait.Freeze.js b/docs/implementors/core/marker/trait.Freeze.js similarity index 100% rename from doc/implementors/core/marker/trait.Freeze.js rename to docs/implementors/core/marker/trait.Freeze.js diff --git a/doc/implementors/core/marker/trait.Send.js b/docs/implementors/core/marker/trait.Send.js similarity index 100% rename from doc/implementors/core/marker/trait.Send.js rename to docs/implementors/core/marker/trait.Send.js diff --git a/doc/implementors/core/marker/trait.Sync.js b/docs/implementors/core/marker/trait.Sync.js similarity index 100% rename from doc/implementors/core/marker/trait.Sync.js rename to docs/implementors/core/marker/trait.Sync.js diff --git a/doc/implementors/core/marker/trait.Unpin.js b/docs/implementors/core/marker/trait.Unpin.js similarity index 100% rename from doc/implementors/core/marker/trait.Unpin.js rename to docs/implementors/core/marker/trait.Unpin.js diff --git a/doc/implementors/core/panic/unwind_safe/trait.RefUnwindSafe.js b/docs/implementors/core/panic/unwind_safe/trait.RefUnwindSafe.js similarity index 100% rename from doc/implementors/core/panic/unwind_safe/trait.RefUnwindSafe.js rename to docs/implementors/core/panic/unwind_safe/trait.RefUnwindSafe.js diff --git a/doc/implementors/core/panic/unwind_safe/trait.UnwindSafe.js b/docs/implementors/core/panic/unwind_safe/trait.UnwindSafe.js similarity index 100% rename from doc/implementors/core/panic/unwind_safe/trait.UnwindSafe.js rename to docs/implementors/core/panic/unwind_safe/trait.UnwindSafe.js diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..ea8244e --- /dev/null +++ b/docs/index.html @@ -0,0 +1,3 @@ + + + diff --git a/doc/light.css b/docs/light.css similarity index 100% rename from doc/light.css rename to docs/light.css diff --git a/doc/main.js b/docs/main.js similarity index 100% rename from doc/main.js rename to docs/main.js diff --git a/doc/normalize.css b/docs/normalize.css similarity index 100% rename from doc/normalize.css rename to docs/normalize.css diff --git a/doc/noscript.css b/docs/noscript.css similarity index 100% rename from doc/noscript.css rename to docs/noscript.css diff --git a/doc/rust-logo.svg b/docs/rust-logo.svg similarity index 100% rename from doc/rust-logo.svg rename to docs/rust-logo.svg diff --git a/doc/rustdoc.css b/docs/rustdoc.css similarity index 100% rename from doc/rustdoc.css rename to docs/rustdoc.css diff --git a/docs/search-index.js b/docs/search-index.js new file mode 100644 index 0000000..b88f7e2 --- /dev/null +++ b/docs/search-index.js @@ -0,0 +1,5 @@ +var searchIndex = JSON.parse('{\ +"b15f":{"doc":"Driver code for the board 15","t":[2,0,14,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","digital_read","digital_write","discard","fmt","from","get_board_info","into","new","read_dip_switch","reconnect","self_test","test_connection","test_int_conv","try_from","try_into","type_id","vzip"],"q":["b15f","","","b15f::b15f","","","","","","","","","","","","","","","","","","",""],"d":["","This module contains all the structures and functions …","Builds a new request buffer from the given data","Structure representing the driver for the board 15","","","Reads the value of the specified port","Sets the value of the specified port","Clears data in the USART buffers on this device and on the …","","Returns the argument unchanged.","Yields information about the installed firmware on the B15","Calls U::from(self).","Creates a new instance of the B15","Reads the value of the DIP switch (S7)","Tries to reestablish a connection to the B15","Enables the self test mode of the B15","Tests the connetion to the B15","Test the integer conversion of the USART connection","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[1,[[3,[2,0]]]],[[1,2],[[3,[0]]]],[1,[[3,[0]]]],[[1,4],5],[[]],[1,[[3,[[7,[6]],0]]]],[[]],[[],[[3,[1,0]]]],[1,[[3,[2,0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[[],3],[[],3],[[],8],[[]]],"p":[[3,"B15F"],[15,"u8"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\ +}'); +if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)}; +if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; diff --git a/doc/search.js b/docs/search.js similarity index 100% rename from doc/search.js rename to docs/search.js diff --git a/doc/settings.css b/docs/settings.css similarity index 100% rename from doc/settings.css rename to docs/settings.css diff --git a/doc/settings.html b/docs/settings.html similarity index 100% rename from doc/settings.html rename to docs/settings.html diff --git a/doc/settings.js b/docs/settings.js similarity index 100% rename from doc/settings.js rename to docs/settings.js diff --git a/doc/source-files.js b/docs/source-files.js similarity index 86% rename from doc/source-files.js rename to docs/source-files.js index b008575..b04802a 100644 --- a/doc/source-files.js +++ b/docs/source-files.js @@ -1,4 +1,4 @@ var sourcesIndex = JSON.parse('{\ -"b15f":["",[],["assert.rs","b15f.rs","error.rs","lib.rs","request.rs"]]\ +"b15f":["",[],["assert.rs","b15f.rs","error.rs","lib.rs","request.rs","usart.rs"]]\ }'); createSourceSidebar(); diff --git a/doc/source-script.js b/docs/source-script.js similarity index 100% rename from doc/source-script.js rename to docs/source-script.js diff --git a/doc/src/b15f/assert.rs.html b/docs/src/b15f/assert.rs.html similarity index 100% rename from doc/src/b15f/assert.rs.html rename to docs/src/b15f/assert.rs.html diff --git a/doc/src/b15f/b15f.rs.html b/docs/src/b15f/b15f.rs.html similarity index 84% rename from doc/src/b15f/b15f.rs.html rename to docs/src/b15f/b15f.rs.html index 173dca6..79a391c 100644 --- a/doc/src/b15f/b15f.rs.html +++ b/docs/src/b15f/b15f.rs.html @@ -372,6 +372,64 @@ 372 373 374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432
//! This module contains all the structures and functions related to
 //! interacting with the B15 on a high level. If you are writing code
 //! for the B15, this is the module you want to use.
@@ -380,7 +438,7 @@
 use rand::Rng;
 use serialport::SerialPort;
 
-use crate::{assert::assert_in_range, error::Error, request::Request, build_request};
+use crate::{assert::assert_in_range, error::Error, request::Request, usart::read_sized, build_request};
 
 macro_rules! log {
 	($text: literal, $($arg:tt)*) => (println!(concat!("[B15F] ", $text), $($arg)*));
@@ -489,6 +547,42 @@
 		Ok(port)
 	}
 
+	/// Tries to reestablish a connection to the B15
+	pub fn reconnect(&mut self) -> Result<(), Error> {
+		let tries = 3;
+		while tries > 0 {
+			sleep(Duration::from_millis(64));
+			self.discard()?;
+
+			match self.test_connection() {
+				Ok(_) => return Ok(()),
+				Err(_) => { }
+			};
+
+		}
+
+		Err("Connection could not be repaired".into())		
+	}
+
+	/// Enables the self test mode of the B15
+	/// 
+	/// IMPORTANT: Nothing must be connected to the B15 during this self check
+	/// routine.
+	/// 
+	/// # Errors 
+	/// This function returns an `error::Error` when communication with
+	/// the board or the self check fails.
+	pub fn self_test(&mut self) -> Result<(), Error> {
+		self.usart.write(build_request!(Request::SelfTest))?;
+
+		let aw = read_sized::<1>(&mut self.usart)?;
+		if aw[0] != B15F::MSG_OK {
+			return Err("Self test failed".into())
+		}
+
+		Ok(())
+	}
+
 	/// Sets the value of the specified port
 	///
 	/// # Errors 
@@ -524,9 +618,7 @@
 		
 		self.usart.write(build_request![request, reversed])?;
 
-		let mut aw: [u8; 1] = [0; 1];
-		self.usart.read(&mut aw)?;
-
+		let aw = read_sized::<1>(&mut self.usart)?;
 		if aw[0] != B15F::MSG_OK {
 			return Err(format!("Setting Port {} failed", PORT).into());
 		}
@@ -569,12 +661,39 @@
 		self.usart.clear(serialport::ClearBuffer::Input)?;
 		self.usart.write(build_request![request])?;
 
-		let mut aw: [u8; 1] = [0; 1];
-		self.usart.read(&mut aw)?;
-
+		let aw = read_sized::<1>(&mut self.usart)?;
 		Ok(u8::reverse_bits(aw[0]))
 	}
 
+	/// Reads the value  of the DIP switch (S7)
+	/// 
+	/// # Returns
+	/// A bitfield representing the value of all 8 DIP switches. The least
+	/// significant bit represents switch 1.
+	/// 
+	/// # Errors
+	/// When communication with the board fails an `error::Error` is returned.
+	/// 
+	/// # Example
+	/// ```
+	/// use b15f::B15F;
+	/// 
+	/// fn main() -> Result<(), String> {
+	/// 	let mut drv = B15F::new()?;
+	/// 
+	/// 	println!("{}", drv.read_dip_switch()?);
+	/// 
+	/// 	Ok(())
+	/// }
+	/// ```
+	pub fn read_dip_switch(&mut self) -> Result<u8, Error> {
+		self.usart.clear(serialport::ClearBuffer::Input)?;
+		self.usart.write(build_request!(Request::ReadDipSwitch))?;
+		
+		let aw = read_sized::<1>(&mut self.usart)?;
+		Ok(aw[0].reverse_bits())
+	}
+
 	/// Yields information about the installed firmware on the B15
 	/// 
 	/// Returns an array of strings, where each string contains a piece
@@ -625,9 +744,7 @@
 			data_count[0] -= 1;
 		}
 
-		let mut aw: [u8; 1] = [0; 1];		
-		self.usart.read(&mut aw)?;		
-
+		let aw = read_sized::<1>(&mut self.usart)?;
 		if aw[0] != B15F::MSG_OK {
 			return Err(format!("Board info is faulty: code {}", aw[0]).into());
 		}		
@@ -659,9 +776,8 @@
 		
 		self.usart.write(build_request!(Request::IntTest, dummy & 0xFF, dummy >> 8))?;
 
-		let mut aw: [u8; 2] = [0; 2];
-		self.usart.read(&mut aw)?;
-
+		let aw = read_sized::<2>(&mut self.usart)?;
+		
 		let result = u16::from_le_bytes(aw);
 		if result != dummy * 3 {
 			return Err("Int conversion failed".into());
diff --git a/doc/src/b15f/error.rs.html b/docs/src/b15f/error.rs.html
similarity index 100%
rename from doc/src/b15f/error.rs.html
rename to docs/src/b15f/error.rs.html
diff --git a/doc/src/b15f/lib.rs.html b/docs/src/b15f/lib.rs.html
similarity index 99%
rename from doc/src/b15f/lib.rs.html
rename to docs/src/b15f/lib.rs.html
index 7dc4593..9481665 100644
--- a/doc/src/b15f/lib.rs.html
+++ b/docs/src/b15f/lib.rs.html
@@ -22,7 +22,6 @@
 
#![deny(missing_docs,
     missing_debug_implementations,
     trivial_casts,
-    unsafe_code,
     unstable_features,
     unused_import_braces, unused_qualifications)]
 
@@ -35,6 +34,7 @@
 //! [`original`]: https://github.com/devfix/b15f
 
 pub mod b15f;
+mod usart;
 mod request;
 mod error;
 mod assert;
diff --git a/doc/src/b15f/request.rs.html b/docs/src/b15f/request.rs.html
similarity index 96%
rename from doc/src/b15f/request.rs.html
rename to docs/src/b15f/request.rs.html
index cd90f5c..543b3ea 100644
--- a/doc/src/b15f/request.rs.html
+++ b/docs/src/b15f/request.rs.html
@@ -27,6 +27,7 @@
 27
 28
 29
+30
 
//! This module contains the request data used to communicate
 //! with the B15 via USART. 
 //! 
@@ -50,10 +51,11 @@
 	Test 			= 1,
 	Info 			= 2,
 	IntTest			= 3,
-
+	SelfTest		= 4,
 	DigitalWrite0 	= 5,
 	DigitalWrite1 	= 6,
 	DigitalRead0	= 7,
-	DigitalRead1	= 8
+	DigitalRead1	= 8,
+	ReadDipSwitch	= 9
 }
\ No newline at end of file diff --git a/docs/src/b15f/usart.rs.html b/docs/src/b15f/usart.rs.html new file mode 100644 index 0000000..a7b3d38 --- /dev/null +++ b/docs/src/b15f/usart.rs.html @@ -0,0 +1,19 @@ +usart.rs - source
1
+2
+3
+4
+5
+6
+7
+8
+9
+
use serialport::SerialPort;
+use crate::error::Error;
+
+pub fn read_sized<const N: usize> (usart: &mut Box<dyn SerialPort>) -> Result<[u8; N], Error> {
+	let mut buf: [u8; N] = [0; N];
+	
+	usart.read(&mut buf)?;
+	Ok(buf)
+}
+
\ No newline at end of file diff --git a/doc/storage.js b/docs/storage.js similarity index 100% rename from doc/storage.js rename to docs/storage.js diff --git a/doc/toggle-minus.svg b/docs/toggle-minus.svg similarity index 100% rename from doc/toggle-minus.svg rename to docs/toggle-minus.svg diff --git a/doc/toggle-plus.svg b/docs/toggle-plus.svg similarity index 100% rename from doc/toggle-plus.svg rename to docs/toggle-plus.svg diff --git a/doc/wheel.svg b/docs/wheel.svg similarity index 100% rename from doc/wheel.svg rename to docs/wheel.svg