fixed some problems and added the demos for fxhelloworld, fxbasicexample and fxchompies

This commit is contained in:
ZennDev1337 2023-10-06 15:21:04 +02:00
parent 9ad03927de
commit 4a3100c0bd
18 changed files with 258 additions and 85 deletions

View file

@ -50,14 +50,10 @@ extern "C"
{
FX::drawString(buffer);
}
////
void arduboyfx_draw_string(const char *str)
{
FX::drawString(str);
}
////
void arduboyfx_set_cursor_x(int16_t x)
{
FX::setCursorX(x);
@ -80,19 +76,19 @@ extern "C"
}
void arduboyfx_draw_number_i16(int16_t n, int8_t digits)
{
FX::drawNumber(n);
FX::drawNumber(n,digits);
}
void arduboyfx_draw_number_i32(int32_t n, int8_t digits)
{
FX::drawNumber(n);
FX::drawNumber(n,digits);
}
void arduboyfx_draw_number_u16(uint16_t n, int8_t digits)
{
FX::drawNumber(n);
FX::drawNumber(n,digits);
}
void arduboyfx_draw_number_u32(uint32_t n, int8_t digits)
{
FX::drawNumber(n);
FX::drawNumber(n,digits);
}
void arduboyfx_draw_char(uint8_t c)
{

View file

@ -23,6 +23,10 @@ pub const A: ButtonSet = ButtonSet {
pub const B: ButtonSet = ButtonSet {
flag_set: 0b00000100,
};
/// Just a `const` for the any
pub const ANY_BUTTON: ButtonSet = ButtonSet {
flag_set: 0b11111111,
};
/// Just a `const` for the UP button
pub const UP_BUTTON: ButtonSet = UP;
/// Just a `const` for the RIGHT button

View file

@ -4,16 +4,15 @@
//! ```
//! use arduboy_rust::prelude::*;
//!
//! fn setup(){
//! fn setup() {
//! FX::begin()
//! }
//!
//! ```
//! You will need to uncomment the ArduboyFX_Library in the import_config.h file.
#![allow(non_upper_case_globals)]
use super::drawable_number::DrawableNumber;
use super::drawable_string::DrawableString;
use core::ffi::{c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
use core::ffi::{c_int, c_size_t, c_uchar, c_uint, c_ulong};
pub fn begin() {
unsafe { arduboyfx_begin() }
}
@ -66,12 +65,15 @@ pub fn set_cursor_x(x: i16) {
pub fn set_cursor_y(y: i16) {
unsafe { arduboyfx_set_cursor_y(y) }
}
pub fn set_cursor_range(left: i32, wrap: i32) {
pub fn set_cursor_range(left: i16, wrap: i16) {
unsafe { arduboyfx_set_cursor_range(left, wrap) }
}
pub fn set_font(address: u32, mode: u8) {
unsafe { arduboyfx_set_font(address, mode) }
}
pub fn set_font_mode(mode: u8) {
unsafe { arduboyfx_set_font_mode(mode) };
}
extern "C" {
#[link_name = "arduboyfx_begin"]
@ -107,8 +109,10 @@ extern "C" {
fn arduboyfx_set_cursor_y(y: c_int);
#[link_name = "arduboyfx_set_font"]
fn arduboyfx_set_font(address: c_ulong, mode: c_uchar);
#[link_name = "arduboyfx_set_font_mode"]
fn arduboyfx_set_font_mode(mode: c_uchar);
#[link_name = "arduboyfx_set_cursor_range"]
fn arduboyfx_set_cursor_range(left: c_long, wrap: c_long);
fn arduboyfx_set_cursor_range(left: c_int, wrap: c_int);
#[link_name = "arduboyfx_draw_char"]
fn arduboyfx_draw_char(c: c_uchar);

View file

@ -11,23 +11,21 @@ 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};
pub use crate::library::c::*;
#[doc(hidden)]
pub use crate::library::arduboyfx::{ fx as FX};
pub use crate::library::arduboyfx::{self};
pub use crate::library::eeprom::{EEPROM, EEPROMBYTE, EEPROMBYTECHECKLESS};
#[doc(hidden)]
pub use crate::library::progmem::Pstring;
pub use crate::library::sprites;
pub use crate::print::*;
#[doc(inline)]
pub use crate::serial_print as serial;
pub use crate::{
f, get_ardvoice_tone_addr, get_sprite_addr, get_string_addr, get_tones_addr, progmem,
};
#[doc(inline)]
pub use crate::{serial_print as serial};
use core::cmp;
pub use 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

@ -23,6 +23,7 @@ extern "C" {
///
///Example
/// ```
/// use arduboy_rust::prelude::*;
/// let value: i16 = 42;
///
/// serial::print(b"Hello World\n\0"[..]); // Prints "Hello World" and then sets the
@ -42,6 +43,7 @@ pub fn print(x: impl Serialprintable) {
///
///Example
/// ```
/// use arduboy_rust::prelude::*;
/// let value: i16 = 42;
///
/// serial::print(b"Hello World\n\0"[..]); // Prints "Hello World" and then sets the
@ -58,6 +60,7 @@ pub fn println(x: impl Serialprintlnable) {
///
/// ### Example
/// ```
/// use arduboy_rust::prelude::*;
/// serial::begin(9600)
/// ```
pub fn begin(baud_rates: u32) {
@ -69,10 +72,11 @@ pub fn end() {
}
/// Reads incoming serial data.
/// Use only inside of [available()]:
/// ```
/// if (serial::available() > 0) {
///```
/// use arduboy_rust::prelude::*;
/// if serial::available() > 0 {
/// // read the incoming byte:
/// let incoming_byte: i16 = Serial::read();
/// let incoming_byte: i16 = serial::read();
///
/// // say what you got:
/// serial::print("I received: ");
@ -89,23 +93,24 @@ pub fn read() -> i16 {
///
/// Use only inside of [available()]:
/// ```
/// if (Serial::available() > 0) {
/// use arduboy_rust::prelude::*;
/// if serial::available() > 0 {
/// // read the incoming byte:
/// let incomingByte: &str = Serial::read_as_utf8_str();
/// let incoming_byte: &str = serial::read_as_utf8_str();
///
/// // say what you got:
/// Serial::print("I received: ");
/// Serial::println(incomingByte);
/// serial::print("I received: ");
/// serial::println(incoming_byte);
/// }
/// ```
/// ### Returns
///
///The first byte of incoming serial data available (or -1 if no data is available). Data type: &str.
pub fn read_as_utf8_str() -> &'static str {
let intcoming_byte = unsafe { serial_read() };
let incoming_byte = unsafe { serial_read() };
static mut L: [u8; 2] = [0, 0];
unsafe {
L[0] = intcoming_byte as u8;
L[0] = incoming_byte as u8;
}
unsafe { core::str::from_utf8(&L).unwrap() }
}
@ -113,13 +118,14 @@ pub fn read_as_utf8_str() -> &'static str {
/// 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() > 0) {
/// use arduboy_rust::prelude::*;
/// if serial::available() > 0 {
/// // read the incoming byte:
/// incomingByte = Serial::read();
/// let incoming_byte = serial::read();
///
/// // say what you got:
/// Serial::print("I received: ");
/// Serial::println(incomingByte);
/// serial::print("I received: ");
/// serial::println(incoming_byte);
/// }
/// ```
pub fn available() -> i16 {
@ -218,7 +224,7 @@ impl Serialprintlnable for &str {
fn default_parameters() -> Self::Parameters {}
}
impl<const N: usize> Serialprintlnable for crate::heapless::String<N> {
impl<const N: usize> Serialprintlnable for heapless::String<N> {
type Parameters = ();
fn println_2(self, _params: Self::Parameters) {
@ -361,7 +367,7 @@ impl Serialprintable for &str {
fn default_parameters() -> Self::Parameters {}
}
impl<const N: usize> Serialprintable for crate::heapless::String<N> {
impl<const N: usize> Serialprintable for heapless::String<N> {
type Parameters = ();
fn print_2(self, _params: Self::Parameters) {