ElenixOS System API
The eos namespace is the core system API provided by ElenixOS for JavaScript script runtime. Through this API, applications and watchfaces can access system services, page navigation, time information, configuration storage, console logging, and other functions.
Namespace Structure
eos
├── eos.console — Console Logging
│ ├── .log()
│ ├── .info()
│ ├── .warn()
│ ├── .error()
│ └── .debug()
├── eos.view — View Management
│ └── .active()
├── eos.activity — Activity Management
│ ├── .current()
│ ├── .visible()
│ ├── .bottom()
│ ├── .watchface()
│ ├── .rootScreen()
│ ├── .getView()
│ ├── .setView()
│ ├── .getTitle()
│ ├── .setTitle()
│ ├── .getType()
│ ├── .setType()
│ ├── .setAppHeaderVisible()
│ ├── .isAppHeaderVisible()
│ ├── .enter()
│ ├── .back()
│ └── .isTransitionInProgress()
├── eos.config — Configuration Storage
│ ├── .setStr()
│ ├── .setBool()
│ ├── .setNumber()
│ ├── .getStr()
│ ├── .getBool()
│ └── .getNumber()
├── eos.time — Time Service
│ └── .getNow()
├── eos.appHeader — App Header
│ ├── .setTitle()
│ ├── .hide()
│ └── .show()
├── eos.clockHand — Clock Hands
│ ├── .create()
│ ├── .center()
│ └── .placePivot()
├── Constants
│ ├── eos.FONT_SIZE_*
│ ├── eos.DISPLAY_*
│ ├── eos.CLOCK_HAND_*
│ └── eos.ACTIVITY_TYPE_*
Console Logging (eos.console)
Provides different levels of log output for debugging and information recording.
Methods
eos.console.log(message)
eos.console.info(message)
eos.console.warn(message)
eos.console.error(message)
eos.console.debug(message)
Parameters:
message: String, the log message to output
Returns: None
Description: All logging methods accept a string parameter and output it to the system log. The current script ID is automatically added as a prefix for easy differentiation between logs from different applications.
Example
eos.console.log("Application started");
eos.console.info("User logged in");
eos.console.warn("Low battery");
eos.console.error("Failed to load resource");
eos.console.debug("Position: x=" + x + ", y=" + y);
View Management (eos.view)
Used to get the active View object of the current Activity, which is the foundation for creating UI components.
eos.view.active()
const view = eos.view.active();
Parameters: None
Returns: LVGL object of type lv_obj_t, the View of the current Activity
Description: This method returns the LVGL object associated with the current Activity. All UI components should be created with this as the parent object. Equivalent to eos_view_active() in the C layer.
Example
// Get current View and create UI components
const view = eos.view.active();
const label = new lv.label(view);
label.setText("Hello, ElenixOS!");
label.center();
const button = new lv.button(view);
button.setSize(100, 50);
button.align(lv.ALIGN_CENTER, 0, 40);
Activity Management (eos.activity)
Provides page navigation and Activity query functions. Activity is the page management unit of ElenixOS.
Query Methods
eos.activity.current()
const activity = eos.activity.current();
Get the current Activity (top of the stack).
Parameters: None
Returns: Activity object of type eos_activity_t, returns undefined on failure
eos.activity.visible()
const activity = eos.activity.visible();
Get the currently fully displayed Activity (transition animation complete).
Parameters: None
Returns: Activity object of type eos_activity_t, returns undefined on failure
eos.activity.bottom()
const activity = eos.activity.bottom();
Get the bottom Activity (usually the watchface Activity).
Parameters: None
Returns: Activity object of type eos_activity_t, returns undefined on failure
eos.activity.watchface()
const activity = eos.activity.watchface();
Get the watchface Activity.
Parameters: None
Returns: Activity object of type eos_activity_t, returns undefined on failure
eos.activity.rootScreen()
const screen = eos.activity.rootScreen();
Get the root screen object.
Parameters: None
Returns: Root screen object of type lv_obj_t
eos.activity.isTransitionInProgress()
const isTransitioning = eos.activity.isTransitionInProgress();
Check if Activity transition animation is in progress.
Parameters: None
Returns: boolean — true if transition is in progress, false if idle
View Management
eos.activity.getView(activity)
const view = eos.activity.getView(activity);
Get the View object of the specified Activity.
Parameters:
activity: Activity object (returned by methods likeeos.activity.current())
Returns: View object of type lv_obj_t, returns undefined on failure
eos.activity.setView(activity, view)
eos.activity.setView(activity, view);
Set the View object of the specified Activity.
Parameters:
activity: Activity objectview: LVGL object to be used as the Activity's View
Returns: None
Title Management
eos.activity.getTitle(activity)
const title = eos.activity.getTitle(activity);
Get the title of an Activity.
Parameters:
activity: Activity object
Returns: string, returns undefined on failure
eos.activity.setTitle(activity, title)
eos.activity.setTitle(activity, title);
Set the title of an Activity.
Parameters:
activity: Activity objecttitle: String title
Returns: None
Type Management
eos.activity.getType(activity)
const type = eos.activity.getType(activity);
Get the type of an Activity.
Parameters:
activity: Activity object
Returns: Number, corresponding to eos.ACTIVITY_TYPE_* constants
eos.activity.setType(activity, type)
eos.activity.setType(activity, type);
Set the type of an Activity.
Parameters:
activity: Activity objecttype: Number, useeos.ACTIVITY_TYPE_*constants
Returns: None
AppHeader Visibility
eos.activity.setAppHeaderVisible(activity, visible)
eos.activity.setAppHeaderVisible(activity, visible);
Set AppHeader visibility for an Activity.
Parameters:
activity: Activity objectvisible: Boolean value
Returns: None
eos.activity.isAppHeaderVisible(activity)
const visible = eos.activity.isAppHeaderVisible(activity);
Check if Activity's AppHeader is visible.
Parameters:
activity: Activity object
Returns: boolean
Navigation Methods
eos.activity.enter(activity)
eos.activity.enter(activity);
Enter the specified Activity (push Activity to top of stack and display).
Parameters:
activity: Activity object to enter
Returns: None
eos.activity.back()
eos.activity.back();
Return to the previous Activity (destroy current top Activity, restore previous Activity).
Parameters: None
Returns: boolean — true if operation succeeded, false if failed
Configuration Storage (eos.config)
Provides JSON file-based persistent key-value storage. Each application/watchface has its own independent storage space.
Storage Path:
- Application:
<EOS_SYS_DIR>/app/app_data/<app_id>/config.json - Watchface:
<EOS_SYS_DIR>/app/watchface_data/<wf_id>/config.json
Write Methods
eos.config.setStr(key, value)
eos.config.setStr("username", "Alice");
Store a string value.
Parameters:
key: String, key namevalue: String, value to store
Returns: None
eos.config.setBool(key, value)
eos.config.setBool("dark_mode", true);
Store a boolean value.
Parameters:
key: String, key namevalue: Boolean
Returns: None
eos.config.setNumber(key, value)
eos.config.setNumber("volume", 75);
Store a number value.
Parameters:
key: String, key namevalue: Number
Returns: None
Read Methods
eos.config.getStr(key)
const username = eos.config.getStr("username");
Read a string value. Returns undefined if key doesn't exist.
Parameters:
key: String, key name
Returns: string or undefined
eos.config.getBool(key)
const darkMode = eos.config.getBool("dark_mode");
Read a boolean value. Returns false if key doesn't exist.
Parameters:
key: String, key name
Returns: boolean
eos.config.getNumber(key)
const volume = eos.config.getNumber("volume");
Read a number value. Returns 0 if key doesn't exist.
Parameters:
key: String, key name
Returns: number
Complete Example
// Save user settings
eos.config.setStr("username", "Alice");
eos.config.setBool("dark_mode", true);
eos.config.setNumber("volume", 75);
// Read user settings
const username = eos.config.getStr("username");
const darkMode = eos.config.getBool("dark_mode");
const volume = eos.config.getNumber("volume");
eos.console.log("User: " + username + ", Dark Mode: " + darkMode + ", Volume: " + volume);
Time Service (eos.time)
Provides functionality to get the current system time.
eos.time.getNow()
const now = eos.time.getNow();
Parameters: None
Returns: Time object containing the following fields:
| Field | Type | Description | Range |
|---|---|---|---|
year | number | Year | e.g. 2026 |
month | number | Month | 1-12 |
day | number | Day | 1-31 |
hour | number | Hour | 0-23 |
min | number | Minute | 0-59 |
sec | number | Second | 0-59 |
ms | number | Millisecond | 0-999 |
day_of_week | number | Day of week | 0-6 (0=Sunday) |
Example
const now = eos.time.getNow();
eos.console.log("Current time: " + now.year + "-" + now.month + "-" + now.day + " " + now.hour + ":" + now.min + ":" + now.sec);
// Display time on watchface
const view = eos.view.active();
const timeLabel = new lv.label(view);
function updateTime() {
const t = eos.time.getNow();
const timeStr = String(t.hour).padStart(2, '0') + ":" + String(t.min).padStart(2, '0');
timeLabel.setText(timeStr);
timeLabel.center();
}
App Header (eos.appHeader)
Controls the application's top navigation bar (AppHeader).
eos.appHeader.setTitle(view, title)
eos.appHeader.setTitle(view, "Settings");
Set the app header title for the current Activity.
Parameters:
view: View object ornulltitle: Title string ornull/undefined
Returns: None
eos.appHeader.hide()
eos.appHeader.hide();
Hide the app header.
Parameters: None
Returns: None
eos.appHeader.show()
eos.appHeader.show();
Show the app header and refresh the current Activity's title.
Parameters: None
Returns: None
Example
// Set title
eos.appHeader.setTitle(null, "My App");
// Hide header
eos.appHeader.hide();
// Show header
eos.appHeader.show();
Clock Hands (eos.clockHand)
Create and manage clock hands (hour, minute, second) for watchfaces.
eos.clockHand.create(obj, src, type, cx, cy)
const hand = eos.clockHand.create(parent, "path/to/hand.png", eos.CLOCK_HAND_HOUR, cx, cy);
Create a clock hand image.
Parameters:
obj: Parent LVGL objectsrc: String, path to the hand image resource (relative to app/watchface assets directory)type: Hand type, useeos.CLOCK_HAND_*constantscx: Rotation center X coordinate (relative to top-left of image)cy: Rotation center Y coordinate (relative to top-left of image)
Returns: Hand object of type lv_obj_t
eos.clockHand.center(obj)
eos.clockHand.center(hand);
Align the hand object's center to its parent's center.
Parameters:
obj: Hand LVGL object
Returns: None
eos.clockHand.placePivot(obj, x, y)
eos.clockHand.placePivot(hand, cx, cy);
Set the rotation center position of the hand object.
Parameters:
obj: Hand LVGL objectx: Rotation center X coordinatey: Rotation center Y coordinate
Returns: None
Complete Example
// Get current View
const view = eos.view.active();
// Create watchface background
const bg = new lv.image(view);
bg.setSrc("A:background.png");
bg.center();
// Create hour hand
const hourHand = eos.clockHand.create(view, "hour_hand.png", eos.CLOCK_HAND_HOUR, 5, 50);
eos.clockHand.center(hourHand);
// Create minute hand
const minHand = eos.clockHand.create(view, "min_hand.png", eos.CLOCK_HAND_MINUTE, 5, 65);
eos.clockHand.center(minHand);
// Create second hand
const secHand = eos.clockHand.create(view, "sec_hand.png", eos.CLOCK_HAND_SECOND, 3, 70);
eos.clockHand.center(secHand);
System Constants
ElenixOS defines the following constants under the eos namespace for use in JavaScript scripts.
Font Sizes
| Constant | Value | Description |
|---|---|---|
eos.FONT_SIZE_LARGE | 30 | Large font size |
eos.FONT_SIZE_MEDIUM | 26 | Medium font size |
eos.FONT_SIZE_SMALL | 22 | Small font size |
Display Dimensions
| Constant | Value | Description |
|---|---|---|
eos.DISPLAY_WIDTH | 240 | Screen width (pixels) |
eos.DISPLAY_HEIGHT | 240 | Screen height (pixels) |
Hand Types
| Constant | Value | Description |
|---|---|---|
eos.CLOCK_HAND_HOUR | 0 | Hour hand |
eos.CLOCK_HAND_MINUTE | 1 | Minute hand |
eos.CLOCK_HAND_SECOND | 2 | Second hand |
Activity Types
| Constant | Value | Description |
|---|---|---|
eos.ACTIVITY_TYPE_NULL | 0 | Null type |
eos.ACTIVITY_TYPE_APP | 1 | Application page |
eos.ACTIVITY_TYPE_APP_LIST | 2 | Application list |
eos.ACTIVITY_TYPE_WATCHFACE | 3 | Watchface page |
eos.ACTIVITY_TYPE_WATCHFACE_LIST | 4 | Watchface list |
Error Handling
Error Types
Errors are thrown when API call parameters are incorrect. Common error causes:
| Error Message | Cause |
|---|---|
Invalid argument count | Incorrect number of arguments |
Invalid argument type | Incorrect argument type |
Usage: xxx(key, value) | Usage hint showing correct calling method |
Can't load config | Configuration storage loading failed |
No current activity | No active Activity |
Error Handling Example
try {
const view = eos.view.active();
if (view) {
const label = new lv.label(view);
label.setText("Hello!");
}
} catch (err) {
eos.console.error("Error: " + err);
}
Complete Example: Counter App
// Get current View
const view = eos.view.active();
// Set title
eos.appHeader.setTitle(null, "Counter");
// Read saved count
let count = eos.config.getNumber("count");
// Create display label
const countLabel = new lv.label(view);
countLabel.setStyleTextFont(eos.FONT_SIZE_LARGE, 0);
countLabel.setText(String(count));
countLabel.align(lv.ALIGN_CENTER, 0, -30);
// Create increment button
const incBtn = new lv.button(view);
incBtn.setSize(80, 50);
incBtn.align(lv.ALIGN_CENTER, -50, 30);
incBtn.addEventCb(function() {
count++;
countLabel.setText(String(count));
eos.config.setNumber("count", count);
}, lv.EVENT_CLICKED, null);
const incLabel = new lv.label(incBtn);
incLabel.setText("+1");
// Create decrement button
const decBtn = new lv.button(view);
decBtn.setSize(80, 50);
decBtn.align(lv.ALIGN_CENTER, 50, 30);
decBtn.addEventCb(function() {
count--;
countLabel.setText(String(count));
eos.config.setNumber("count", count);
}, lv.EVENT_CLICKED, null);
const decLabel = new lv.label(decBtn);
decLabel.setText("-1");
Complete Example: Digital Watchface
function updateWatchface() {
const now = eos.time.getNow();
// Format time
const timeStr = String(now.hour).padStart(2, '0') + ":" +
String(now.min).padStart(2, '0');
// Format date
const dateStr = now.year + "-" +
String(now.month).padStart(2, '0') + "-" +
String(now.day).padStart(2, '0');
// Update UI
timeLabel.setText(timeStr);
dateLabel.setText(dateStr);
// Update hand angles
const hourAngle = (now.hour % 12) * 30 + now.min * 0.5;
const minAngle = now.min * 6 + now.sec * 0.1;
const secAngle = now.sec * 6;
}
// Get View and create UI
const view = eos.view.active();
eos.appHeader.hide();
// Create time label
const timeLabel = new lv.label(view);
timeLabel.setStyleTextFont(eos.FONT_SIZE_LARGE, 0);
timeLabel.align(lv.ALIGN_CENTER, 0, -20);
// Create date label
const dateLabel = new lv.label(view);
dateLabel.setStyleTextFont(eos.FONT_SIZE_SMALL, 0);
dateLabel.align(lv.ALIGN_CENTER, 0, 10);
// Update every second
const timer = new lv.timer(function() {
updateWatchface();
}, 1000, null);
updateWatchface();
Related Documentation
- JS API General Usage — Understand JS API conventions
- LVGL UI API — Detailed LVGL UI component documentation
- Activity and View — Activity system details