Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/display #14

Merged
merged 6 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Modules/Bindings/Build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn main() -> Result<(), ()> {
println!("cargo:rerun-if-changed=Tests/WASM_test/src/main.rs");
println!("cargo:rerun-if-changed=Tests/WASM_test/src/File_system.rs");
println!("cargo:rerun-if-changed=Tests/WASM_test/src/Task.rs");
println!("cargo:rerun-if-changed=Tests/WASM_test/src/Graphics.rs");
println!("cargo:rerun-if-changed=Tests/WASM_test/Cargo.toml");

// TODO : Add a check for test mode
Expand Down
9 changes: 8 additions & 1 deletion Modules/Bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ Binding_tool = { path = "../../../Binding_tool", features = ["Native"] }
Shared = { path = "../Shared" }
Users = { path = "../Users" }
Task = { path = "../Task" }
Graphics = { path = "../Graphics" }
Screen = { path = "../Screen" }

[[test]]
name = "File_system_bindings_tests"
path = "Tests/File_system.rs"

[[test]]
name = "Task_tests"
name = "Task_bindings_tests"
path = "Tests/Task.rs"

[[test]]
name = "Graphics_bindings_tests"
path = "Tests/Graphics.rs"

72 changes: 72 additions & 0 deletions Modules/Bindings/Tests/Graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

use std::{
thread::{self, sleep},
time::{Duration, Instant},
};

use Bindings::{File_system_bindings, Graphics_bindings, Task_bindings};
use File_system::{
Drivers::Native::File_system_type,
Prelude::{Path_type, Virtual_file_system_type},
};
use Graphics::{lvgl, Display_type, Draw_buffer_type, Input_type};
use Screen::{Drivers::SDL2::New_touchscreen, Prelude::Point_type};
use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue};

#[test]
fn Integration_test() {
let Binary_buffer = include_bytes!(
"../../../target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm"
);

const Horizontal_resolution: u32 = 800;
const Vertical_resolution: u32 = 480;
const Buffer_size: usize = (Horizontal_resolution * Vertical_resolution / 2) as usize;

let Touchscreen = New_touchscreen(Point_type::New(
Horizontal_resolution as i16,
Vertical_resolution as i16,
));
assert!(Touchscreen.is_ok());
let (mut Screen, mut Pointer) = Touchscreen.unwrap();

let Buffer = Draw_buffer_type::<Buffer_size>::default();

let Display = Display_type::New(&mut Screen, Buffer);
assert!(Display.is_ok());
let Display = Display.unwrap();

let _Input = Input_type::New(&Pointer, &Display);
assert!(_Input.is_ok());
let mut _Input = _Input.unwrap();

let Display_object = Display.Get_object();
assert!(Display_object.is_ok());
let mut Display_object = Display_object.unwrap();

thread::spawn(|| {
let (_Runtime, _Module, Instance) = Instantiate_test_environment(
Binary_buffer,
Graphics_bindings::New(),
&Data_type::New(),
);

assert_eq!(
Instance
.Call_export_function("Test_graphics", &vec![])
.unwrap(),
WasmValue::I32(42)
)
});

loop {
let Start = Instant::now();
lvgl::task_handler();
sleep(Duration::from_millis(5));
lvgl::tick_inc(Instant::now().duration_since(Start));
Pointer.Update();
}
}
2 changes: 1 addition & 1 deletion Modules/Bindings/Tests/WASM_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Binding_tool = { path = "../../../../../Binding_tool", features = ["WASM"] }
Binding_tool = { path = "../../../../../Binding_tool", features = ["WASM"] }
31 changes: 31 additions & 0 deletions Modules/Bindings/Tests/WASM_test/src/Graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::thread::sleep;

use Binding_tool::Bind_function_WASM;

#[repr(transparent)]
pub struct Object_type([u8; 64]);

impl Default for Object_type {
fn default() -> Self {
Self([0; 64])
}
}

#[Bind_function_WASM]
fn Create_calendar(Result: &mut Object_type) {}

