Skip to content

Commit

Permalink
futuresdr experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
bastibl committed Feb 14, 2023
1 parent 358095a commit ec0a2ca
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
11 changes: 11 additions & 0 deletions maia-wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions maia-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["science", "webassembly", "web-programming::http-client", "web-pro
crate-type = ["cdylib"]

[dependencies]
console_error_panic_hook = "0.1.7"
js-sys = "0.3"
maia-json = { path = "../maia-httpd/maia-json", version = "0.1.0" }
paste = "1.0"
Expand Down
30 changes: 18 additions & 12 deletions maia-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ pub mod websocket;
/// loaded, and it set up all the objects and callbacks that keep the web
/// application running.
#[wasm_bindgen(start)]
pub fn main() -> Result<(), JsValue> {
pub fn maia_init() {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
}

/// Mounts the waterfall plot.
#[wasm_bindgen]
pub fn waterfall(id: String) -> Result<(), JsValue> {
let window = Rc::new(web_sys::window().ok_or("unable to get window")?);
let document = Rc::new(window.document().ok_or("unable to get document")?);
let canvas = Rc::new(
document
.get_element_by_id("canvas")
.get_element_by_id(&id)
.ok_or("unable to get #canvas element")?
.dyn_into::<web_sys::HtmlCanvasElement>()?,
);
Expand All @@ -50,16 +56,16 @@ pub fn main() -> Result<(), JsValue> {
&mut render_engine.borrow_mut(),
window.performance().ok_or("unable to get performance")?,
)?));
WebSocketClient::start(&window, Rc::clone(&waterfall))?;
let ui = Ui::new(
Rc::clone(&window),
Rc::clone(&document),
Rc::clone(&render_engine),
Rc::clone(&waterfall),
)?;
let waterfall_interaction =
WaterfallInteraction::new(Rc::clone(&render_engine), canvas, ui, Rc::clone(&waterfall));
waterfall_interaction.set_callbacks();
WebSocketClient::start(Rc::clone(&waterfall), "ws://127.0.0.1:9001".to_string())?;
// let ui = Ui::new(
// Rc::clone(&window),
// Rc::clone(&document),
// Rc::clone(&render_engine),
// Rc::clone(&waterfall),
// )?;
// let waterfall_interaction =
// WaterfallInteraction::new(Rc::clone(&render_engine), canvas, ui, Rc::clone(&waterfall));
// waterfall_interaction.set_callbacks();

let f = Rc::new(RefCell::new(None));
let g = f.clone();
Expand Down
10 changes: 5 additions & 5 deletions maia-wasm/src/waterfall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl Waterfall {
zoom_levels: Vec::new(),
freq_num_idx: Rc::new(Cell::new(0)),
freq_num_idx_ticks: Rc::new(Cell::new(0)),
waterfall_min: 35.0,
waterfall_max: 85.0,
waterfall_min: -100.0,
waterfall_max: 0.0,
};

w.update_waterfall_scale();
Expand Down Expand Up @@ -136,9 +136,9 @@ impl Waterfall {
spectrum_linear.copy_to(spectrum_texture);
// Convert to "dB". We don't include the 10.0 factor to save us a multiplication.
// This will later be taken into account in the shader.
for x in spectrum_texture.iter_mut() {
*x = x.log10();
}
// for x in spectrum_texture.iter_mut() {
// *x = x.log10();
// }
}

/// Updates the waterfall for rendering.
Expand Down
7 changes: 2 additions & 5 deletions maia-wasm/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ impl WebSocketClient {
/// for the WebSocket client. No further interaction with the
/// `WebSocketClient` returned by this function is needed and it can be
/// dropped immediately.
pub fn start(window: &Window, waterfall: Rc<RefCell<Waterfall>>) -> Result<(), JsValue> {
let location = window.location();
let hostname = location.hostname()?;
let port = location.port()?;
pub fn start(waterfall: Rc<RefCell<Waterfall>>, url: String) -> Result<(), JsValue> {
let data = Rc::new(WebSocketData {
url: format!("ws://{hostname}:{port}/waterfall"),
url,
onmessage: onmessage(waterfall).into_js_value(),
onclose: RefCell::new(None),
});
Expand Down

0 comments on commit ec0a2ca

Please sign in to comment.