npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@duinoapp/upload-multitool

v0.0.3

Published

Micro Controller Uploading Multitool

Downloads

71

Readme

upload-multitool

WIP: This project is currently a work in progress

A modern tool for uploading to micro controllers like Arduinos and ESP devices, written in typescript with automated tests.

Project Objectives

This project aims to achieve the following:

  • Production ready
    • Written in TypeScript
    • Automated testing against real devices
  • Browser friendly
    • SerialPort Agnostic (connection is passed through)
    • Small bundle size?
  • Developer Friendly
    • Promises
    • Linting
    • Documentation
    • Modern development practices
  • Board Variety
    • Support most arduino protocols
    • Support ESP devices
    • Platform for easy addition of new protocols

Usage

install your favourite way

npm install @duinoapp/upload-multitool
yarn add @duinoapp/upload-multitool
pnpm add @duinoapp/upload-multitool

This package exports a few utilities, the main one is upload

import { upload } from '@duinoapp/upload-multitool';
import type { ProgramConfig } from '@duinoapp/upload-multitool';
import { SerialPort } from 'serialport';

const serialport = new SerialPort({ path: '/dev/example', baudRate: 115200 });

const config = {
  // for avr boards, the compiled hex
  bin: compiled.hex,
  // for esp boards, the compiled files and flash settings
  files: compiled.files,
  flashFreq: compiled.flashFreq,
  flashMode: compiled.flashMode,
  // baud rate to connect to bootloader
  speed: 115200,
  // baud rate to use for upload (ESP)
  uploadSpeed: 115200,
  // the tool to use, avrdude or esptool
  tool: 'avr',
  // the CPU of the device
  cpu: 'atmega328p',
  // a standard out interface ({ write(msg: string): void })
  stdout: process.stdout,
  // whether or not to log to stdout verbosely
  verbose: true,
  // handle reconnecting to AVR109 devices when connecting to the bootloader
  // the device ID changes for the bootloader, meaning in some OS's a new connection is required
  // avr109Reconnect?: (opts: ReconnectParams) => Promise<SerialPort>;
} as ProgramConfig;

const res = await upload(serial.port, config);

If you want to programmatically check if a tool/cpu is supported:

import { isSupported } from '@duinoapp/upload-multitool';

console.log(isSupported('avr', 'atmega328p')); // true

Also exports some helpful utilities:

import { WebSerialPort, SerialPortPromise, WebSerialPortPromise } from '@duinoapp/upload-multitool';

// WebSerialPort is a drop-in web replacement for serialport, with some useful static methods:

// Check whether the current browser supports the Web Serial API
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API#browser_compatibility
WebSerialPort.isSupported() // true/false

// request a serial connection from the user,
// first param takes requestPort options: https://developer.mozilla.org/en-US/docs/Web/API/Serial/requestPort#parameters
// second params takes the default open options 
const serialport = WebSerialPort.requestPort({}, { baudRate: 115200 });
serialport.open((err) => {
  if (!err) serialport.write('hello', (err2) => ...)
});

// get a list of the serial connections that have already been requested:
const list = WebSerialPort.list();

// A wrapper util around SerialPort that exposes the same methods but with promises
const serial = new SerialPortPromise(await WebSerialPort.requestPort());
await serial.open();
await serial.write('hello');

// A Merged class of both WebSerialPort and SerialPortPromise, probably use this one
const serial = WebSerialPortPromise.requestPort();
await serial.open();
await serial.write('hello');

Upload return

The upload function will return an object:

{
  // the time it took to complete the upload
  time: number
  // the final serial port used. In most cases the serial port passes in
  // if you pass in a non promise port, internally it will wrap with SerialPortPromise
  // if you pass in a promise port, it is likely the same object, you can check with the serialport.key value on SerialPortPromise
  // if using AVR109 and a reconnect is needed, this will likely be a new connection.
  serialport: SerialPortPromise | WebSerialPortPromise
}

Get in touch

You can contact me in the #multitool-general channel of the duinoapp discord

Join Discord

Influences

This project aims to be a full recode based on existing projects before it: