All files / shared/utils arduino-utils.ts

100% Statements 5/5
50% Branches 1/2
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25    51x             50x               51x   51x     151x    
import type { PinMode } from "../types/arduino.types";
 
const PIN_MODE_NAMES: Record<number, PinMode> = {
  0: "INPUT",
  1: "OUTPUT",
  2: "INPUT_PULLUP",
};
 
export function pinModeToString(mode: number): PinMode {
  return PIN_MODE_NAMES[mode] ?? "INPUT"; // Default to INPUT for invalid modes
}
 
/**
 * PWM-capable digital pins of the Arduino UNO (the pins marked "~"), in board
 * order. The single definition of this hardware property: UI, polling engine
 * and hardware-compatibility checks all derive from it.
 */
export const UNO_PWM_PINS: readonly number[] = [3, 5, 6, 9, 10, 11];
 
const UNO_PWM_PIN_SET: ReadonlySet<number> = new Set(UNO_PWM_PINS);
 
export function isUnoPwmPin(pin: number): boolean {
  return UNO_PWM_PIN_SET.has(pin);
}