add digitalWrite functions
This commit is contained in:
parent
5e27c5f359
commit
b284e2ebab
|
@ -1,4 +1,4 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="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."><meta name="keywords" content="rust, rustlang, rust-lang, b15f"><title>b15f::b15f - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Module b15f</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">b15f</a>::<wbr><a class="mod" href="#">b15f</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/b15f/b15f.rs.html#1-243">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This module contains all the structures and functions related to
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="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."><meta name="keywords" content="rust, rustlang, rust-lang, b15f"><title>b15f::b15f - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../b15f/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Module b15f</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">b15f</a>::<wbr><a class="mod" href="#">b15f</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/b15f/b15f.rs.html#1-316">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>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.</p>
|
||||
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.B15F.html" title="b15f::b15f::B15F struct">B15F</a></div><div class="item-right docblock-short">Structure representing the driver for the board 15</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="b15f" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0 (69f9c33d7 2022-12-12)" ></div></body></html>
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +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],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","discard","fmt","from","get_board_info","into","new","test_connection","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","","","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 <code>U::from(self)</code>.","Creates a new instance of the B15","Tests the connetion to the B15","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[1,[[2,[0]]]],[[1,3],4],[[]],[1,[[2,[[6,[5]],0]]]],[[]],[[],[[2,[1,0]]]],[1,[[2,[0]]]],[[],2],[[],2],[[],7],[[]]],"p":[[3,"B15F"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\
|
||||
"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],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","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","","","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 <code>U::from(self)</code>.","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],"f":[0,0,0,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};
|
||||
|
|
|
@ -241,6 +241,79 @@
|
|||
<span id="241">241</span>
|
||||
<span id="242">242</span>
|
||||
<span id="243">243</span>
|
||||
<span id="244">244</span>
|
||||
<span id="245">245</span>
|
||||
<span id="246">246</span>
|
||||
<span id="247">247</span>
|
||||
<span id="248">248</span>
|
||||
<span id="249">249</span>
|
||||
<span id="250">250</span>
|
||||
<span id="251">251</span>
|
||||
<span id="252">252</span>
|
||||
<span id="253">253</span>
|
||||
<span id="254">254</span>
|
||||
<span id="255">255</span>
|
||||
<span id="256">256</span>
|
||||
<span id="257">257</span>
|
||||
<span id="258">258</span>
|
||||
<span id="259">259</span>
|
||||
<span id="260">260</span>
|
||||
<span id="261">261</span>
|
||||
<span id="262">262</span>
|
||||
<span id="263">263</span>
|
||||
<span id="264">264</span>
|
||||
<span id="265">265</span>
|
||||
<span id="266">266</span>
|
||||
<span id="267">267</span>
|
||||
<span id="268">268</span>
|
||||
<span id="269">269</span>
|
||||
<span id="270">270</span>
|
||||
<span id="271">271</span>
|
||||
<span id="272">272</span>
|
||||
<span id="273">273</span>
|
||||
<span id="274">274</span>
|
||||
<span id="275">275</span>
|
||||
<span id="276">276</span>
|
||||
<span id="277">277</span>
|
||||
<span id="278">278</span>
|
||||
<span id="279">279</span>
|
||||
<span id="280">280</span>
|
||||
<span id="281">281</span>
|
||||
<span id="282">282</span>
|
||||
<span id="283">283</span>
|
||||
<span id="284">284</span>
|
||||
<span id="285">285</span>
|
||||
<span id="286">286</span>
|
||||
<span id="287">287</span>
|
||||
<span id="288">288</span>
|
||||
<span id="289">289</span>
|
||||
<span id="290">290</span>
|
||||
<span id="291">291</span>
|
||||
<span id="292">292</span>
|
||||
<span id="293">293</span>
|
||||
<span id="294">294</span>
|
||||
<span id="295">295</span>
|
||||
<span id="296">296</span>
|
||||
<span id="297">297</span>
|
||||
<span id="298">298</span>
|
||||
<span id="299">299</span>
|
||||
<span id="300">300</span>
|
||||
<span id="301">301</span>
|
||||
<span id="302">302</span>
|
||||
<span id="303">303</span>
|
||||
<span id="304">304</span>
|
||||
<span id="305">305</span>
|
||||
<span id="306">306</span>
|
||||
<span id="307">307</span>
|
||||
<span id="308">308</span>
|
||||
<span id="309">309</span>
|
||||
<span id="310">310</span>
|
||||
<span id="311">311</span>
|
||||
<span id="312">312</span>
|
||||
<span id="313">313</span>
|
||||
<span id="314">314</span>
|
||||
<span id="315">315</span>
|
||||
<span id="316">316</span>
|
||||
</pre><pre class="rust"><code><span class="doccomment">//! 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.
|
||||
|
@ -282,6 +355,14 @@
|
|||
/// program; calling `B15F::new()` more than once might lead to unexpected
|
||||
/// behaviour.
|
||||
///
|
||||
/// # Returns
|
||||
/// A new B15F object is returned. It contains an already active USART connection,
|
||||
/// so calling this function multiple times will create an Error
|
||||
///
|
||||
/// # Errors
|
||||
/// An `error::Error` is generated if the connection to the board cannot be
|
||||
/// established, or if testing of that connection fails.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use b15f::B15F;
|
||||
|
@ -305,6 +386,11 @@
|
|||
<span class="prelude-val">Err</span>(<span class="kw">_</span>) => {} <span class="comment">// Do nothing
|
||||
</span>};
|
||||
|
||||
<span class="kw">match </span>drv.test_int_conv() {
|
||||
<span class="prelude-val">Ok</span>(()) => <span class="kw">break</span>,
|
||||
<span class="prelude-val">Err</span>(<span class="kw">_</span>) => {}
|
||||
}
|
||||
|
||||
tries -= <span class="number">1</span>;
|
||||
}
|
||||
|
||||
|
@ -346,11 +432,46 @@
|
|||
<span class="prelude-val">Ok</span>(port)
|
||||
}
|
||||
|
||||
<span class="doccomment">/// 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.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
</span><span class="kw">pub fn </span>digital_write<<span class="kw">const </span>port: u8> (<span class="kw-2">&mut </span><span class="self">self</span>, value: u8) -> <span class="prelude-ty">Result</span><(), Error> {
|
||||
<span class="macro">assert!</span>(port == <span class="number">0 </span>|| port == <span class="number">1</span>);
|
||||
|
||||
<span class="kw">let </span>reversed = value.reverse_bits();
|
||||
<span class="kw">let </span>request = <span class="kw">if </span>port == <span class="number">0 </span>{ Request::DigitalWrite0 } <span class="kw">else </span>{ Request::DigitalWrite1 };
|
||||
|
||||
<span class="self">self</span>.usart.write(<span class="macro">build_request!</span>[request, reversed])<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>aw: [u8; <span class="number">1</span>] = [<span class="number">0</span>; <span class="number">1</span>];
|
||||
<span class="self">self</span>.usart.read(<span class="kw-2">&mut </span>aw)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">if </span>aw[<span class="number">0</span>] != B15F::MSG_OK {
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">"Setting Port {} failed"</span>, port).into());
|
||||
}
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="doccomment">/// 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
|
||||
/// 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
|
||||
/// An `error::Error` is generated if the communication with the board fails.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use b15f::B15F;
|
||||
|
@ -412,13 +533,38 @@
|
|||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="doccomment">/// 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.
|
||||
</span><span class="kw">pub fn </span>test_int_conv(<span class="kw-2">&mut </span><span class="self">self</span>) -> <span class="prelude-ty">Result</span><(), Error> {
|
||||
<span class="kw">let </span>dummy: u16 = rand::thread_rng().gen_range(<span class="number">0x0000</span>..=(<span class="number">0xFFFF </span>/ <span class="number">3</span>));
|
||||
|
||||
<span class="self">self</span>.usart.write(<span class="macro">build_request!</span>(Request::IntTest, dummy & <span class="number">0xFF</span>, dummy >> <span class="number">8</span>))<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>aw: [u8; <span class="number">2</span>] = [<span class="number">0</span>; <span class="number">2</span>];
|
||||
<span class="self">self</span>.usart.read(<span class="kw-2">&mut </span>aw)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>result = u16::from_le_bytes(aw);
|
||||
<span class="kw">if </span>result != dummy * <span class="number">3 </span>{
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="string">"Int conversion failed"</span>.into());
|
||||
}
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="doccomment">/// 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.
|
||||
///
|
||||
/// ## Examples
|
||||
/// # Errors
|
||||
/// An `error::Error` is returned if the test fails, or if the
|
||||
/// communication itself fails.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use b15f::B15F;
|
||||
///
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
<span id="21">21</span>
|
||||
<span id="22">22</span>
|
||||
<span id="23">23</span>
|
||||
<span id="24">24</span>
|
||||
<span id="25">25</span>
|
||||
<span id="26">26</span>
|
||||
<span id="27">27</span>
|
||||
</pre><pre class="rust"><code><span class="doccomment">//! This module contains the request data used to communicate
|
||||
//! with the B15 via USART.
|
||||
//!
|
||||
|
@ -40,8 +44,12 @@
|
|||
|
||||
<span class="attribute">#[repr(u8)]
|
||||
</span><span class="kw">pub enum </span>Request {
|
||||
Discard = <span class="number">0</span>,
|
||||
Test = <span class="number">1</span>,
|
||||
Info = <span class="number">2
|
||||
</span>}</code></pre></div>
|
||||
Discard = <span class="number">0</span>,
|
||||
Test = <span class="number">1</span>,
|
||||
Info = <span class="number">2</span>,
|
||||
IntTest = <span class="number">3</span>,
|
||||
|
||||
DigitalWrite0 = <span class="number">5</span>,
|
||||
DigitalWrite1 = <span class="number">6</span>,
|
||||
}</code></pre></div>
|
||||
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="b15f" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0 (69f9c33d7 2022-12-12)" ></div></body></html>
|
21
examples/nightrider.rs
Normal file
21
examples/nightrider.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
use b15f::b15f::B15F;
|
||||
|
||||
fn main() {
|
||||
let mut drv = B15F::new().unwrap();
|
||||
|
||||
let mut position = 0;
|
||||
let mut direction = 1;
|
||||
|
||||
loop {
|
||||
drv.digital_write::<0>(1 << position);
|
||||
|
||||
position += direction;
|
||||
if position >= 7 || position <= 0 {
|
||||
direction *= -1;
|
||||
}
|
||||
|
||||
sleep(Duration::from_millis(50));
|
||||
}
|
||||
}
|
75
src/b15f.rs
75
src/b15f.rs
|
@ -39,6 +39,14 @@ impl B15F {
|
|||
/// program; calling `B15F::new()` more than once might lead to unexpected
|
||||
/// behaviour.
|
||||
///
|
||||
/// # Returns
|
||||
/// A new B15F object is returned. It contains an already active USART connection,
|
||||
/// so calling this function multiple times will create an Error
|
||||
///
|
||||
/// # Errors
|
||||
/// An `error::Error` is generated if the connection to the board cannot be
|
||||
/// established, or if testing of that connection fails.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use b15f::B15F;
|
||||
|
@ -62,6 +70,11 @@ impl B15F {
|
|||
Err(_) => {} // Do nothing
|
||||
};
|
||||
|
||||
match drv.test_int_conv() {
|
||||
Ok(()) => break,
|
||||
Err(_) => {}
|
||||
}
|
||||
|
||||
tries -= 1;
|
||||
}
|
||||
|
||||
|
@ -103,11 +116,46 @@ impl B15F {
|
|||
Ok(port)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
pub fn digital_write<const port: u8> (&mut self, value: u8) -> Result<(), Error> {
|
||||
assert!(port == 0 || port == 1);
|
||||
|
||||
let reversed = value.reverse_bits();
|
||||
let request = if port == 0 { Request::DigitalWrite0 } else { Request::DigitalWrite1 };
|
||||
|
||||
self.usart.write(build_request![request, reversed])?;
|
||||
|
||||
let mut aw: [u8; 1] = [0; 1];
|
||||
self.usart.read(&mut aw)?;
|
||||
|
||||
if aw[0] != B15F::MSG_OK {
|
||||
return Err(format!("Setting Port {} failed", port).into());
|
||||
}
|
||||
|
||||
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
|
||||
/// 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
|
||||
/// An `error::Error` is generated if the communication with the board fails.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use b15f::B15F;
|
||||
|
@ -169,13 +217,38 @@ impl B15F {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub fn test_int_conv(&mut self) -> Result<(), Error> {
|
||||
let dummy: u16 = rand::thread_rng().gen_range(0x0000..=(0xFFFF / 3));
|
||||
|
||||
self.usart.write(build_request!(Request::IntTest, dummy & 0xFF, dummy >> 8))?;
|
||||
|
||||
let mut aw: [u8; 2] = [0; 2];
|
||||
self.usart.read(&mut aw)?;
|
||||
|
||||
let result = u16::from_le_bytes(aw);
|
||||
if result != dummy * 3 {
|
||||
return Err("Int conversion failed".into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// ## Examples
|
||||
/// # Errors
|
||||
/// An `error::Error` is returned if the test fails, or if the
|
||||
/// communication itself fails.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use b15f::B15F;
|
||||
///
|
||||
|
|
|
@ -17,7 +17,11 @@ macro_rules! build_request {
|
|||
|
||||
#[repr(u8)]
|
||||
pub enum Request {
|
||||
Discard = 0,
|
||||
Test = 1,
|
||||
Info = 2
|
||||
Discard = 0,
|
||||
Test = 1,
|
||||
Info = 2,
|
||||
IntTest = 3,
|
||||
|
||||
DigitalWrite0 = 5,
|
||||
DigitalWrite1 = 6,
|
||||
}
|
Loading…
Reference in a new issue