"use strict"; class Grove_UnitVAICamera { // Constants // Header of a receive packet static get _HOP() { return [0xFF, 0xD8, 0xEA, 0x01]; } // "Take a picture" instruction static get _TAP() { return [0xFF, 0xD8, 0xEA, 0x00]; } constructor() { this.keys = ["vcc", "cam_tx", "cam_rx", "gnd", "baud", "grove"]; this.requiredKeys = ["cam_tx", "cam_rx"]; this.ioKeys = this.keys; this.displayName = "Cam"; this.displayIoNames = { cam_tx: "camTx", cam_rx: "camRx" }; } static info() { return { name: "Grove_UnitVAICamera", }; } wired(obniz) { this.obniz = obniz; if (this.params.grove) { this.uart = this.params.grove.getUart(this.params.baud, "3v"); } else { this.obniz.setVccGnd(this.params.vcc, this.params.gnd, "5v"); this.uart = obniz.getFreeUart(); this.uart.start({ tx: this.params.cam_tx, rx: this.params.cam_rx, baud: this.params.baud, bits: this.params.bits, parity: this.params.parity, stop: this.params.stop, }); } } arrayToBase64(array) { //return Buffer.from(array).toString("base64"); // this line just work in obniz.js let uint8Array = new Uint8Array(array.length); for(let i = 0; i < uint8Array.length; i++) { uint8Array[i] = array[i]; } return btoa(String.fromCharCode(...new Uint8Array(uint8Array))); } async _drainUntil(uart, search, recv) { this.log("_drainUntil" + search); if (!recv) { recv = []; } this.log("recv:" + recv + ":" ); while (true) { const readed = uart.readBytes(); recv = recv.concat(readed); this.log("recv:" + recv + ":" ); const tail = this._seekTail(search, recv); if (tail >= 0) { recv.splice(0, tail); return recv; } await this.obniz.wait(10); } } _seekTail(search, src) { let f = 0; for (let i = 0; i < src.length; i++) { if (src[i] === search[f]) { f++; if (f === search.length) { this.log("find"); return i + 1; } } else { f = 0; } } return -1; } log(value) { // HTMLの