Skip to main content

API Reference

This reference covers the complete HIL API surface: hardware I/O functions, system operators, I2C, event handlers, autopilot commands, and the registry HTTP/WS endpoints (Rashwan, 2026).

HIL LISP Built-in Operators​

Arithmetic​

OperatorSyntaxDescriptionExample
+(+ a b)Addition(+ 3 4) → 7
-(- a b)Subtraction(- 10 3) → 7
-(- a)Negation(- 5) → -5
*(* a b)Multiplication(* 6 7) → 42
/(/ a b)Integer division(/ 10 3) → 3
%(% a b)Modulo(% 10 3) → 1

Comparison​

OperatorSyntaxDescription
==(== a b)Equal
!=(!= a b)Not equal
>(> a b)Greater than
<(< a b)Less than
>=(>= a b)Greater or equal
<=(<= a b)Less or equal

Boolean​

OperatorSyntaxDescription
AND(AND a b)Logical AND (both nonzero = 1)
OR(OR a b)Logical OR (either nonzero = 1)
NOT(NOT a)Logical NOT (0 → 1, nonzero → 0)

Math Utilities​

OperatorSyntaxDescription
MIN(MIN a b)Minimum of two values
MAX(MAX a b)Maximum of two values
ABS(ABS a)Absolute value
MAP(MAP v inMin inMax outMin outMax)Linear interpolation
CONSTRAIN(CONSTRAIN v min max)Clamp to range
RANDOM(RANDOM min max)Random integer in [min, max]

Control Flow​

OperatorSyntaxDescription
IF(IF cond then else)Conditional
COND(COND (cond1 body1) ...)Multi-way branch
WHILE(WHILE cond body)Loop while true
FOR(FOR var from to body)Counted loop (stop value exclusive; up or down)
DO(DO expr1 expr2 ...)Sequence
BREAK(BREAK)Exit innermost loop
CONTINUE(CONTINUE)Skip to next iteration

Variables and Functions​

OperatorSyntaxDescription
SET(SET var value)Assign variable
DEFUN(DEFUN name (params) body)Define function
LOAD(LOAD "path")Load a package file

Hardware I/O​

OperatorSyntaxDescription
PIN-MODE(PIN-MODE TYPE pin mode)Configure pin (0=input, 1=output)
WRITE(WRITE TYPE pin value)Write to pin (D=digital, A=analog, P=PWM)
READ(READ TYPE pin)Read from pin
TOGGLE(TOGGLE pin)Toggle digital pin
TONE(TONE pin freq duration)Play a tone
DELAY(DELAY ms)Delay in milliseconds
DLY-US(DLY-US us)Delay in microseconds
AWAIT(AWAIT pin state timeout)Wait for pin state with timeout
MILLIS(MILLIS)Current time in ms
PULSE(PULSE pin timeout)Measure pulse width (µs)
BLINK(BLINK pin count onMs offMs)Blink LED pattern

I2C​

OperatorSyntaxDescription
I2C-START(I2C-START addr rw)Start I2C transaction
I2C-WRITE(I2C-WRITE byte)Write byte to I2C
I2C-READ(I2C-READ ack)Read byte from I2C (ack=1)
I2C-STOP(I2C-STOP)End I2C transaction

Peripherals​

OperatorSyntaxDescription
SERVO(SERVO pin angle)Set servo angle (0-180)
LCD-INIT(LCD-INIT)Initialize LCD
LCD-PRINT(LCD-PRINT text)Print to LCD
LCD-CLEAR(LCD-CLEAR)Clear LCD
LCD-SETCURSOR(LCD-SETCURSOR col row)Set LCD cursor position
NEO-SET(NEO-SET idx r g b)Set NeoPixel color
NEO-SHOW(NEO-SHOW)Update NeoPixel display
MP3-PLAY(MP3-PLAY track)Play MP3 track
MP3-VOL(MP3-VOL level)Set MP3 volume

Sensors​

OperatorSyntaxDescription
LM35(LM35)Read LM35 temperature
ULTRASONIC(ULTRASONIC trig echo)Read distance in cm
DHT-READ(DHT-READ pin)Read DHT sensor data
RTC-READ(RTC-READ)Read real-time clock

Events​

OperatorSyntaxDescription
ON-EVENT(ON-EVENT type pin action)Arm digital event
ON-CHANGE(ON-CHANGE pin threshold action)Arm analog threshold event
ATTENTION(ATTENTION pin flag)Bypass event polling limits
EVT-ARM(EVT-ARM type pin threshold)Low-level event arm
EVT-POLL(EVT-POLL)Poll for events

Control Systems​

OperatorSyntaxDescription
PID-INIT(PID-INIT kp ki kd)Initialize PID controller
CLOSED-LOOP(CLOSED-LOOP target pin)Start closed-loop control
OPEN-LOOP(OPEN-LOOP)Stop closed-loop control

Autopilot​

OperatorSyntaxDescription
AUTOPILOT-BEGIN(AUTOPILOT-BEGIN)Start recording autopilot commands
AUTOPILOT-END(AUTOPILOT-END)Stop recording and store to flash

List Operations​

OperatorSyntaxDescription
FIRST(FIRST list)Get first element
SECOND(SECOND list)Get second element

Batching​

OperatorSyntaxDescription
BATCH-BEGIN(BATCH-BEGIN)Disable per-command ACK
BATCH-END(BATCH-END)Re-enable per-command ACK

System​

OperatorSyntaxDescription
EXIT(EXIT)Halt execution
LOG(LOG val...)Print to serial console

Registry HTTP API​

EndpointMethodDescription
/apiGETRegistry info (name, version, package count)
/api/healthGETHealth check with uptime
/api/search?q=GETSearch packages
/api/packages/:nameGETPackage metadata
/api/packages/:name/downloadGETDownload package
/api/ota/versionsGETList OTA versions
/api/ota/announcePOSTAnnounce new version (admin)
/api/errorsGETList errors
/api/errors/statsGETError statistics
/api/errorsPOSTReport error
/api/network/devicesGETList IoT devices
/api/network/feedGETRecent messages
/api/network/topicsGETActive topics

WebSocket API​

Connect to ws://host:3002/ws for real-time IoT communication:

Message TypeDirectionDescription
authClient→ServerAuthenticate device
heartbeatClient→ServerKeep-alive ping
publishClient→ServerPublish to topic
subscribeClient→ServerSubscribe to topic
messageBothDirect device message

References

Rashwan, S. (2026). HIL: A LISP-based hardware-in-the-loop operating system. https://github.com/SRashwan/hilp