#[Bind_function_WASM]
fn Delete_object(Object: &mut Object_type) {}

#[no_mangle]
fn Test_graphics() -> u32 {
let mut Object = Object_type::default();

Create_calendar(&mut Object);

// sleep(std::time::Duration::from_secs(1));

// Delete_object(&mut Object);

42
}
2 changes: 2 additions & 0 deletions Modules/Bindings/Tests/WASM_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
mod File_system;

mod Task;

mod Graphics;
53 changes: 53 additions & 0 deletions Modules/Bindings/src/Graphics/Object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::{
mem::size_of,
ptr::{copy_nonoverlapping, null_mut},
};

use Binding_tool::Bind_function_native;
use Graphics::lvgl::sys::{
lv_calendar_create, lv_disp_get_default, lv_disp_get_hor_res, lv_disp_get_scr_act,
lv_disp_get_ver_res, lv_mem_alloc, lv_mem_free, lv_mem_realloc, lv_memset_00,
lv_obj_allocate_spec_attr, lv_obj_class_t, lv_obj_create, lv_obj_del,
lv_obj_enable_style_refresh, lv_obj_get_index, lv_obj_mark_layout_as_dirty, lv_obj_set_parent,
lv_obj_t,
};
use Virtual_machine::{Function_descriptor_type, Function_descriptors, Registrable_trait};

pub struct Graphics_bindings {}

impl Registrable_trait for Graphics_bindings {
fn Get_functions(&self) -> &[Function_descriptor_type] {
&Graphics_bindings_functions
}
}

impl Graphics_bindings {
pub fn New() -> Self {
println!("Size of lv_obj_t: {}", size_of::<lv_obj_t>());
Self {}
}
}

const Graphics_bindings_functions: [Function_descriptor_type; 2] =
Function_descriptors!(Create_object_binding, Create_calendar_binding);

#[Bind_function_native(Prefix = "Graphics")]
fn Create_object(Result: &mut lv_obj_t) {
unsafe {
let obj = lv_obj_create(null_mut());
}
}

#[Bind_function_native(Prefix = "Graphics")]
fn Create_calendar(Result: &mut lv_obj_t) {
unsafe {
let current_screen = lv_disp_get_scr_act(lv_disp_get_default());
}
}

#[Bind_function_native(Prefix = "Graphics")]
fn Delete_object(Object: &mut lv_obj_t) {
unsafe {
lv_obj_del(Object);
}
}
2 changes: 2 additions & 0 deletions Modules/Bindings/src/Graphics/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod Object;
pub use Object::*;
3 changes: 3 additions & 0 deletions Modules/Bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ pub use File_system::*;

mod Task;
pub use Task::*;

mod Graphics;
pub use Graphics::*;
2 changes: 1 addition & 1 deletion Modules/Graphics/include/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@
*==================*/

/*Enable the examples to be built with the library*/
#define LV_BUILD_EXAMPLES 1
#define LV_BUILD_EXAMPLES 0

