Access/ control reTerminal DM hardware such as accelerometer, light sensor, touch panel, buzzer, buttons, LEDs
npm install npm-reterminal-dmsh
npm install npm-reterminal-dm --save
`
$3
`sh
npm install https://github.com/cgjgh/npm-reterminal-dm
`
Available Hardware Components
- Touch Panel: Multi-touch capacitive touchscreen
- Buzzer: Built-in buzzer for audio feedback
- LEDs: User-controllable LED (red)
- Light Sensor: Ambient light intensity sensor
Usage
$3
Control and monitor the capacitive touch panel:
`javascript
const InputEvent = require('npm-reterminal-dm');
const dev = require('npm-reterminal-dm/lib/deviceid');
const touch = new InputEvent.Touch(dev.tpPath());
// Listen for touch coordinates
touch.on('x-axis', function(coordinate) {
console.log('X-axis coordinate: ' + coordinate);
});
touch.on('y-axis', function(coordinate) {
console.log('Y-axis coordinate: ' + coordinate);
});
`
$3
Control the built-in buzzer:
`javascript
const buzz = require('npm-reterminal-dm/lib/buzzer');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function buzzerDemo() {
console.log("Buzzer ON");
buzz.buzzerOn();
await sleep(1000);
console.log("Buzzer OFF");
buzz.buzzerOff();
await sleep(1000);
}
buzzerDemo();
`
#### Buzzer Functions
- buzzerOn() - Turn buzzer on
- buzzerOff() - Turn buzzer off
$3
Control the user LED:
`javascript
const led = require('npm-reterminal-dm/lib/led');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function ledDemo() {
console.log("User LED ON");
led.usrRedOn();
await sleep(1000);
console.log("User LED OFF");
led.usrRedOff();
await sleep(1000);
}
ledDemo();
`
#### LED Functions
- usrRedOn() - Turn user red LED on
- usrRedOff() - Turn user red LED off
$3
Read ambient light intensity:
`javascript
const light = require('npm-reterminal-dm/lib/light');
// Single reading
console.log("Light Intensity: " + light.lightSense());
// Continuous monitoring
setInterval(() => {
console.log("Light Intensity: " + light.lightSense());
}, 1000);
`
#### Light Sensor Functions
- lightSense() - Returns current light intensity value
Device Detection
The package automatically detects hardware components through the device ID system:
`javascript
const dev = require('npm-reterminal-dm/lib/deviceid');
// Get device paths
console.log("Touch panel path:", dev.tpPath());
console.log("Buttons path:", dev.buttonsPath());
console.log("Accelerometer path:", dev.accelPath());
`
Hardware Requirements
- reTerminal DM device
- Linux-based operating system
- Root/sudo access for hardware control
- Node.js environment
System Paths
The package interacts with the following system paths:
- Touch Panel: /dev/input/eventX (where X is auto-detected)
- Buzzer: /sys/class/leds/usr-buzzer/brightness
- User LED: /sys/class/leds/usr-led/brightness
- Light Sensor: /sys/bus/iio/devices/iio:device0/in_illuminance_input
Error Handling
The package includes built-in error handling for:
- Device disconnection events
- File system access errors
- Hardware communication failures
`javascript
const touch = new InputEvent.Touch(dev.tpPath());
touch.on('error', function(err) {
console.error('Touch panel error:', err);
});
touch.on('disconnect', function() {
console.log('Touch panel disconnected');
});
``