Skip to content

Commit

Permalink
use client for all support methods
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpertsov committed Jan 19, 2023
1 parent c865046 commit 57ee6bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
29 changes: 11 additions & 18 deletions web/frontend/src/components/board.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<!-- eslint-disable no-useless-return -->
<script setup lang="ts">

import { grpc } from '@improbable-eng/grpc-web';
import { toast } from '../lib/toast';
import { displayError } from '../lib/error';
import { rcLogConditionally } from '../lib/log';
import { Client, boardApi, BoardClient, ServiceError } from '@viamrobotics/sdk';
import { Client, BoardClient, ServiceError } from '@viamrobotics/sdk';

interface Props {
name: string
Expand All @@ -26,22 +25,16 @@ const pwmFrequency = $ref('');

let getPinMessage = $ref('');

const getGPIO = () => {
const req = new boardApi.GetGPIORequest();
req.setName(props.name);
req.setPin(getPin);

rcLogConditionally(req);
props.client.boardService.getGPIO(req, new grpc.Metadata(), (error, response) => {
if (error) {
toast.error(error.message);
return;
}

const x = response!.toObject();

getPinMessage = `Pin: ${getPin} is ${x.high ? 'high' : 'low'}`;
});
const getGPIO = async () => {
const bc = new BoardClient(props.client, props.name, { requestLogger: rcLogConditionally });
try {
const response = await bc.getGPIO(getPin);
getPinMessage = `Pin: ${getPin} is ${response.toObject().high ? 'high' : 'low'}`;
return;
} catch (error) {
toast.error((error as ServiceError).message);
return;
}
};

const setGPIO = async () => {
Expand Down
22 changes: 9 additions & 13 deletions web/frontend/src/components/motor-detail.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!-- eslint-disable no-useless-return -->
<script setup lang="ts">
import { onMounted } from 'vue';
import { grpc } from '@improbable-eng/grpc-web';
import { Client, motorApi, MotorClient, ServiceError } from '@viamrobotics/sdk';
import { displayError } from '../lib/error';
import { rcLogConditionally } from '../lib/log';
Expand Down Expand Up @@ -117,19 +116,16 @@ const motorStop = async () => {
}
};

onMounted(() => {
const req = new motorApi.GetPropertiesRequest();
req.setName(props.name);

rcLogConditionally(req);
props.client.motorService.getProperties(req, new grpc.Metadata(), (err, resp) => {
if (err) {
return displayError(err);
}

properties = resp!.toObject();
});
onMounted(async () => {
const mc = new MotorClient(props.client, props.name, { requestLogger: rcLogConditionally });
try {
properties = await mc.getProperties();
} catch (error) {
displayError(error as ServiceError);
return;
}
});

</script>

<template>
Expand Down

0 comments on commit 57ee6bd

Please sign in to comment.