forked from jacobrosenthal/js-stk500v1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: initial setup * refactor: update examples to use async/await * refactor: rename index.js to index.ts and add TypeScript typings for STK500 class * refactor: lib files to TypeScript * refactor: update uno.js to use async/await * refactor: rename example files to TypeScript, changed ts runner * refactor: remove allowJs option from tsconfig.json after migration * chore: add .npmignore, updated copyright * chore: add GitHub Actions workflow for quality checks
- Loading branch information
1 parent
a255983
commit 451fc57
Showing
25 changed files
with
1,053 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Quality | ||
|
||
on: pull_request | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref_name }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# lint: | ||
# name: Linting rules | ||
# runs-on: ubuntu-latest | ||
|
||
# steps: | ||
# - name: Checkout | ||
# uses: actions/checkout@v4 | ||
|
||
# - name: Setup Node.js | ||
# uses: actions/setup-node@v4 | ||
# with: | ||
# node-version-file: .nvmrc | ||
|
||
# - name: Install dependencies | ||
# run: npm ci | ||
|
||
# - name: Linting rules | ||
# run: npm run lint | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
test: | ||
name: Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run test suite | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!dist | ||
!package.json | ||
!README.md | ||
!LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from "fs/promises"; | ||
import { SerialPort } from "serialport"; | ||
import intel_hex from "intel-hex"; | ||
import Stk500 from "../src/index.js"; | ||
|
||
const stk = new Stk500(); | ||
|
||
const board = { | ||
name: "ATmega4809", | ||
baud: 19200, | ||
signature: Buffer.from([0x1e, 0x94, 0x06]), | ||
pageSize: 128, | ||
timeout: 400, | ||
}; | ||
|
||
async function readHexFile(filePath) { | ||
const data = await fs.readFile(filePath, { encoding: "utf8" }); | ||
return intel_hex.parse(data).data; | ||
} | ||
|
||
function createSerialPort(path, baudRate) { | ||
return new Promise((resolve, reject) => { | ||
const serialPort = new SerialPort({ path, baudRate }); | ||
serialPort.on("open", () => resolve(serialPort)); | ||
serialPort.on("error", reject); | ||
}); | ||
} | ||
|
||
async function closeSerialPort(serialPort) { | ||
return new Promise<void>((resolve) => { | ||
serialPort.close((error) => { | ||
if (error) console.log(error); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
async function upload(path) { | ||
let serialPort; | ||
try { | ||
const hex = await readHexFile("arduino-1.0.6/168/avr4809.cpp.hex"); | ||
serialPort = await createSerialPort(path, board.baud); | ||
await stk.bootload(serialPort, hex, board, false); | ||
console.log("Programming SUCCESS!"); | ||
} catch (error) { | ||
console.error("Programming failed:", error); | ||
} finally { | ||
if (serialPort) { | ||
await closeSerialPort(serialPort); | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
if (process.argv[2]) { | ||
await upload(process.argv[2]); | ||
} else { | ||
console.log("Call with a path like /dev/tty.something"); | ||
} | ||
process.exit(0); | ||
} | ||
|
||
main().catch(console.error); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from "fs/promises"; | ||
import { SerialPort } from "serialport"; | ||
import intel_hex from "intel-hex"; | ||
import Stk500 from "../src/index.js"; | ||
|
||
const stk = new Stk500(); | ||
|
||
const board = { | ||
name: "Diecimila / Duemilanove 168", | ||
baud: 19200, | ||
signature: Buffer.from([0x1e, 0x94, 0x06]), | ||
pageSize: 128, | ||
timeout: 400, | ||
}; | ||
|
||
async function readHexFile(filePath) { | ||
const data = await fs.readFile(filePath, { encoding: "utf8" }); | ||
return intel_hex.parse(data).data; | ||
} | ||
|
||
function createSerialPort(path, baudRate) { | ||
return new Promise((resolve, reject) => { | ||
const serialPort = new SerialPort({ path, baudRate }); | ||
serialPort.on("open", () => resolve(serialPort)); | ||
serialPort.on("error", reject); | ||
}); | ||
} | ||
|
||
async function closeSerialPort(serialPort) { | ||
return new Promise<void>((resolve) => { | ||
serialPort.close((error) => { | ||
if (error) console.log(error); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
async function upload(path) { | ||
let serialPort; | ||
try { | ||
const hex = await readHexFile("arduino-1.0.6/168/StandardFirmata.cpp.hex"); | ||
serialPort = await createSerialPort(path, board.baud); | ||
await stk.bootload(serialPort, hex, board, false); | ||
console.log("Programming SUCCESS!"); | ||
} catch (error) { | ||
console.error("Programming failed:", error); | ||
} finally { | ||
if (serialPort) { | ||
await closeSerialPort(serialPort); | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
if (process.argv[2]) { | ||
await upload(process.argv[2]); | ||
} else { | ||
console.log("Call with a path like /dev/tty.something"); | ||
} | ||
process.exit(0); | ||
} | ||
|
||
main().catch(console.error); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.