1use std::collections::BTreeMap;
2
3use wasm_bindgen::prelude::*;
4
5use cpu::*;
6
7#[wasm_bindgen]
8pub fn tx2_unmasked_alarm_active(tx2: &Tx2) -> bool {
9 tx2.unmasked_alarm_active()
10}
11
12#[wasm_bindgen]
13pub fn get_alarm_statuses(tx2: &Tx2) -> Result<JsValue, String> {
14 let alarm_status = tx2.get_alarm_statuses();
15 match serde_wasm_bindgen::to_value(&alarm_status) {
16 Ok(val) => {
17 Ok(val)
23 }
24 Err(e) => {
25 Err(e.to_string())
27 }
28 }
29}
30
31#[wasm_bindgen]
32pub fn drain_alarm_changes(tx2: &mut Tx2) -> Result<JsValue, String> {
33 let change_map: BTreeMap<String, AlarmStatus> = tx2
34 .drain_alarm_changes()
35 .into_iter()
36 .map(|(kind, status)| (kind.to_string(), status))
37 .collect();
38 serde_wasm_bindgen::to_value(&change_map).map_err(|e| e.to_string())
39}
40
41#[wasm_bindgen]
42pub fn set_alarm_masked(tx2: &mut Tx2, alarm_name: &str, masked: bool) -> Result<(), String> {
43 match AlarmKind::try_from(alarm_name) {
44 Ok(kind) => tx2
45 .set_alarm_masked(kind, masked)
46 .map_err(|e| e.to_string()),
47 Err(e) => Err(e.to_string()),
48 }
49}