igbopie/spherov2.js

View on GitHub
examples/src/web.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Toys, Scanner, Core } from 'spherov2.js';
import { patrol } from './utils/patrol';

const robot = `SB-`;
export const starter = async <T extends Core>(fn: (sphero: T) => void) => {
  const adv = Toys.find((toy) => toy.prefix === robot);
  const sphero = await Scanner.find<T>(adv);
  if (sphero) {
    fn(sphero);
  }
};

document.querySelector('button').onclick = () => {
  starter(patrol);
};