dxDriver
1. Overview
dxDriver is one of the core basic modules of DejaOS.
It provides a unified entry point for all device‑specific hardware drivers, combining a JavaScript configuration file (dxDriver.js) with a set of native driver .so libraries.
- Defines all hardware resource mappings for a specific device model (GPIO pins, UART paths, camera devices, PWM channels, etc.).
- Loads the corresponding native driver libraries that actually drive the hardware.
- Is required in almost all real devices and should be enabled by default in DejaOS projects.
2. Files
dxDriver.js- Multiple
*.sofiles
Ensure all these files are included under the
dxmodulessubdirectory of your project root.
3. Dependencies
4. Compatible Devices
Compatible with all devices running dejaOS v2.0+.
5. Configuration Structure
Below is a simplified example from the DW200 device:
const dxDriver = {};
// 1) GPIO pins
dxDriver.GPIO = {
// Relay control
RELAY: 35,
};
// 2) Communication channels
dxDriver.CHANNEL = {
// RS‑485 UART
UART_PATH: "/dev/ttyS3",
// USB HID virtual device
USBHID_PATH: "/dev/hidg1",
};
// 3) Camera parameters
dxDriver.CAPTURER = {
WIDTH: 800,
HEIGHT: 600,
PATH: "/dev/video11",
};
// 4) PWM channel for buzzer
dxDriver.PWM = {
BEEP_CHANNEL: 4,
BEEP_GPIO: 130,
BEEP_PERIOD_NS: 366166,
BEEP_DUTY: (366166 * 50) / 255,
};
export default dxDriver;
Each device can define its own sections (e.g. GPIO, CHANNEL, CAPTURER, PWM, etc.) according to its hardware design.
6. Usage
6.1 Importing dxDriver
import dxDriver from "./dxmodules/dxDriver.js";
// Example: use GPIO resource to control a relay
const relayPin = dxDriver.GPIO.RELAY;
// Pass relayPin to your GPIO abstraction (e.g. dxGpio) to drive the hardware
Typical patterns:
- Use
dxDriver.GPIOconstants when configuringdxGpio/dxGpioKey. - Use
dxDriver.CHANNEL.UART_PATHwhen configuring serial communication modules. - Use
dxDriver.CAPTURERwhen initializing camera modules. - Use
dxDriver.PWMwhen controlling buzzers or LEDs viadxPwm.
7. Best Practices
- Treat
dxDriveras the single source of truth for all hardware resource definitions in your project. - Avoid hard‑coding GPIO numbers or
/dev/...paths elsewhere in your code; always reference them throughdxDriver. - For new hardware revisions, create a separate
dxDriver.jsvariant (and driver.soset) to keep configurations clean and maintainable.