@little-dash/utils
v0.1.1
Published
Shared utilities for littledash applications
Maintainers
Readme
@littledash/utils
Shared utilities for building littledash applications.
Installation
yarn add @littledash/utils
# or
npm install @littledash/utilsFeatures
Image Utilities
Convert PNG images to RGB565 format for display on littledash devices:
import { loadPngAsRgb565, loadPngAsElement } from "@littledash/utils/image";
// Load and convert image
const imageData = await loadPngAsRgb565("./logo.png", 100, 50);
// Or get a ready-to-use display element
const element = await loadPngAsElement("./logo.png", 10, 10, 100, 50);Device Configuration
Configure littledash devices with WiFi credentials and server URL:
import { configureDevice } from "@littledash/utils/configure-device";
await configureDevice({
serverUrl: "http://192.168.1.100:3000",
envPath: "./.env", // optional
});Or use the CLI:
# Auto-detect server URL
yarn littledash-configure
# Specify server URL
yarn littledash-configure 192.168.1.100:3000Usage in Your Project
1. Update package.json
{
"dependencies": {
"@littledash/utils": "file:../../packages/littledash-utils"
},
"scripts": {
"configure-device": "littledash-configure"
}
}2. Update your imports
Replace local imports with the package:
// Before
import { loadPngAsRgb565 } from "./utils/image.js";
// After
import { loadPngAsRgb565 } from "@littledash/utils/image";3. Use the configure-device script
yarn configure-deviceAPI
Image Functions
loadPngAsRgb565(filePath, targetWidth?, targetHeight?)
Loads a PNG file and converts it to RGB565 format.
Parameters:
filePath(string): Path to PNG filetargetWidth(number, optional): Target width for resizingtargetHeight(number, optional): Target height for resizing
Returns: Promise<{ data: string; width: number; height: number }>
loadPngAsElement(filePath, x, y, targetWidth?, targetHeight?)
Loads a PNG and returns a display element configuration.
Parameters:
filePath(string): Path to PNG filex(number): X position on displayy(number): Y position on displaytargetWidth(number, optional): Target width for resizingtargetHeight(number, optional): Target height for resizing
Returns: Display element object
Configuration Functions
configureDevice(options?)
Configures a littledash device via serial connection.
Parameters:
options.serverUrl(string, optional): Server URL to configureoptions.envPath(string, optional): Path to .env file
Returns: Promise<void>
runConfigureDeviceCLI()
CLI entry point for device configuration. Reads from .env and command line arguments.
Environment Variables
Create a .env file in your project root:
WIFI_SSID=your_wifi_ssid
WIFI_PASSWORD=your_wifi_password
PORT=3000License
MIT
