commit save to work

This commit is contained in:
ZennDev1337 2023-10-09 08:25:48 +02:00
parent 4a3100c0bd
commit 4c3a37dee7
8 changed files with 607 additions and 12 deletions

View file

@ -200,4 +200,12 @@ extern "C"
{
arduboy.setRGBled(red, green, blue);
}
uint8_t arduboy_buttons_state()
{
return arduboy.buttonsState();
}
void arduboy_exit_to_bootloader()
{
arduboy.exitToBootloader();
}
}

View file

@ -94,4 +94,12 @@ extern "C"
{
FX::drawChar(c);
}
uint8_t arduboyfx_load_game_state(uint8_t *gameState,size_t size)
{
return FX::loadGameState(gameState, size);
}
void arduboyfx_save_game_state(uint8_t *gameState,size_t size)
{
FX::saveGameState(gameState, size);
}
}

View file

@ -2,11 +2,13 @@
//!
//! All of the functions are safe wrapped inside the [Arduboy2] struct.
#![allow(dead_code)]
use crate::hardware::buttons::ButtonSet;
use crate::print::Printable;
use core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
use core::mem;
use core::ops::Not;
/// The standard font size of the arduboy
///
/// this is to calculate with it.
@ -29,6 +31,7 @@ pub enum Color {
/// Led is on
White,
}
impl Not for Color {
type Output = Self;
@ -39,6 +42,7 @@ impl Not for Color {
}
}
}
/// This struct is used by a few Arduboy functions.
#[derive(Debug, Clone, Copy)]
pub struct Rect {
@ -51,6 +55,7 @@ pub struct Rect {
/// Rect height
pub height: u8,
}
/// This struct is used by a few Arduboy functions.
#[derive(Debug, Clone, Copy)]
pub struct Point {
@ -62,6 +67,7 @@ pub struct Point {
/// This is the struct to interact in a save way with the Arduboy2 C++ library.
pub struct Arduboy2 {}
impl Arduboy2 {
/// gives you a new instance of the [Arduboy2]
/// ## Example
@ -348,7 +354,7 @@ impl Arduboy2 {
/// ```
/// #![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"Hello World\n\0"[..]); // Prints "Hello World" and then sets the
@ -511,10 +517,10 @@ impl Arduboy2 {
///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**
///> 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.
pub fn set_rgb_led_single(&self, color: u8, val: u8) {
unsafe { set_rgb_led_single(color, val) }
@ -550,7 +556,7 @@ impl Arduboy2 {
///```
/// #![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) {
@ -636,10 +642,30 @@ impl Arduboy2 {
pub fn idle(&self) {
unsafe { idle() }
}
///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
pub fn buttons_state(&self) -> u8 {
unsafe { arduboy_buttons_state() }
}
///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 "New Sketch Upload" menu or prompt telling the user to "Press and hold the DOWN button when the procedure to upload a new sketch has been initiated".
///The sketch would then wait for the DOWN button to be pressed and then call this function.
pub fn exit_to_bootloader(&self) {
unsafe { arduboy_exit_to_bootloader() }
}
}
extern "C" {
#[link_name = "arduboy_begin"]
fn begin();
@ -797,4 +823,10 @@ extern "C" {
#[link_name = "arduboy_set_rgb_led"]
fn set_rgb_led(red: c_uchar, green: c_uchar, blue: c_uchar);
#[link_name = "arduboy_buttons_state"]
fn arduboy_buttons_state() -> u8;
#[link_name = "arduboy_exit_to_bootloader"]
fn arduboy_exit_to_bootloader();
}

View file

@ -74,7 +74,20 @@ pub fn set_font(address: u32, mode: u8) {
pub fn set_font_mode(mode: u8) {
unsafe { arduboyfx_set_font_mode(mode) };
}
pub fn load_game_state<T>(your_struct: &mut T) -> u8 {
let pointer = your_struct as *mut T;
let object_pointer = pointer as *mut u8;
let object_size = core::mem::size_of::<T>();
unsafe { arduboyfx_load_game_state(object_pointer, object_size) }
}
pub fn save_game_state<T>(your_struct: &T) {
let pointer = your_struct as *const T;
let object_pointer = pointer as *const u8;
let object_size = core::mem::size_of::<T>();
unsafe { arduboyfx_save_game_state(object_pointer, object_size) }
}
extern "C" {
#[link_name = "arduboyfx_begin"]
fn arduboyfx_begin();
@ -115,5 +128,9 @@ extern "C" {
fn arduboyfx_set_cursor_range(left: c_int, wrap: c_int);
#[link_name = "arduboyfx_draw_char"]
fn arduboyfx_draw_char(c: c_uchar);
#[link_name = "arduboyfx_load_game_state"]
fn arduboyfx_load_game_state(object: *mut u8, size: usize) -> u8;
#[link_name = "arduboyfx_save_game_state"]
fn arduboyfx_save_game_state(object: *const u8, size: usize);
}

View file

@ -11,7 +11,6 @@ pub use crate::hardware::led::{self, *};
pub use crate::heapless::{LinearMap, String, Vec};
pub use crate::library::arduboy2::{self, *};
pub use crate::library::arduboy_tones::{self, ArduboyTones};
#[doc(hidden)]
pub use crate::library::arduboyfx::{self, fx};
pub use crate::library::arduino::*;
pub use crate::library::ardvoice::{self, ArdVoice};