import { invoke } from "@tauri-apps/api/tauri"
import { message } from '@tauri-apps/api/dialog';
import { useLocalStorage } from '@vueuse/core'

const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600 })

export async function useSerial(input) {
  try {
    await invoke('write_serial', { input: input + ";", portName: serialConfig.value.port, baud: serialConfig.value.baud });
  } catch (err) {
    console.error(err);
    await message(err, { title: 'Error while writing serial', type: 'error' });
  }
}
