diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 71% rename from .eslintrc.js rename to .eslintrc.cjs index 2e21fb9..650e463 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -6,9 +6,8 @@ module.exports = { 'plugin:react-hooks/recommended', 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/eslint-recommended', - 'prettier', ], - plugins: ['@typescript-eslint', 'prettier'], + plugins: ['@typescript-eslint'], parser: '@typescript-eslint/parser', env: { browser: true, @@ -22,21 +21,13 @@ module.exports = { }, parserOptions: { sourceType: 'module', - ecmaFeatures: { - jsx: true, - }, - }, - ecmaFeatures: { - impliedStrict: true, //常にStrictMode }, rules: { - 'prefer-template': 'error', - 'pretter/prettier': 'error', '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/explicit-module-boundary-types': 'off', 'no-dupe-args': ['error'], 'no-dupe-keys': ['error'], 'no-unreachable': ['error'], - "brace-style": ["error", "stroustrup"] + //"brace-style": ["error", "stroustrup"], }, } \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..de67fbb --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,17 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts + - run: npm run build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c07740d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,17 @@ +name: Test + +on: push + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: setup Node.js + uses: actions/setup-node@v4 + with: + node-version: lts + - run: npm install + - run: npm run lint + - run: npm run typecheck diff --git a/.prettierrc b/.prettierrc index 91b5ffa..5f26435 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,5 +3,6 @@ "semi": false, "quoteProps": "consistent", "jsxBracketSameLine": false, - "singleAttributePerLine": true + "singleAttributePerLine": true, + "braceStyle": "stroustrup" } diff --git a/.vscode/settings.json b/.vscode/settings.json index c70312f..510340b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "editor.defaultFormatter": "dbaeumer.vscode-eslint", "editor.formatOnSave": true, "editor.formatOnType": true, "editor.formatOnPaste": true, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..226b50e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,69 @@ +# How to contribute to the project + +This project welcomes any change, improvement, or suggestion! + +If you'd like to help its development feel free to open a new issue and raise a pull request. + +## IMPORTANT + +If you'd like to work on an existing issue, kindly **ask** for it to be assigned to you. + +Do you have any struggles with the issue you are working on? Feel free to **tag [me](https://github.com/AllenShintani)** in it _and/or_ open a draft pull request. Please add the appropriate labels to the issues. It's not necessary if an appropriate label does not exist. + +We will collaborate with users and contributors to develop the necessary features, devices, etc. This OSS will be developed in a scrum style. We appreciate and respect all contributors and users. + +### How do I make a contribution + +If you've never made an open source contribution before or are curious about how contributions operate in our project? Here's a quick rundown! + +#### Fork this repository + +Fork this repository by clicking on the fork button on the top of [this](https://github.com/AllenShintani/Edison) page. +This will create a copy of this repository in your account `/`. + +#### Clone the repository + +Now clone the forked repository to your machine. Go to your GitHub account, open the forked repository, and copy the link provided under `HTTPS` when you click on the green button labeled `code` on the repository page + +Open a terminal and run the following git command: + +``` +git clone "url you just copied" +``` + +where "URL you just copied" (without quotation marks) is the URL to this repository (your fork of this project). + +For example: + +``` +git clone https://github.com/AllenShintani/Edison.git +``` + +#### Create a new branch for your changes or fix + + ```sh + $ git checkout -b + ``` + +#### Setup the project in your local by following the steps listed in the [README.md](https://github.com/AllenShintani/Edison/blob/master/README.md) file + +#### Open the project in a code editor and begin working on it +#### Add the contents of the changed files to the "snapshot" git uses to manage the state of the project, also known as the index + + ```sh + $ git add . + ``` + +#### Add a descriptive commit message + + ```sh + $ git commit -m "Insert a short message of the changes made here" + ``` + +#### Push the changes to the remote repository + + ```sh + $ git push -u origin + ``` + +#### Submit a pull request to the upstream repository diff --git a/README.md b/README.md index 78a805c..4354b85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- なんかいい感じの画像 + なんかいい感じの画像

@@ -8,9 +8,18 @@

Edison can control microcontroller board with TypeScript or JavaScript!

-

+

-

+ + GitHub stars + + +[![NPM +version](https://img.shields.io/npm/v/edison.svg?style=flat)](https://www.npmjs.com/package/edison) +[![NPM +downloads](https://img.shields.io/npm/dm/edison.svg?style=flat)](https://www.npmjs.com/package/edison) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/edison-js/Edison/blob/main/LICENSE) +
## Documentation diff --git a/global.d.ts b/global.d.ts index 543ccd4..e69de29 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,9 +0,0 @@ -import { Led } from "./src/types/LED"; -import { Sensor } from "./src/types/Sensor"; -import { ServoMotor } from "./src/types/ServoMotor"; - -// write here all pin mode -export type Output = Led | Sensor -export type Servo = ServoMotor - -export type Mode = 'Servo' | 'Output' | 'Input' | 'Pwm' ; \ No newline at end of file diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 7d59ced..0000000 --- a/jest.config.js +++ /dev/null @@ -1,5 +0,0 @@ -/** @type {import("ts-jest/dist/types").InitialOptionsTsJest} */ -module.exports = { - preset: "ts-jest", - testEnvironment: "node", -}; \ No newline at end of file diff --git a/package.json b/package.json index 511fe7e..bedd4b5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "dependencies": { + "@types/microtime": "^2.1.2", "@types/react": "^18.2.31", "@types/react-dom": "^18.2.14", "react": "^18.2.0", @@ -12,15 +13,20 @@ "devDependencies": { "@types/node": "^20.8.8", "@types/serialport": "^8.0.3", + "@typescript-eslint/eslint-plugin": "^6.18.1", "dotenv-cli": "^7.3.0", - "eslint": "^8.50.0", + "eslint": "^8.56.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", - "prettier": "^3.0.3" + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", + "prettier": "^3.0.3", + "vite-plugin-checker": "^0.6.2", + "vitest": "^0.34.6" }, "name": "edison", "type": "module", - "version": "0.1.31", + "version": "0.1.32", "exports": { ".": { "import": "./dist/esm/index.mjs", @@ -38,7 +44,9 @@ "build:cjs": "tsc -p tsconfig.cjs.json && node rename-to-cjs.cjs && node importEx-to-cjs.cjs", "build:esm": "tsc -p tsconfig.esm.json && node rename-to-esm.mjs", "build": "npm run build:cjs && npm run build:esm", - "test": "jest --coverage", + "lint": "npx eslint src/**/*.ts ", + "type-check": "tsc --noEmit", + "test": "vitest", "format": "prettier --write \"./src/**/*.{ts}\"" }, "repository": { diff --git a/src/__tests__/urils/board.test.ts b/src/__tests__/urils/board.test.ts new file mode 100644 index 0000000..08ea7fa --- /dev/null +++ b/src/__tests__/urils/board.test.ts @@ -0,0 +1,36 @@ +// // board.test.ts +// import { describe, it, expect, vi } from 'vitest' +// import type { SerialPort } from 'serialport' +// import { board } from '../../utils/board' +// import { findArduinoPath } from '../../utils/findArduinoPath' + +// // SerialPort と findArduinoPath のモック +// vi.mock('serialport', () => ({ +// SerialPort: vi.fn().mockImplementation(() => ({ +// on: vi.fn((event, callback) => { +// if (event === 'data') { +// // 'data' イベントのモック処理 +// setTimeout(() => callback('some data'), 0) +// } +// }), +// // 他の必要なメソッドもモック化 +// })), +// })) + +// vi.mock('../../utils/findArduinoPath', () => ({ +// findArduinoPath: vi.fn().mockResolvedValue('/dev/ttyUSB0'), +// })) + +// describe('board module', () => { +// it('should emit "ready" when Arduino is connected', async () => { +// ;(findArduinoPath as vi.Mock).mockResolvedValue('/dev/ttyUSB0') +// const mockSerialPortInstance = new SerialPort({ +// path: '/dev/ttyUSB0', +// baudRate: 57600, +// }) +// const readyListener = vi.fn() +// board.on('ready', readyListener) +// await board.connectAutomatic() +// expect(readyListener).toHaveBeenCalled() +// }) +// }) diff --git a/src/factory/analog/analogPort.ts b/src/factory/analog/analogPort.ts index f53becd..cf47688 100644 --- a/src/factory/analog/analogPort.ts +++ b/src/factory/analog/analogPort.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { setAnalogState } from '../../uniqueDevice/setAnalogState' import { AnalogPin, Sensor, analogPinMapping } from '../../types/analog/analog' import { Subscription } from 'rxjs' diff --git a/src/factory/analog/uniqueDevice/pressureSensor.ts b/src/factory/analog/uniqueDevice/pressureSensor.ts index 1d78416..b38fd67 100644 --- a/src/factory/analog/uniqueDevice/pressureSensor.ts +++ b/src/factory/analog/uniqueDevice/pressureSensor.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { AnalogPin, Sensor } from '../../../types/analog/analog' import { analogPort } from '../analogPort' @@ -19,11 +19,11 @@ export const attachPressureSensor = (port: SerialPort, pin: AnalogPin) => { } }) }, - onOver: async( + onOver: async ( method: Sensor, func: () => Promise | Promise | void | number, ): Promise => { - return - } + return + }, } } diff --git a/src/factory/complex/ultrasonicSensor.ts b/src/factory/complex/ultrasonicSensor.ts new file mode 100644 index 0000000..af0e587 --- /dev/null +++ b/src/factory/complex/ultrasonicSensor.ts @@ -0,0 +1,35 @@ +import { outputPort } from '../output/outputPort' +import { inputPort } from '../input/inputPort' +import { delay } from '../../index' +import type { SerialPort } from '../../index' +import type { Sensor } from '../../types/analog/analog' + +export const attachUltrasonicSensor = ( + port: SerialPort, + trigPin: number, + echoPin: number, +) => { + const trig = outputPort(port)(trigPin) + const echo = inputPort(port)(echoPin) + + return { + measure: async ( + method: Sensor, + func: () => Promise | Promise | void | number, + ): Promise => { + // echo.readを一度だけ呼び出し + await echo.read(method, async () => { + await func() + }) + + // 無限ループでTrigのon/offのみを繰り返す + while (true) { + //console.log('Trig') + await trig.on() // TrigピンをHIGHにする + await delay(20) + await trig.off() // TrigピンをLOWにする + await delay(20) // 次の測定までの待機時間 + } + }, + } +} diff --git a/src/factory/input/inputPort.ts b/src/factory/input/inputPort.ts index 9ddc10e..8295396 100644 --- a/src/factory/input/inputPort.ts +++ b/src/factory/input/inputPort.ts @@ -1,12 +1,15 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { setInputState } from '../../helper/Input/setInputState' import { Subscription } from 'rxjs' import { Sensor } from '../../types/analog/analog' +import microtime from 'microtime' export const inputPort = (port: SerialPort) => { return (pin: number) => { let subscription: Subscription let prevValue: boolean + // let startTime: number + // let endTime: number return { read: async ( @@ -16,6 +19,9 @@ export const inputPort = (port: SerialPort) => { const observable = setInputState(pin, port) subscription = observable.subscribe((value: boolean) => { + //console.log('value: ', value, 'prevValue: ', prevValue) + const currentTime = microtime.now() // 現在の時刻を取得 + if (typeof prevValue !== 'undefined') { // first emit will be skipped if (value && method === 'on') { @@ -25,9 +31,29 @@ export const inputPort = (port: SerialPort) => { func() } else if (method === 'change' && value !== prevValue) { // is value changed? - //console.log('change') func() } + /* + else if (method === 'sonic' && value !== prevValue) { + if (value && !prevValue) { + // EchoピンがLOWからHIGHに変わった瞬間 + startTime = currentTime + } else if (!value && prevValue) { + // EchoピンがHIGHからLOWに変わった瞬間 + endTime = currentTime + + // 時間差を計算(パルス幅) + const pulseWidth = endTime - startTime + console.log(`Pulse Width: ${pulseWidth} us`) + // 往復距離を半分にして距離を計算 + const distance = ((pulseWidth / 2) * 340 * 100) / 1000000 // 音速を340m/sに設定 + console.log(`Distance: ${distance} cm`) + + // funcに距離を渡す + //func(distance) + } + } + */ } prevValue = value }) diff --git a/src/factory/input/uniqueDevice/collisionSensor.ts b/src/factory/input/uniqueDevice/collisionSensor.ts index 079c595..f2d70a8 100644 --- a/src/factory/input/uniqueDevice/collisionSensor.ts +++ b/src/factory/input/uniqueDevice/collisionSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from '../../../index' import { Sensor } from '../../../types/analog/analog' export const attachCollisionSensor = (port: SerialPort, pin: number) => { diff --git a/src/factory/input/uniqueDevice/flameSensor.ts b/src/factory/input/uniqueDevice/flameSensor.ts index 809bf3f..c206370 100644 --- a/src/factory/input/uniqueDevice/flameSensor.ts +++ b/src/factory/input/uniqueDevice/flameSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachFlameSensor = (port: SerialPort, pin: number) => { // const flameSensor = inputPort(port)(pin) diff --git a/src/factory/input/uniqueDevice/hallEffectSensor.ts b/src/factory/input/uniqueDevice/hallEffectSensor.ts index d964889..e15408d 100644 --- a/src/factory/input/uniqueDevice/hallEffectSensor.ts +++ b/src/factory/input/uniqueDevice/hallEffectSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { Sensor } from '../../../types/analog/analog' export const attachHallEffectSensor = (port: SerialPort, pin: number) => { diff --git a/src/factory/input/uniqueDevice/infraredObstacleAvoidanceSensor.ts b/src/factory/input/uniqueDevice/infraredObstacleAvoidanceSensor.ts index a1ef036..f7753e9 100644 --- a/src/factory/input/uniqueDevice/infraredObstacleAvoidanceSensor.ts +++ b/src/factory/input/uniqueDevice/infraredObstacleAvoidanceSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachInfraredObstacleAvoidanceSensor = ( // port: SerialPort, diff --git a/src/factory/input/uniqueDevice/knockSensor.ts b/src/factory/input/uniqueDevice/knockSensor.ts index 06b071e..0d9e636 100644 --- a/src/factory/input/uniqueDevice/knockSensor.ts +++ b/src/factory/input/uniqueDevice/knockSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachKnockSensor = (port: SerialPort, pin: number) => { // const knockSensor = inputPort(port)(pin) diff --git a/src/factory/input/uniqueDevice/lineTracking.ts b/src/factory/input/uniqueDevice/lineTracking.ts index 6116b32..90a3f64 100644 --- a/src/factory/input/uniqueDevice/lineTracking.ts +++ b/src/factory/input/uniqueDevice/lineTracking.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachLineTracking = (port: SerialPort, pin: number) => { // const buzzer = inputPort(port)(pin) diff --git a/src/factory/input/uniqueDevice/photoInterrupter.ts b/src/factory/input/uniqueDevice/photoInterrupter.ts index eae1cf8..fe0ec94 100644 --- a/src/factory/input/uniqueDevice/photoInterrupter.ts +++ b/src/factory/input/uniqueDevice/photoInterrupter.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachPhotoInterrupter = (port: SerialPort, pin: number) => { // const photoInterrupter = inputPort(port)(pin) diff --git a/src/factory/input/uniqueDevice/pirMotionSensor.ts b/src/factory/input/uniqueDevice/pirMotionSensor.ts index b83f4ae..2380b37 100644 --- a/src/factory/input/uniqueDevice/pirMotionSensor.ts +++ b/src/factory/input/uniqueDevice/pirMotionSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachPirMorionSensor = (port: SerialPort, pin: number) => { // const PirmotionSensor = inputPort(port)(pin) diff --git a/src/factory/input/uniqueDevice/pushButton.ts b/src/factory/input/uniqueDevice/pushButton.ts index 0779719..70e4ab1 100644 --- a/src/factory/input/uniqueDevice/pushButton.ts +++ b/src/factory/input/uniqueDevice/pushButton.ts @@ -1,12 +1,18 @@ +import { Sensor } from '../../../types/analog/analog' import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' -// export const attachPushButton = (port: SerialPort, pin: number) => { -// const pushButton = inputPort(port)(pin) +export const attachButton = (port: SerialPort, pin: number) => { + const pushButton = inputPort(port)(pin) -// return { -// on: async () => { -// await pushButton.read() -// }, -// } -// } + return { + read: async ( + method: Sensor, + func: () => Promise | Promise | void | number, + ): Promise => { + return pushButton.read(method, async () => { + await func() + }) + }, + } +} diff --git a/src/factory/input/uniqueDevice/readSensor.ts b/src/factory/input/uniqueDevice/readSensor.ts index 9d6275c..7f2f150 100644 --- a/src/factory/input/uniqueDevice/readSensor.ts +++ b/src/factory/input/uniqueDevice/readSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachReadSensor = (port: SerialPort, pin: number) => { // const readSensor = inputPort(port)(pin) diff --git a/src/factory/input/uniqueDevice/tiltSensor.ts b/src/factory/input/uniqueDevice/tiltSensor.ts index b0f2bfd..044f785 100644 --- a/src/factory/input/uniqueDevice/tiltSensor.ts +++ b/src/factory/input/uniqueDevice/tiltSensor.ts @@ -1,5 +1,5 @@ import { inputPort } from '../inputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // export const attachTiltSensor = (port: SerialPort, pin: number) => { // const tiltSensor = inputPort(port)(pin) diff --git a/src/factory/output/outputPort.ts b/src/factory/output/outputPort.ts index bb8fd7b..5403300 100644 --- a/src/factory/output/outputPort.ts +++ b/src/factory/output/outputPort.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { setOutputState } from '../../helper/Output/setOutputState' import { setAnalogOutput } from '../../helper/Output/setAnalogOutput' diff --git a/src/factory/output/uniqueDevice/buzzer.ts b/src/factory/output/uniqueDevice/buzzer.ts index 31e3bb4..217802e 100644 --- a/src/factory/output/uniqueDevice/buzzer.ts +++ b/src/factory/output/uniqueDevice/buzzer.ts @@ -1,5 +1,5 @@ import { outputPort } from '../outputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const attachBuzzer = (port: SerialPort, pin: number) => { const buzzer = outputPort(port)(pin) diff --git a/src/factory/output/uniqueDevice/led.ts b/src/factory/output/uniqueDevice/led.ts index e62453f..b8e2caa 100644 --- a/src/factory/output/uniqueDevice/led.ts +++ b/src/factory/output/uniqueDevice/led.ts @@ -1,5 +1,5 @@ import { outputPort } from '../outputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { delay } from '../../../utils/delay' export const attachLed = (port: SerialPort, pin: number) => { diff --git a/src/factory/output/uniqueDevice/output.ts b/src/factory/output/uniqueDevice/output.ts index f8bee24..f930a2c 100644 --- a/src/factory/output/uniqueDevice/output.ts +++ b/src/factory/output/uniqueDevice/output.ts @@ -1,5 +1,5 @@ import { outputPort } from '../outputPort' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const attachOutput = (port: SerialPort, pin: number) => { const output = outputPort(port)(pin) diff --git a/src/factory/output/uniqueDevice/rgbLed.ts b/src/factory/output/uniqueDevice/rgbLed.ts index 8088b6c..90833b0 100644 --- a/src/factory/output/uniqueDevice/rgbLed.ts +++ b/src/factory/output/uniqueDevice/rgbLed.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { pwmPort } from '../../pwm/pwmPort' export const attachRgbLed = ( diff --git a/src/factory/pwm/pwmPort.ts b/src/factory/pwm/pwmPort.ts index d6faa05..b27ef3a 100644 --- a/src/factory/pwm/pwmPort.ts +++ b/src/factory/pwm/pwmPort.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { setPwmState } from '../../helper/PWM/setPwmState' export const pwmPort = (port: SerialPort) => { diff --git a/src/factory/pwm/uniqueDevice/passiveBuzzer.ts b/src/factory/pwm/uniqueDevice/passiveBuzzer.ts index 47d7c4d..dcb524d 100644 --- a/src/factory/pwm/uniqueDevice/passiveBuzzer.ts +++ b/src/factory/pwm/uniqueDevice/passiveBuzzer.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { pwmPort } from '../pwmPort' export const attachPassiveBuzzer = (port: SerialPort, pin: number) => { diff --git a/src/factory/pwm/uniqueDevice/vibrationSensor.ts b/src/factory/pwm/uniqueDevice/vibrationSensor.ts index 9a9e0f3..04ce55c 100644 --- a/src/factory/pwm/uniqueDevice/vibrationSensor.ts +++ b/src/factory/pwm/uniqueDevice/vibrationSensor.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { pwmPort } from '../pwmPort' export const attachVibrationSensor = (port: SerialPort, pin: number) => { diff --git a/src/factory/servo/servoPort.ts b/src/factory/servo/servoPort.ts index 46fb52f..b4a6a80 100644 --- a/src/factory/servo/servoPort.ts +++ b/src/factory/servo/servoPort.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { setPinToServo } from '../../helper/Servo/setPinToServo' import { setServoAngle } from '../../helper/Servo/setServoAngle' import { delay } from '../../utils/delay' diff --git a/src/factory/servo/uniqueDevice/servo.ts b/src/factory/servo/uniqueDevice/servo.ts index fe36e69..5d01ef5 100644 --- a/src/factory/servo/uniqueDevice/servo.ts +++ b/src/factory/servo/uniqueDevice/servo.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { servoPort } from '../servoPort' export const attachServo = (port: SerialPort, pin: number) => { diff --git a/src/helper/Analog/bufferAnalog.ts b/src/helper/Analog/bufferAnalog.ts index c3fbaf2..990e8aa 100644 --- a/src/helper/Analog/bufferAnalog.ts +++ b/src/helper/Analog/bufferAnalog.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const bufferAnalog = ( port: SerialPort, diff --git a/src/helper/Analog/setPinAnalog.ts b/src/helper/Analog/setPinAnalog.ts index cefc3cd..1037f35 100644 --- a/src/helper/Analog/setPinAnalog.ts +++ b/src/helper/Analog/setPinAnalog.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const setPinAnalog = (pin: number, port: SerialPort): Promise => { const SET_PIN_MODE = 0xf4 diff --git a/src/helper/Input/setInputState.ts b/src/helper/Input/setInputState.ts index ecedd91..34f329c 100644 --- a/src/helper/Input/setInputState.ts +++ b/src/helper/Input/setInputState.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { bufferWrite } from '../Utils/bufferWrite' import { Observable } from 'rxjs' @@ -23,13 +23,17 @@ export const setInputState = ( port.on('data', (data) => { // Check if the new data starts with 0x91 or 0x90, if so, reset the buffer - if (data.length > 0 && (data[0] === 0x91 || data[0] === 0x90)) { + if ( + data.length > 0 && + 4 > data.length && + (data[0] === 0x91 || data[0] === 0x90) + ) { buffer = data // Reset buffer with new data - } else { - buffer = Buffer.concat([buffer, data]) // Append new data to the existing buffer + } else if (4 > data.length) { + const dataToAppend = data.slice(0, 3) // dataToAppend is the new data + buffer = Buffer.concat([buffer, dataToAppend]) } - // Process complete messages in the buffer if ( ((buffer[0] === 0x90 && pin < 8) || (buffer[0] === 0x91 && pin >= 8)) && buffer.length === 3 diff --git a/src/helper/Input/setPinInput.ts b/src/helper/Input/setPinInput.ts index 2bdd110..ed86184 100644 --- a/src/helper/Input/setPinInput.ts +++ b/src/helper/Input/setPinInput.ts @@ -1,4 +1,4 @@ -// import { SerialPort } from 'serialport' +// import type { SerialPort } from 'serialport' // export const setPinInput = (pin: number, port: SerialPort): Promise => { // return new Promise((resolve, reject) => { diff --git a/src/helper/Output/setAnalogOutput.ts b/src/helper/Output/setAnalogOutput.ts index 05178ca..8d61aec 100644 --- a/src/helper/Output/setAnalogOutput.ts +++ b/src/helper/Output/setAnalogOutput.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { bufferWrite } from '../Utils/bufferWrite' export const setAnalogOutput = async ( diff --git a/src/helper/Output/setOutputState.ts b/src/helper/Output/setOutputState.ts index 51c541d..e157c54 100644 --- a/src/helper/Output/setOutputState.ts +++ b/src/helper/Output/setOutputState.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { setPinOutput } from './setPinOutput' import { bufferWrite } from '../Utils/bufferWrite' import { delay } from '../../utils/delay' diff --git a/src/helper/Output/setPinOutput.ts b/src/helper/Output/setPinOutput.ts index 689e224..9cda205 100644 --- a/src/helper/Output/setPinOutput.ts +++ b/src/helper/Output/setPinOutput.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const setPinOutput = (pin: number, port: SerialPort): Promise => { return new Promise((resolve, reject) => { diff --git a/src/helper/PWM/setPwmState.ts b/src/helper/PWM/setPwmState.ts index 7d623b4..388602f 100644 --- a/src/helper/PWM/setPwmState.ts +++ b/src/helper/PWM/setPwmState.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { bufferWrite } from '../Utils/bufferWrite' const SET_PIN_MODE = 0xf4 diff --git a/src/helper/Servo/setPinToServo.ts b/src/helper/Servo/setPinToServo.ts index 1cb3e99..08a1b36 100644 --- a/src/helper/Servo/setPinToServo.ts +++ b/src/helper/Servo/setPinToServo.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // Switch pin 9 to servo mode export const setPinToServo = (pin: number, port: SerialPort): Promise => { diff --git a/src/helper/Servo/setServoAngle.ts b/src/helper/Servo/setServoAngle.ts index 2128166..72b2ecb 100644 --- a/src/helper/Servo/setServoAngle.ts +++ b/src/helper/Servo/setServoAngle.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // Set servo angle on Arduino export const setServoAngle = ( diff --git a/src/helper/Utils/bufferWrite.ts b/src/helper/Utils/bufferWrite.ts index 45c480e..fd3e342 100644 --- a/src/helper/Utils/bufferWrite.ts +++ b/src/helper/Utils/bufferWrite.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const bufferWrite = ( port: SerialPort, diff --git a/src/index.ts b/src/index.ts index fc89423..25e6451 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,12 +3,13 @@ export { attachLed } from './factory/output/uniqueDevice/led' export { attachBuzzer } from './factory/output/uniqueDevice/buzzer' export { attachPressureSensor } from './factory/analog/uniqueDevice/pressureSensor' export { attachServo } from './factory/servo/uniqueDevice/servo' -//export { attachUltrasonicSensor } from './factory/input/uniqueDevice/ultrasonicSensor' +//export { attachUltrasonicSensor } from './factory/complex/ultrasonicSensor' export { attachRgbLed } from './factory/output/uniqueDevice/rgbLed' export { attachCollisionSensor } from './factory/input/uniqueDevice/collisionSensor' //export { attachLineTracking } from './factory/input/uniqueDevice/lineTracking' export { attachOutput } from './factory/output/uniqueDevice/output' export { attachHallEffectSensor } from './factory/input/uniqueDevice/hallEffectSensor' +export { attachButton } from './factory/input/uniqueDevice/pushButton' //export { attachInfraredObstacleAvoidanceSensor } from './factory/input/uniqueDevice/infraredObstacleAvoidanceSensor' export { delay } from './utils/delay' export { SerialPort } from 'serialport' diff --git a/src/test/Buzzer.ts b/src/test/Buzzer.ts index c085a07..284b15b 100644 --- a/src/test/Buzzer.ts +++ b/src/test/Buzzer.ts @@ -1,6 +1,6 @@ import { board } from '../utils/board' import { attachBuzzer } from '../factory/output/uniqueDevice/buzzer' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' board.on('ready', (port: SerialPort) => { //console.log('Board is ready!') diff --git a/src/test/CollisionSensor.ts b/src/test/CollisionSensor.ts index 74e6648..7f1c2b0 100644 --- a/src/test/CollisionSensor.ts +++ b/src/test/CollisionSensor.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from '../index' import { attachCollisionSensor } from '../factory/input/uniqueDevice/collisionSensor' import { attachLed } from '../factory/output/uniqueDevice/led' import { board } from '../utils/board' diff --git a/src/test/FlameSensor.ts b/src/test/FlameSensor.ts index da2f144..c6e4630 100644 --- a/src/test/FlameSensor.ts +++ b/src/test/FlameSensor.ts @@ -1,5 +1,5 @@ // import { board } from '../utils/board' -// import { SerialPort } from 'serialport' +// import type { SerialPort } from 'serialport' // import { attachTiltSensor } from '../factory/input/uniqueDevice/tiltSensor' // board.connectManual('/dev/ttyUSB0') diff --git a/src/test/HallEffectSensor.ts b/src/test/HallEffectSensor.ts index 47bb353..d21518e 100644 --- a/src/test/HallEffectSensor.ts +++ b/src/test/HallEffectSensor.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { attachLed } from '../factory/output/uniqueDevice/led' import { board } from '../utils/board' import { attachHallEffectSensor } from '../factory/input/uniqueDevice/hallEffectSensor' diff --git a/src/test/InfraredObstacleAvoidanceSensor.ts b/src/test/InfraredObstacleAvoidanceSensor.ts index a4a9248..733be70 100644 --- a/src/test/InfraredObstacleAvoidanceSensor.ts +++ b/src/test/InfraredObstacleAvoidanceSensor.ts @@ -1,5 +1,5 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' // import { attachInfraredObstacleAvoidanceSensor } from '../factory/input/uniqueDevice/infraredObstacleAvoidanceSensor' // board.connectManual('/dev/ttyUSB0') diff --git a/src/test/KnockSensor.ts b/src/test/KnockSensor.ts index 904569b..db82883 100644 --- a/src/test/KnockSensor.ts +++ b/src/test/KnockSensor.ts @@ -1,11 +1,11 @@ -import { board } from '../utils/board' -// import { SerialPort } from 'serialport' -// import { attachKnockSensor } from '../factory/input/uniqueDevice/knockSensor' +// import { board } from '../utils/board' +// // import type { SerialPort } from 'serialport' +// // import { attachKnockSensor } from '../factory/input/uniqueDevice/knockSensor' -// board.connectManual('/dev/ttyUSB0') +// // board.connectManual('/dev/ttyUSB0') -// board.on('ready', async (port: SerialPort) => { -// console.log('Board is ready!') -// const knockSensor = attachKnockSensor(port, 12) -// await knockSensor.on() -// }) +// // board.on('ready', async (port: SerialPort) => { +// // console.log('Board is ready!') +// // const knockSensor = attachKnockSensor(port, 12) +// // await knockSensor.on() +// // }) diff --git a/src/test/Led.ts b/src/test/Led.ts index 840fdba..ec8600c 100644 --- a/src/test/Led.ts +++ b/src/test/Led.ts @@ -1,6 +1,6 @@ import { board } from '../utils/board' import { attachLed } from '../factory/output/uniqueDevice/led' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' board.connectManual('/dev/ttyUSB0') diff --git a/src/test/LineTracking.ts b/src/test/LineTracking.ts index 6240b37..9c0b7f4 100644 --- a/src/test/LineTracking.ts +++ b/src/test/LineTracking.ts @@ -1,11 +1,11 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' -// import { attachLineTracking } from '../factory/input/uniqueDevice/lineTracking' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' +// // import { attachLineTracking } from '../factory/input/uniqueDevice/lineTracking' -// board.connectManual('/dev/ttyUSB0') +// // board.connectManual('/dev/ttyUSB0') -// board.on('ready', (port: SerialPort) => { -// console.log('Board is ready!') -// const lineTracking = attachLineTracking(port, 12) -// lineTracking.on() -// }) +// // board.on('ready', (port: SerialPort) => { +// // console.log('Board is ready!') +// // const lineTracking = attachLineTracking(port, 12) +// // lineTracking.on() +// // }) diff --git a/src/test/Output.ts b/src/test/Output.ts index 98f78ce..2e8e61f 100644 --- a/src/test/Output.ts +++ b/src/test/Output.ts @@ -1,6 +1,6 @@ import { attachOutput } from '../factory/output/uniqueDevice/output' import { board } from '../utils/board' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' board.connectManual('/dev/ttyUSB0') diff --git a/src/test/PIRMotionSensor.ts b/src/test/PIRMotionSensor.ts index d9b6e93..353f771 100644 --- a/src/test/PIRMotionSensor.ts +++ b/src/test/PIRMotionSensor.ts @@ -1,11 +1,11 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' -// import { attachPirMorionSensor } from '../factory/input/uniqueDevice/pirMotionSensor' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' +// // import { attachPirMorionSensor } from '../factory/input/uniqueDevice/pirMotionSensor' -// board.connectManual('/dev/ttyUSB0') +// // board.connectManual('/dev/ttyUSB0') -// board.on('ready', async (port: SerialPort) => { -// console.log('Board is ready!') -// const pirMotionSensor = attachPirMorionSensor(port, 12) -// await pirMotionSensor.on() -// }) +// // board.on('ready', async (port: SerialPort) => { +// // console.log('Board is ready!') +// // const pirMotionSensor = attachPirMorionSensor(port, 12) +// // await pirMotionSensor.on() +// // }) diff --git a/src/test/PassiveBuzzer.ts b/src/test/PassiveBuzzer.ts index bc6ffc7..c5635c7 100644 --- a/src/test/PassiveBuzzer.ts +++ b/src/test/PassiveBuzzer.ts @@ -1,5 +1,5 @@ import { board } from '../utils/board' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { delay } from '../utils/delay' import { attachPassiveBuzzer } from '../factory/pwm/uniqueDevice/passiveBuzzer' diff --git a/src/test/PhotoInterrupter.ts b/src/test/PhotoInterrupter.ts index 9b5e82b..1ade992 100644 --- a/src/test/PhotoInterrupter.ts +++ b/src/test/PhotoInterrupter.ts @@ -1,5 +1,5 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' // import { attachPhotoInterrupter } from '../factory/input/uniqueDevice/photoInterrupter' // board.connectManual('/dev/ttyUSB0') diff --git a/src/test/RGBLed.ts b/src/test/RGBLed.ts index 1bc6f62..330924e 100644 --- a/src/test/RGBLed.ts +++ b/src/test/RGBLed.ts @@ -1,6 +1,6 @@ import { board } from '../utils/board' import { attachRgbLed } from '../factory/output/uniqueDevice/rgbLed' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' board.connectManual('/dev/ttyUSB0') diff --git a/src/test/ReadSensor.ts b/src/test/ReadSensor.ts index 2ff44f2..f619045 100644 --- a/src/test/ReadSensor.ts +++ b/src/test/ReadSensor.ts @@ -1,11 +1,11 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' -// import { attachReadSensor } from '../factory/input/uniqueDevice/readSensor' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' +// // import { attachReadSensor } from '../factory/input/uniqueDevice/readSensor' -// board.connectManual('/dev/ttyUSB0') +// // board.connectManual('/dev/ttyUSB0') -// board.on('ready', async (port: SerialPort) => { -// console.log('Board is ready!') -// const readSensor = attachReadSensor(port, 12) -// await readSensor.on() -// }) +// // board.on('ready', async (port: SerialPort) => { +// // console.log('Board is ready!') +// // const readSensor = attachReadSensor(port, 12) +// // await readSensor.on() +// // }) diff --git a/src/test/Servo.ts b/src/test/Servo.ts index aaddf6e..ca95172 100644 --- a/src/test/Servo.ts +++ b/src/test/Servo.ts @@ -1,6 +1,6 @@ import { board } from '../utils/board' import { attachServo } from '../factory/servo/uniqueDevice/servo' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' board.on('ready', async (port: SerialPort) => { //console.log('Board is ready!') diff --git a/src/test/TempertureSensor.ts b/src/test/TempertureSensor.ts index 80f7987..cdd4b4e 100644 --- a/src/test/TempertureSensor.ts +++ b/src/test/TempertureSensor.ts @@ -1,6 +1,6 @@ import { board } from '../utils/board' import { attachPressureSensor } from '../factory/analog/uniqueDevice/pressureSensor' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { attachLed } from '../factory/output/uniqueDevice/led' board.on('ready', (port: SerialPort) => { diff --git a/src/test/TiltSensor.ts b/src/test/TiltSensor.ts index 544fc94..e508d8e 100644 --- a/src/test/TiltSensor.ts +++ b/src/test/TiltSensor.ts @@ -1,5 +1,5 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' // import { attachTiltSensor } from '../factory/input/uniqueDevice/tiltSensor' // board.connectManual('/dev/ttyUSB0') diff --git a/src/test/Vibration.ts b/src/test/Vibration.ts index 581c265..2312ccc 100644 --- a/src/test/Vibration.ts +++ b/src/test/Vibration.ts @@ -1,5 +1,5 @@ import { board } from '../utils/board' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { delay } from '../utils/delay' import { attachVibrationSensor } from '../factory/pwm/uniqueDevice/vibrationSensor' diff --git a/src/test/pressureSensor.ts b/src/test/pressureSensor.ts index 80f7987..cdd4b4e 100644 --- a/src/test/pressureSensor.ts +++ b/src/test/pressureSensor.ts @@ -1,6 +1,6 @@ import { board } from '../utils/board' import { attachPressureSensor } from '../factory/analog/uniqueDevice/pressureSensor' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { attachLed } from '../factory/output/uniqueDevice/led' board.on('ready', (port: SerialPort) => { diff --git a/src/test/pushButton.ts b/src/test/pushButton.ts index b406cc9..05e7208 100644 --- a/src/test/pushButton.ts +++ b/src/test/pushButton.ts @@ -1,5 +1,5 @@ -import { board } from '../utils/board' -import { SerialPort } from 'serialport' +// import { board } from '../utils/board' +// import type { SerialPort } from 'serialport' // import { attachPushButton } from '../factory/input/uniqueDevice/pushButton' // board.connectManual('/dev/ttyUSB0') diff --git a/src/test/ultrasonicSensor.ts b/src/test/ultrasonicSensor.ts index faf2238..7edd54f 100644 --- a/src/test/ultrasonicSensor.ts +++ b/src/test/ultrasonicSensor.ts @@ -1,10 +1,14 @@ -// import { board } from '../utils/board' -// import { attachUltrasonicSensor } from '../factory/input/uniqueDevice/ultrasonicSensor' -// import { SerialPort } from 'serialport' +import { board } from '../utils/board' +import { attachUltrasonicSensor } from '../factory/complex/ultrasonicSensor' +import type { SerialPort } from '../index' -// board.on('ready', async (port: SerialPort) => { -// console.log('Board is ready!') -// const ultrasonicSensor = attachUltrasonicSensor(port, 2) -// const val: number = await ultrasonicSensor.measure() -// console.log(val) -// }) +board.on('ready', async (port: SerialPort) => { + console.log('Board is ready!') + //const led1 = attachBuzzer(port, 12) + const ultrasonicSensor = attachUltrasonicSensor(port, 3, 2) + console.log( + ultrasonicSensor.measure('on', () => { + console.log('ooooooooooooooooooooooooooooooooooooooooooo') + }), + ) +}) diff --git a/src/tsxTest/Board.tsx b/src/tsxTest/Board.tsx index 38cb9cf..8ba7926 100644 --- a/src/tsxTest/Board.tsx +++ b/src/tsxTest/Board.tsx @@ -1,7 +1,7 @@ // Board.tsx import React, { useEffect, useState, createContext, ReactNode } from 'react' import { board } from '../utils/board' -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' export const BoardContext = createContext(null) diff --git a/src/types/analog/analog.ts b/src/types/analog/analog.ts index d961135..b232d59 100644 --- a/src/types/analog/analog.ts +++ b/src/types/analog/analog.ts @@ -18,4 +18,4 @@ export const analogPinMapping: AnalogpinMapping = { A5: 5, } -export type Sensor = 'on' | 'off' | 'change' +export type Sensor = 'on' | 'off' | 'change' | 'sonic' diff --git a/src/uniqueDevice/prettierChange.ts b/src/uniqueDevice/prettierChange.ts index 0b7bdd2..5656caf 100644 --- a/src/uniqueDevice/prettierChange.ts +++ b/src/uniqueDevice/prettierChange.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { bufferAnalog } from '../helper/Analog/bufferAnalog' import { Observable } from 'rxjs' diff --git a/src/uniqueDevice/setAnalogState.ts b/src/uniqueDevice/setAnalogState.ts index 39c014e..73a476d 100644 --- a/src/uniqueDevice/setAnalogState.ts +++ b/src/uniqueDevice/setAnalogState.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { bufferAnalog } from '../helper/Analog/bufferAnalog' import { Observable } from 'rxjs' diff --git a/src/utils/board.ts b/src/utils/board.ts index 076468f..5676c0c 100644 --- a/src/utils/board.ts +++ b/src/utils/board.ts @@ -16,7 +16,7 @@ const connectAutomatic = async () => { // console.log('Arduino path: ', arduinoPath) const port = new SerialPort({ path: arduinoPath, baudRate: 57600 }) - port.on('data', (data) => { + port.on('data', (/*data*/) => { // console.log('Data received!: ', data) if (!isReadyEmitted) { boardEmitter.emit('ready', port) @@ -29,7 +29,7 @@ const connectManual = (arduinoPath: string) => { // console.log('Arduino path: ', arduinoPath) const port = new SerialPort({ path: arduinoPath, baudRate: 57600 }) - port.on('data', (data) => { + port.on('data', (/*data*/) => { // console.log('Data received!: ', data) if (!isReadyEmitted) { boardEmitter.emit('ready', port) @@ -44,5 +44,4 @@ export const board = { connectManual, } -// connectAutomatic() diff --git a/src/utils/findArduinoPath.ts b/src/utils/findArduinoPath.ts index aeed855..708be52 100644 --- a/src/utils/findArduinoPath.ts +++ b/src/utils/findArduinoPath.ts @@ -5,7 +5,7 @@ export const findArduinoPath = async (): Promise => { const ports = await SerialPort.list() for (const port of ports) { // console.log(port) - if (port.manufacturer && port.manufacturer.includes('Arduino')) { + if (port.manufacturer?.includes('Arduino')) { ////console.log(2) // console.log('Arduino found at: ', port.path) return port.path diff --git a/src/utils/portClose.ts b/src/utils/portClose.ts index 365d98e..c7ca0d9 100644 --- a/src/utils/portClose.ts +++ b/src/utils/portClose.ts @@ -1,4 +1,4 @@ -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' // This function closes the serial port. Console will be closed. export const portClose = (port: SerialPort): Promise => { diff --git a/src/utils/portOpen.ts b/src/utils/portOpen.ts index 65dc860..cfd1009 100644 --- a/src/utils/portOpen.ts +++ b/src/utils/portOpen.ts @@ -1,6 +1,6 @@ import { SerialPort } from 'serialport' -export const portOpen = (path: string): SerialPort => { +export const portOpen = (path: string): SerialPort => { const port = new SerialPort({ path, baudRate: 57600 }) return port } diff --git a/src/utils/setup.ts b/src/utils/setup.ts index d739d15..ca78662 100644 --- a/src/utils/setup.ts +++ b/src/utils/setup.ts @@ -1,5 +1,5 @@ /* -import { SerialPort } from 'serialport' +import type { SerialPort } from 'serialport' import { findArduinoPath } from './findArduinoPath' import { outputPort } from '../factory/output/outputPort' import { servoPort } from '../factory/servo/servoPort' diff --git a/vite-env.d.ts b/vite-env.d.ts new file mode 100644 index 0000000..6cedb90 --- /dev/null +++ b/vite-env.d.ts @@ -0,0 +1,4 @@ +declare const __APP_VERSION__: string +declare const __APP_NAME__: string +declare const __APP_DESCRIPTION__: string +declare const __APP_AUTHOR__: string diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..b1c6ea4 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1 @@ +export default {}