Skip to content

Commit

Permalink
Merge pull request #58 from AllenShintani/master
Browse files Browse the repository at this point in the history
CI bug fixed
  • Loading branch information
AllenShintani authored Jan 10, 2024
2 parents bea4d58 + 626ead8 commit caf6f60
Show file tree
Hide file tree
Showing 80 changed files with 376 additions and 161 deletions.
13 changes: 2 additions & 11 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"],
},
}
17 changes: 17 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"semi": false,
"quoteProps": "consistent",
"jsxBracketSameLine": false,
"singleAttributePerLine": true
"singleAttributePerLine": true,
"braceStyle": "stroustrup"
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true,
Expand Down
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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 `<your-GitHub-username>/<repository-name>`.

#### 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 <branch-name>
```

#### 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 <branch-name>
```

#### Submit a pull request to the upstream repository
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<p align="center">

<img width="300px" src="/public/images/icon.png" alt ="なんかいい感じの画像">
<img width="300px" src="/public/images/icon.png" alt="なんかいい感じの画像">

</p>

<h1 align="center">Edison</h1>

<p align="center">Edison can control microcontroller board with TypeScript or JavaScript!</p>

<p align="center">
<div align="center">

</p>
<a href="https://github.com/edison-js/Edison/stargazers">
<img src="https://img.shields.io/github/stars/edison-js/Edison" alt="GitHub stars">
</a>

[![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)
</div>

## Documentation

Expand Down
9 changes: 0 additions & 9 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -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' ;
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/urils/board.test.ts
Original file line number Diff line number Diff line change
@@ -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()
// })
// })
2 changes: 1 addition & 1 deletion src/factory/analog/analogPort.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
8 changes: 4 additions & 4 deletions src/factory/analog/uniqueDevice/pressureSensor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SerialPort } from 'serialport'
import type { SerialPort } from 'serialport'
import { AnalogPin, Sensor } from '../../../types/analog/analog'
import { analogPort } from '../analogPort'

Expand All @@ -19,11 +19,11 @@ export const attachPressureSensor = (port: SerialPort, pin: AnalogPin) => {
}
})
},
onOver: async(
onOver: async (
method: Sensor,
func: () => Promise<void> | Promise<number> | void | number,
): Promise<void> => {
return
}
return
},
}
}
35 changes: 35 additions & 0 deletions src/factory/complex/ultrasonicSensor.ts
Original file line number Diff line number Diff line change
@@ -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<void> | Promise<number> | void | number,
): Promise<void> => {
// 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) // 次の測定までの待機時間
}
},
}
}
Loading

0 comments on commit caf6f60

Please sign in to comment.