-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a16f59
commit ee39574
Showing
9 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
mod File_system; | ||
|
||
mod Task; | ||
|
||
mod Graphics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod Object; | ||
pub use Object::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ pub use File_system::*; | |
|
||
mod Task; | ||
pub use Task::*; | ||
|
||
mod Graphics; | ||
pub use Graphics::*; |