added all the examples for the FX library. changes in the Readme.md and updated the docs.

This commit is contained in:
ZennDev1337 2023-10-09 10:15:40 +02:00
parent 4c3a37dee7
commit 6c70700ad7
157 changed files with 838 additions and 768 deletions

View file

@ -67,6 +67,10 @@
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! A list of all six buttons available on the Arduboy
/// Just a `const` for the UP button
</span><span class="kw">pub const </span>UP: ButtonSet = ButtonSet {
@ -92,6 +96,10 @@
</span><span class="kw">pub const </span>B: ButtonSet = ButtonSet {
flag_set: <span class="number">0b00000100</span>,
};
<span class="doccomment">/// Just a `const` for the any
</span><span class="kw">pub const </span>ANY_BUTTON: ButtonSet = ButtonSet {
flag_set: <span class="number">0b11111111</span>,
};
<span class="doccomment">/// Just a `const` for the UP button
</span><span class="kw">pub const </span>UP_BUTTON: ButtonSet = UP;
<span class="doccomment">/// Just a `const` for the RIGHT button

View file

@ -798,15 +798,49 @@
<a href="#798" id="798">798</a>
<a href="#799" id="799">799</a>
<a href="#800" id="800">800</a>
<a href="#801" id="801">801</a>
<a href="#802" id="802">802</a>
<a href="#803" id="803">803</a>
<a href="#804" id="804">804</a>
<a href="#805" id="805">805</a>
<a href="#806" id="806">806</a>
<a href="#807" id="807">807</a>
<a href="#808" id="808">808</a>
<a href="#809" id="809">809</a>
<a href="#810" id="810">810</a>
<a href="#811" id="811">811</a>
<a href="#812" id="812">812</a>
<a href="#813" id="813">813</a>
<a href="#814" id="814">814</a>
<a href="#815" id="815">815</a>
<a href="#816" id="816">816</a>
<a href="#817" id="817">817</a>
<a href="#818" id="818">818</a>
<a href="#819" id="819">819</a>
<a href="#820" id="820">820</a>
<a href="#821" id="821">821</a>
<a href="#822" id="822">822</a>
<a href="#823" id="823">823</a>
<a href="#824" id="824">824</a>
<a href="#825" id="825">825</a>
<a href="#826" id="826">826</a>
<a href="#827" id="827">827</a>
<a href="#828" id="828">828</a>
<a href="#829" id="829">829</a>
<a href="#830" id="830">830</a>
<a href="#831" id="831">831</a>
<a href="#832" id="832">832</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the Module to interact in a save way with the Arduboy2 C++ library.
//!
//! All of the functions are safe wrapped inside the [Arduboy2] struct.
</span><span class="attr">#![allow(dead_code)]
</span><span class="kw">use </span><span class="kw">crate</span>::hardware::buttons::ButtonSet;
<span class="kw">use </span><span class="kw">crate</span>::print::Printable;
<span class="kw">use </span>core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
<span class="kw">use </span>core::mem;
<span class="kw">use </span>core::ops::Not;
<span class="doccomment">/// The standard font size of the arduboy
///
/// this is to calculate with it.
@ -829,6 +863,7 @@
<span class="doccomment">/// Led is on
</span>White,
}
<span class="kw">impl </span>Not <span class="kw">for </span>Color {
<span class="kw">type </span>Output = <span class="self">Self</span>;
@ -839,6 +874,7 @@
}
}
}
<span class="doccomment">/// This struct is used by a few Arduboy functions.
</span><span class="attr">#[derive(Debug, Clone, Copy)]
</span><span class="kw">pub struct </span>Rect {
@ -851,6 +887,7 @@
<span class="doccomment">/// Rect height
</span><span class="kw">pub </span>height: u8,
}
<span class="doccomment">/// This struct is used by a few Arduboy functions.
</span><span class="attr">#[derive(Debug, Clone, Copy)]
</span><span class="kw">pub struct </span>Point {
@ -862,6 +899,7 @@
<span class="doccomment">/// This is the struct to interact in a save way with the Arduboy2 C++ library.
</span><span class="kw">pub struct </span>Arduboy2 {}
<span class="kw">impl </span>Arduboy2 {
<span class="doccomment">/// gives you a new instance of the [Arduboy2]
/// ## Example
@ -1148,7 +1186,7 @@
/// ```
/// #![allow(non_upper_case_globals)]
/// use arduboy_rust::prelude::*;
/// const arduboy:Arduboy2 =Arduboy2::new();
/// const arduboy: Arduboy2 = Arduboy2::new();
/// let value: i16 = 42;
///
/// arduboy.print(b&quot;Hello World\n\0&quot;[..]); // Prints &quot;Hello World&quot; and then sets the
@ -1311,10 +1349,10 @@
///Parameters
///- color The name of the LED to set. The value given should be one of RED_LED, GREEN_LED or BLUE_LED.
///- val The brightness value for the LED, from 0 to 255.
///
///
///**Note**
///&gt; In order to use this function, the 3 parameter version must first be called at least once, in order to initialize the hardware.
///
///
///This 2 parameter version of the function will set the brightness of a single LED within the RGB LED without affecting the current brightness of the other two. See the description of the 3 parameter version of this function for more details on the RGB LED.
</span><span class="kw">pub fn </span>set_rgb_led_single(<span class="kw-2">&amp;</span><span class="self">self</span>, color: u8, val: u8) {
<span class="kw">unsafe </span>{ set_rgb_led_single(color, val) }
@ -1350,7 +1388,7 @@
///```
/// #![allow(non_upper_case_globals)]
/// use arduboy_rust::prelude::*;
/// const arduboy:Arduboy2 =Arduboy2::new();
/// const arduboy: Arduboy2 = Arduboy2::new();
///
/// if arduboy.everyXFrames(5) {
/// if arduboy.pressed(A_BUTTON) {
@ -1436,10 +1474,30 @@
</span><span class="kw">pub fn </span>idle(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">unsafe </span>{ idle() }
}
<span class="doccomment">///Get the current state of all buttons as a bitmask.
///
///### Returns
///A bitmask of the state of all the buttons.
///
///The returned mask contains a bit for each button. For any pressed button, its bit will be 1. For released buttons their associated bits will be 0.
///
///The following defined mask values should be used for the buttons:
/// LEFT_BUTTON, RIGHT_BUTTON, UP_BUTTON, DOWN_BUTTON, A_BUTTON, B_BUTTON
</span><span class="kw">pub fn </span>buttons_state(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; u8 {
<span class="kw">unsafe </span>{ arduboy_buttons_state() }
}
<span class="doccomment">///Exit the sketch and start the bootloader.
///
///The sketch will exit and the bootloader will be started in command mode. The effect will be similar to pressing the reset button.
///
///This function is intended to be used to allow uploading a new sketch, when the USB code has been removed to gain more code space. Ideally, the sketch would present a &quot;New Sketch Upload&quot; menu or prompt telling the user to &quot;Press and hold the DOWN button when the procedure to upload a new sketch has been initiated&quot;.
///The sketch would then wait for the DOWN button to be pressed and then call this function.
</span><span class="kw">pub fn </span>exit_to_bootloader(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">unsafe </span>{ arduboy_exit_to_bootloader() }
}
}
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduboy_begin&quot;</span>]
</span><span class="kw">fn </span>begin();
@ -1597,5 +1655,11 @@
<span class="attr">#[link_name = <span class="string">&quot;arduboy_set_rgb_led&quot;</span>]
</span><span class="kw">fn </span>set_rgb_led(red: c_uchar, green: c_uchar, blue: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduboy_buttons_state&quot;</span>]
</span><span class="kw">fn </span>arduboy_buttons_state() -&gt; u8;
<span class="attr">#[link_name = <span class="string">&quot;arduboy_exit_to_bootloader&quot;</span>]
</span><span class="kw">fn </span>arduboy_exit_to_bootloader();
}
</code></pre></div></section></main></body></html>

View file

@ -113,22 +113,42 @@
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! Functions given by the ArduboyFX library.
//!
//! You can use the &#39;FX::&#39; module to access the functions after the import of the prelude
//! ```
//! use arduboy_rust::prelude::*;
//!
//! fn setup(){
//! fn setup() {
//! FX::begin()
//! }
//!
//! ```
//! You will need to uncomment the ArduboyFX_Library in the import_config.h file.
</span><span class="attr">#![allow(non_upper_case_globals)]
</span><span class="kw">use </span><span class="kw">super</span>::drawable_number::DrawableNumber;
<span class="kw">use </span><span class="kw">super</span>::drawable_string::DrawableString;
<span class="kw">use </span>core::ffi::{c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
<span class="kw">use </span>core::ffi::{c_int, c_size_t, c_uchar, c_uint, c_ulong};
<span class="kw">pub fn </span>begin() {
<span class="kw">unsafe </span>{ arduboyfx_begin() }
}
@ -181,13 +201,29 @@
<span class="kw">pub fn </span>set_cursor_y(y: i16) {
<span class="kw">unsafe </span>{ arduboyfx_set_cursor_y(y) }
}
<span class="kw">pub fn </span>set_cursor_range(left: i32, wrap: i32) {
<span class="kw">pub fn </span>set_cursor_range(left: i16, wrap: i16) {
<span class="kw">unsafe </span>{ arduboyfx_set_cursor_range(left, wrap) }
}
<span class="kw">pub fn </span>set_font(address: u32, mode: u8) {
<span class="kw">unsafe </span>{ arduboyfx_set_font(address, mode) }
}
<span class="kw">pub fn </span>set_font_mode(mode: u8) {
<span class="kw">unsafe </span>{ arduboyfx_set_font_mode(mode) };
}
<span class="kw">pub fn </span>load_game_state&lt;T&gt;(your_struct: <span class="kw-2">&amp;mut </span>T) -&gt; u8 {
<span class="kw">let </span>pointer = your_struct <span class="kw">as </span><span class="kw-2">*mut </span>T;
<span class="kw">let </span>object_pointer = pointer <span class="kw">as </span><span class="kw-2">*mut </span>u8;
<span class="kw">let </span>object_size = core::mem::size_of::&lt;T&gt;();
<span class="kw">unsafe </span>{ arduboyfx_load_game_state(object_pointer, object_size) }
}
<span class="kw">pub fn </span>save_game_state&lt;T&gt;(your_struct: <span class="kw-2">&amp;</span>T) {
<span class="kw">let </span>pointer = your_struct <span class="kw">as </span><span class="kw-2">*const </span>T;
<span class="kw">let </span>object_pointer = pointer <span class="kw">as </span><span class="kw-2">*const </span>u8;
<span class="kw">let </span>object_size = core::mem::size_of::&lt;T&gt;();
<span class="kw">unsafe </span>{ arduboyfx_save_game_state(object_pointer, object_size) }
}
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_begin&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_begin();
@ -222,10 +258,16 @@
</span><span class="kw">fn </span>arduboyfx_set_cursor_y(y: c_int);
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_set_font&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_set_font(address: c_ulong, mode: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_set_font_mode&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_set_font_mode(mode: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_set_cursor_range&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_set_cursor_range(left: c_long, wrap: c_long);
</span><span class="kw">fn </span>arduboyfx_set_cursor_range(left: c_int, wrap: c_int);
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_draw_char&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_draw_char(c: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_load_game_state&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_load_game_state(object: <span class="kw-2">*mut </span>u8, size: usize) -&gt; u8;
<span class="attr">#[link_name = <span class="string">&quot;arduboyfx_save_game_state&quot;</span>]
</span><span class="kw">fn </span>arduboyfx_save_game_state(object: <span class="kw-2">*const </span>u8, size: usize);
}
</code></pre></div></section></main></body></html>

View file

@ -36,9 +36,6 @@
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the important one to use this library effective in your project
//!
//! Import the module:
@ -52,23 +49,20 @@
<span class="kw">pub use </span><span class="kw">crate</span>::heapless::{LinearMap, String, Vec};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy2::{<span class="self">self</span>, <span class="kw-2">*</span>};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy_tones::{<span class="self">self</span>, ArduboyTones};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboyfx::{<span class="self">self</span>, fx};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduino::<span class="kw-2">*</span>;
<span class="kw">pub use </span><span class="kw">crate</span>::library::ardvoice::{<span class="self">self</span>, ArdVoice};
<span class="kw">pub use </span><span class="kw">crate</span>::library::c::<span class="kw-2">*</span>;
<span class="attr">#[doc(hidden)]
</span><span class="kw">pub use </span><span class="kw">crate</span>::library::arduboyfx::{ fx <span class="kw">as </span>FX};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboyfx::{<span class="self">self</span>};
<span class="kw">pub use </span><span class="kw">crate</span>::library::eeprom::{EEPROM, EEPROMBYTE, EEPROMBYTECHECKLESS};
<span class="attr">#[doc(hidden)]
</span><span class="kw">pub use </span><span class="kw">crate</span>::library::progmem::Pstring;
<span class="kw">pub use </span><span class="kw">crate</span>::library::sprites;
<span class="kw">pub use </span><span class="kw">crate</span>::print::<span class="kw-2">*</span>;
<span class="attr">#[doc(inline)]
</span><span class="kw">pub use </span><span class="kw">crate</span>::serial_print <span class="kw">as </span>serial;
<span class="kw">pub use crate</span>::{
f, get_ardvoice_tone_addr, get_sprite_addr, get_string_addr, get_tones_addr, progmem,
};
<span class="attr">#[doc(inline)]
</span><span class="kw">pub use crate</span>::{serial_print <span class="kw">as </span>serial};
<span class="kw">use </span>core::cmp;
<span class="kw">pub use </span>core::ffi::{
c_char, c_double, c_float, c_int, c_long, c_longlong, c_size_t, c_uchar, c_uint, c_ulong,

View file

@ -410,6 +410,12 @@
<a href="#410" id="410">410</a>
<a href="#411" id="411">411</a>
<a href="#412" id="412">412</a>
<a href="#413" id="413">413</a>
<a href="#414" id="414">414</a>
<a href="#415" id="415">415</a>
<a href="#416" id="416">416</a>
<a href="#417" id="417">417</a>
<a href="#418" id="418">418</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the Module to interact in a save way with the Arduino Serial C++ library.
//!
//! You will need to uncomment the Arduino_Serial_Library in the import_config.h file.
@ -435,6 +441,7 @@
///
///Example
/// ```
/// use arduboy_rust::prelude::*;
/// let value: i16 = 42;
///
/// serial::print(b&quot;Hello World\n\0&quot;[..]); // Prints &quot;Hello World&quot; and then sets the
@ -454,6 +461,7 @@
///
///Example
/// ```
/// use arduboy_rust::prelude::*;
/// let value: i16 = 42;
///
/// serial::print(b&quot;Hello World\n\0&quot;[..]); // Prints &quot;Hello World&quot; and then sets the
@ -470,6 +478,7 @@
///
/// ### Example
/// ```
/// use arduboy_rust::prelude::*;
/// serial::begin(9600)
/// ```
</span><span class="kw">pub fn </span>begin(baud_rates: u32) {
@ -481,10 +490,11 @@
}
<span class="doccomment">/// Reads incoming serial data.
/// Use only inside of [available()]:
/// ```
/// if (serial::available() &gt; 0) {
///```
/// use arduboy_rust::prelude::*;
/// if serial::available() &gt; 0 {
/// // read the incoming byte:
/// let incoming_byte: i16 = Serial::read();
/// let incoming_byte: i16 = serial::read();
///
/// // say what you got:
/// serial::print(&quot;I received: &quot;);
@ -501,23 +511,24 @@
///
/// Use only inside of [available()]:
/// ```
/// if (Serial::available() &gt; 0) {
/// use arduboy_rust::prelude::*;
/// if serial::available() &gt; 0 {
/// // read the incoming byte:
/// let incomingByte: &amp;str = Serial::read_as_utf8_str();
/// let incoming_byte: &amp;str = serial::read_as_utf8_str();
///
/// // say what you got:
/// Serial::print(&quot;I received: &quot;);
/// Serial::println(incomingByte);
/// serial::print(&quot;I received: &quot;);
/// serial::println(incoming_byte);
/// }
/// ```
/// ### Returns
///
///The first byte of incoming serial data available (or -1 if no data is available). Data type: &amp;str.
</span><span class="kw">pub fn </span>read_as_utf8_str() -&gt; <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>str {
<span class="kw">let </span>intcoming_byte = <span class="kw">unsafe </span>{ serial_read() };
<span class="kw">let </span>incoming_byte = <span class="kw">unsafe </span>{ serial_read() };
<span class="kw">static </span><span class="kw-2">mut </span>L: [u8; <span class="number">2</span>] = [<span class="number">0</span>, <span class="number">0</span>];
<span class="kw">unsafe </span>{
L[<span class="number">0</span>] = intcoming_byte <span class="kw">as </span>u8;
L[<span class="number">0</span>] = incoming_byte <span class="kw">as </span>u8;
}
<span class="kw">unsafe </span>{ core::str::from_utf8(<span class="kw-2">&amp;</span>L).unwrap() }
}
@ -525,13 +536,14 @@
<span class="doccomment">/// Get the number of bytes (characters) available for reading from the serial port. This is data thats already arrived and stored in the serial receive buffer (which holds 64 bytes).
/// ### Example
/// ```
/// if (Serial::available() &gt; 0) {
/// use arduboy_rust::prelude::*;
/// if serial::available() &gt; 0 {
/// // read the incoming byte:
/// incomingByte = Serial::read();
/// let incoming_byte = serial::read();
///
/// // say what you got:
/// Serial::print(&quot;I received: &quot;);
/// Serial::println(incomingByte);
/// serial::print(&quot;I received: &quot;);
/// serial::println(incoming_byte);
/// }
/// ```
</span><span class="kw">pub fn </span>available() -&gt; i16 {
@ -630,7 +642,7 @@
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Serialprintlnable <span class="kw">for </span><span class="kw">crate</span>::heapless::String&lt;N&gt; {
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Serialprintlnable <span class="kw">for </span>heapless::String&lt;N&gt; {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>println_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
@ -773,7 +785,7 @@
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Serialprintable <span class="kw">for </span><span class="kw">crate</span>::heapless::String&lt;N&gt; {
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Serialprintable <span class="kw">for </span>heapless::String&lt;N&gt; {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {