Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Created June 29, 2024 07:51
Show Gist options
  • Save billywhizz/3afda9486c4f91b0b2caf61c5c923a84 to your computer and use it in GitHub Desktop.
Save billywhizz/3afda9486c4f91b0b2caf61c5c923a84 to your computer and use it in GitHub Desktop.
WiringPi Issue on Bun

setup

git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi/
./build debian

install bun 1.1.15

curl -fsSL https://bun.sh/install | bash -s "bun-v1.1.15"

test

$ bun test.js 
read 1
read 0
read 1
read 0

install bun 1.1.16

curl -fsSL https://bun.sh/install | bash -s "bun-v1.1.16"

test

$ bun test.js 
Illegal instruction
import { dlopen, FFIType, suffix } from "bun:ffi";
const path = "./debian-template/wiringPi/usr/lib/libwiringPi.so.3.6";
const {
symbols: {
wiringPiSetupGpio,
pinMode,
digitalWrite,
digitalRead
},
} = dlopen(
path, // a library name or file path
{
wiringPiSetupGpio: {
args:[],
returns: FFIType.int
},
pinMode: {
args: [FFIType.int, FFIType.int], // pin, mode
returns: FFIType.void
},
digitalWrite: {
args: [FFIType.int, FFIType.int], // pin, value (high or low)
returns: FFIType.void
},
digitalRead: {
args: [FFIType.int],
returns: FFIType.int
},
},
);
wiringPiSetupGpio();
pinMode(26, 1);
let value = 0;
while (true ) {
value = value === 0 ? 1 : 0;
digitalWrite(26, value);
const v = digitalRead(26);
console.log(`read ${v}`);
await new Promise((res) => setTimeout(res, 1000));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment