Hello World Quick Start
π Create a New Projectβ
- Launch VSCode and click the
DejaOS
icon in the sidebar - Select
Create Project
, enter a project name, and choose a storage path - Click
Submit
to create the project
- In your project directory, click the
app.dxproj
file to open the visual configuration interface - After editing the configuration, click
Add Module
to add required modules and save
β οΈ Note:
- Ensure the selected device model matches your actual hardware
- If you change the device model, reconfigure all module versions
- Module versions are not compatible across different device models
π Import an Existing Projectβ
DejaOS offers a variety of GitHub examples. You can download any example and import it into VSCode:
- After downloading, open the code directory in VSCode
- Make sure the directory contains an
app.dxproj
file at the rootβthis is required to activate the extension
π Connect Device & Sync Codeβ
- Click the
Not Connected
button at the bottom of VSCode and select your device - Once connected, click
syncAll
for the initial full sync (this may take a while)
β οΈ Note:
- Please select an example that matches your connected device model. If they don't match, you can manually modify the device model in app.dxproj and reselect modules versions
- The first sync must use
syncAll
. For subsequent development, usesync
for faster incremental updates.
βοΈ Coding Example: Controls Relayβ
Add the following code to your project's main.js
to control a relay with a button press:
import logger from "../dxmodules/dxLogger.js";
import dxui from "../dxmodules/dxUi.js";
import std from "../dxmodules/dxStd.js";
import gpio from "../dxmodules/dxGpio.js";
import * as os from "os";
// ui context
let context = {};
function initScreen() {
// ui init
dxui.init({ orientation: 1 }, context);
// Create screen
let mainView = dxui.View.build("mainView", dxui.Utils.LAYER.MAIN);
// Create a button control
let button = dxui.Button.build(mainView.id + "button", mainView);
// Set button size
button.setSize(130, 50);
// Create a label control
let label = dxui.Label.build(mainView.id + "label", button);
// Set text content
label.text("Click");
// Set text color
label.textColor(0x000000);
// Set the position of the text in the button
label.align(dxui.Utils.ALIGN.CENTER, 0, 0);
// Listen for button click event
button.on(dxui.Utils.EVENT.CLICK, handleGpio);
// Load screen
dxui.loadMain(mainView);
}
(function () {
initScreen();
})();
function handleGpio() {
const gpio_id_dw200 = 44;
// Init gpio
let res = gpio.init();
logger.info("init gpio", res);
// Request gpio
res = gpio.request(gpio_id_dw200);
logger.info("request gpio", res);
// Output high level to open the relay
res = gpio.setValue(gpio_id_dw200, 1);
logger.info("Output high level", res);
// Get whether the current level is high or low
res = gpio.getValue(gpio_id_dw200);
logger.info("The level is now", res);
// Wait 3 seconds
os.sleep(3000);
// Output low level to close the relay
res = gpio.setValue(gpio_id_dw200, 0);
logger.info("Output low level", res);
res = gpio.getValue(gpio_id_dw200);
logger.info("The level is now", res);
}
std.setInterval(() => {
dxui.handler();
}, 5);
βΆοΈ Run the Projectβ
- After coding, click the
sync
button to upload changes to your device - Once synced, click
start
to launch the application - View log output in the VSCode console and observe the device screen
β
π¦ Package the Projectβ
When development is complete, you can package your project as a .dpk
installer for deployment:
- Click the
package
button to start packaging
- The installer will be saved in the
.temp/
folder within your project directory
.dpk
files are DejaOS-specific installers, suitable for OTA or serial deployment
π Next Stepsβ
- π¦ To install or upgrade your
.dpk
application on a device, see: App Packaging, Installation, and Upgrade - π§ͺ For more JavaScript App projects, see: Example Projects