Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec committed Jun 29, 2024
1 parent 9173579 commit f3d1ce2
Show file tree
Hide file tree
Showing 18 changed files with 743 additions and 673 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tmp
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": ["oclif", "oclif-typescript", "prettier"],
"rules": {
"complexity": ["warn", 25],
"unicorn/numeric-separators-style": "off",
"unicorn/prefer-event-target": "off",
"no-bitwise": "off",
Expand Down
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import oclifPrettierConfig from "@oclif/prettier-config";

export default {
...oclifPrettierConfig,
singleQuote: true,
printWidth: 150,
bracketSpacing: true,
endOfLine: "auto",
tabWidth: 4
};
1 change: 0 additions & 1 deletion .prettierrc.json

This file was deleted.

17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"eslint-config-prettier": "^9",
"mocha": "^10",
"oclif": "^4",
"prettier": "^3.3.2",
"shx": "^0.3.3",
"ts-node": "^10",
"typescript": "^5"
Expand Down
36 changes: 19 additions & 17 deletions src/commands/bootloader/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { input, select } from '@inquirer/prompts'
import {Command, Flags} from '@oclif/core'
import { Command, Flags } from '@oclif/core'
import { Presets, SingleBar } from 'cli-progress'
import { readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
Expand Down Expand Up @@ -110,26 +110,27 @@ const FIRMWARE_LINKS: Record<FirmwareVersion, Record<AdapterModel, FirmwareMetad
}

export default class Bootloader extends Command {
static override args = {
}
static override args = {}

static override description = 'Interact with the Gecko bootloader in the adapter via serial.'

static override examples = [
'<%= config.bin %> <%= command.id %>',
]
static override examples = ['<%= config.bin %> <%= command.id %>']

static override flags = {
file: Flags.file({ char: 'f', description: 'Path to a firmware file. If not provided, will be set via interactive prompt when entering relevant menu.', exists: true }),
file: Flags.file({
char: 'f',
description: 'Path to a firmware file. If not provided, will be set via interactive prompt when entering relevant menu.',
exists: true,
}),
forceReset: Flags.boolean({ char: 'r', default: false, description: 'Try to force reset into bootloader.' }),
}

public async run(): Promise<void> {
const {flags} = await this.parse(Bootloader)
const portConf = await getPortConf(true/* no TCP */)
const { flags } = await this.parse(Bootloader)
const portConf = await getPortConf(true /* no TCP */)
logger.debug(`Using port conf: ${JSON.stringify(portConf)}`)

const adapterModelChoices: { name: string, value: AdapterModel | undefined }[] = [{ name: 'Not in this list', value: undefined }]
const adapterModelChoices: { name: string; value: AdapterModel | undefined }[] = [{ name: 'Not in this list', value: undefined }]

for (const k of Object.keys(FIRMWARE_LINKS.recommended)) {
adapterModelChoices.push({ name: k, value: k as AdapterModel })
Expand All @@ -141,10 +142,7 @@ export default class Bootloader extends Command {
})

const gecko = new GeckoBootloader(portConf, adapterModel)
const progressBar = new SingleBar(
{ clearOnComplete: true, format: '{bar} {percentage}%' },
Presets.shades_classic
)
const progressBar = new SingleBar({ clearOnComplete: true, format: '{bar} {percentage}%' }, Presets.shades_classic)

gecko.on(BootloaderEvent.FAILED, () => {
this.exit(1)
Expand All @@ -166,7 +164,7 @@ export default class Bootloader extends Command {
progressBar.update(percent)
})

await gecko.connect(this, flags.forceReset)
await gecko.connect(flags.forceReset)

let exit: boolean = false

Expand Down Expand Up @@ -219,7 +217,7 @@ export default class Bootloader extends Command {
let validFirmware: FirmwareValidation = FirmwareValidation.INVALID

while (validFirmware !== FirmwareValidation.VALID) {
firmware = (firmwareFile === undefined) ? (await this.selectFirmware(gecko)) : readFileSync(firmwareFile)
firmware = firmwareFile === undefined ? await this.selectFirmware(gecko) : readFileSync(firmwareFile)

validFirmware = await gecko.validateFirmware(firmware, SUPPORTED_VERSIONS_REGEX, expectedBaudRate)

Expand All @@ -235,7 +233,11 @@ export default class Bootloader extends Command {
private async selectFirmware(gecko: GeckoBootloader): Promise<Buffer> {
const firmwareSource = await select<FirmwareSource>({
choices: [
{ name: 'Use pre-defined firmware (recommended or latest based on your adapter)', value: FirmwareSource.PRE_DEFINED, disabled: (gecko.adapterModel === undefined)},
{
name: 'Use pre-defined firmware (recommended or latest based on your adapter)',
value: FirmwareSource.PRE_DEFINED,
disabled: gecko.adapterModel === undefined,
},
{ name: 'Provide URL', value: FirmwareSource.URL },
{ name: `Select file in data folder (${DATA_FOLDER})`, value: FirmwareSource.DATA_FOLDER },
],
Expand Down
Loading

0 comments on commit f3d1ce2

Please sign in to comment.