import { COHERENT_COMM_BUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT } from '../constants';

export const loadAircraft = () => {
  Coherent.call(
    COHERENT_COMM_BUS_WASM_CALL,
    COMM_BUS_UPDATE_TARGET_EVENT,
    JSON.stringify({
      mode: 3,
    })
  );
};

export const unloadAircraft = () => {
  Coherent.call(
    COHERENT_COMM_BUS_WASM_CALL,
    COMM_BUS_UPDATE_TARGET_EVENT,
    JSON.stringify({
      mode: 4,
    })
  );
};

export const inRangeOf = (value: number, target: number, tolerance: number = 10) => {
  return Math.abs(value - target) < tolerance;
};
