All files / shared/utils arduino-utils.ts

75% Statements 3/4
50% Branches 1/2
50% Functions 1/2
75% Lines 3/4

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    16x           16x             44x            
import type { PinMode } from "../types/arduino.types";
 
const PIN_MODE_NAMES: Record<number, PinMode> = {
  0: "INPUT",
  1: "OUTPUT",
  2: "INPUT_PULLUP",
};
 
const PIN_MODE_VALUES: Record<PinMode, number> = {
  INPUT: 0,
  OUTPUT: 1,
  INPUT_PULLUP: 2,
};
 
export function pinModeToString(mode: number): PinMode {
  return PIN_MODE_NAMES[mode] ?? "INPUT"; // Default to INPUT for invalid modes
}
 
export function stringToPinMode(mode: string): number | undefined {
  return PIN_MODE_VALUES[mode as PinMode];
}