/*===================
* DEMO USAGE
Expand Down
6 changes: 4 additions & 2 deletions Modules/Graphics/src/Display.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use Screen::Prelude::{Area_type, Color_type, Point_type, Refresh_area_type, Screen_traits};

use crate::Draw_buffer_type;

pub struct Display_type(lvgl::Display);

impl Display_type {
pub fn New<Screen_type: Screen_traits<Buffer_size>, const Buffer_size: usize>(
Screen: &mut Screen_type,
Draw_buffer: lvgl::DrawBuffer<Buffer_size>,
Draw_buffer: Draw_buffer_type<Buffer_size>,
) -> Result<Self, ()> {
let Resolution = match Screen.Get_resolution() {
Ok(Resolution) => Resolution,
Expand Down Expand Up @@ -41,7 +43,7 @@ impl Display_type {
};

let LVGL_display = match lvgl::Display::register(
Draw_buffer,
Draw_buffer.into(),
Resolution.X as u32,
Resolution.Y as u32,
Binding_function,
Expand Down
8 changes: 3 additions & 5 deletions Modules/Graphics/src/Input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ impl Input_type {
Touch_type::Released => Input_data.released(),
};

// if Changed {
Input_data.once()
// } else {
// Input_data.and_continued()
// }
};

match pointer::Pointer::register(Binding_function, Display.Get_lvgl_display()) {
Expand All @@ -36,6 +32,8 @@ impl Input_type {

#[cfg(test)]
mod tests {
use crate::Draw_buffer_type;

use super::*;
use lvgl::Widget;
use std::{
Expand All @@ -58,7 +56,7 @@ mod tests {
assert!(Touchscreen.is_ok());
let (mut Screen, mut Pointer) = Touchscreen.unwrap();

let Buffer = lvgl::DrawBuffer::<Buffer_size>::default();
let Buffer = Draw_buffer_type::<Buffer_size>::default();

let Display = Display_type::New(&mut Screen, Buffer);
assert!(Display.is_ok());
Expand Down
9 changes: 3 additions & 6 deletions Modules/Graphics/src/Window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use cstr_core::CString;
use lvgl::{
style::{FlexFlow, Style},
widgets::Label,
LvError, NativeObject, Obj, Widget,
LvError, NativeObject, Obj,
};
use Task::Task_identifier_type;

pub type Windows_indentifier_type = u16;

Expand All @@ -13,11 +12,9 @@ struct Window_type<'a> {
}

impl<'a> Window_type<'a> {
pub fn New<'b>(Parent: &'a mut impl NativeObject, Title_string: &str) -> Result<Self, LvError> {
pub fn New(Parent: &'a mut impl NativeObject, Title_string: &str) -> Result<Self, LvError> {
let mut Window = Obj::create(Parent)?;

let Style = Style::default().set_flex_flow(FlexFlow::COLUMN);

let mut Header = Obj::create(&mut Window)?;

let mut Title = Label::create(&mut Header)?;
Expand All @@ -28,7 +25,7 @@ impl<'a> Window_type<'a> {

// TODO : Wait for lv_binding_rust to implement correct drop and lifetime management

let mut Window = Self { Window };
let Window = Self { Window };

Ok(Window)
}
Expand Down
18 changes: 15 additions & 3 deletions Modules/Graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@

mod Display;
mod Input;
mod Window;
//mod Window;

pub use lvgl;
pub use Display::*;
pub use Input::*;
//pub use Window::*;

use Screen::Prelude::*;
pub use lvgl;
pub use lvgl::sys;

#[repr(transparent)]
pub struct Draw_buffer_type<const Buffer_size: usize>(lvgl::DrawBuffer<Buffer_size>);

impl<const Buffer_size: usize> Default for Draw_buffer_type<Buffer_size> {
fn default() -> Self {
Draw_buffer_type(lvgl::DrawBuffer::<Buffer_size>::default())
}
}

impl<const Buffer_size: usize> From<Draw_buffer_type<Buffer_size>>
for lvgl::DrawBuffer<Buffer_size>
{
fn from(Draw_buffer: Draw_buffer_type<Buffer_size>) -> Self {
Draw_buffer.0
}
}
22 changes: 22 additions & 0 deletions Setup_git_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

Hooks_dir=".git/hooks"
Pre_commit_file=$Hooks_dir/pre-commit
Pre_commit_hook="\
#!/bin/sh\n\
if ! cargo fmt -- --check > /dev/null 2>&1; then\n\
echo \"Please run 'cargo fmt' to format your code before making a commit.\"\n\
exit 1\n\
fi\n\
"

if [ ! -d "$Hooks_dir" ]; then
echo "The '.git/hooks' directory does not exist. Are you in the root of a git repository?"
exit 1
fi

rm -f $Pre_commit_file
echo $Pre_commit_hook > $Hooks_dir/pre-commit
chmod +x $Pre_commit_file

echo "Git hooks setup successfully!"
Loading