greenbreakfast aa28fcb272 adding back pressure to weather card rolling display | 4 jaren geleden | |
---|---|---|
.. | ||
alarm | 4 jaren geleden | |
audio-manager | 4 jaren geleden | |
blank-card | 4 jaren geleden | |
calendar-card | 4 jaren geleden | |
config-update | 4 jaren geleden | |
device | 4 jaren geleden | |
device-client | 4 jaren geleden | |
input-processor | 4 jaren geleden | |
music-card | 4 jaren geleden | |
oboo-runtime | 4 jaren geleden | |
system-card | 4 jaren geleden | |
test | 4 jaren geleden | |
timer-card | 4 jaren geleden | |
upgrade-card | 4 jaren geleden | |
utils | 4 jaren geleden | |
weather-card | 4 jaren geleden | |
.gitignore | 4 jaren geleden | |
Dockerfile | 4 jaren geleden | |
README.md | 4 jaren geleden | |
demo.sh | 4 jaren geleden | |
makefile | 4 jaren geleden | |
runDemo.sh | 4 jaren geleden | |
test.py | 4 jaren geleden |
Card System for Oboo Smart Clock
Steps to configure Docker:
docker build -t oboo-cards .
`docker run -it oboo-cards /bin/bash
docker run -it -v $(pwd):/usr/src/myapp oboo-cards /bin/bash
Lightweight Javascript ES5 runtime
C code:
oboo-runtime
directoryort.c
main()
functionruntime.c
initRuntime()
function registers these C functions for use in Javascriptduktape
librarymessageQueue.c
mosquitto
libraryserialPort.c
termios
libraryCompiled ort
binary should be run as follows:
./ort <path to JS file>
service mosquitto start
make
make test
Listing of functions available in the Javascript runtime
Description:
Write to a file on the filesystem.
Syntax:
writeFile(filePath, fileContents, callback(err) )
Parameters:
filePath
fileContents
callback(err)
err
parameter will be null if write is successfulDescription:
Write to a file on the filesystem.
Syntax:
readFile(filePath, encoding, callback(err, data) )
Parameters:
filePath
encoding
callback(err, data)
err
parameter will be null if read is successfuldata
will hold contets of the fileDescription:
Use gpioctl
utility to set a GPIO pin to a specified output value
Syntax:
setGpio(gpioNum, value)
Parameters:
gpioNum
value
0
(low) or 1
(high)Description:
Use mpg123
utility to play specified MP3 music file
Syntax:
playMP3(filePath)
Parameters:
filePath
mp3
Description:
Make any system call NOTE: this can be dangerous! This is a blocking call.
Syntax:
system(command)
Parameters:
command
Description:
Makes any system call and returns the output of the command (stdout and stderr) as a string NOTE: this can be dangerous! This is a blocking call.
Syntax:
val = popen(command)
Parameters:
command
Returns:
Description:
Allows you to run system call and returns PID of particular process This is non blocking call.
Syntax:
val = launchProcess(command)
NOTE: Use this call with complete set of parametars like (mpg123 –loop -1 somefile) Returns:
Description:
Allows you to kill process with PID This is non blocking call.
Syntax:
val = killProcess(PID)
Returns: 1 on sucess 0 on failure
Description:
Allows you to check if process with PID is running
Syntax:
val = checkProcess(PID)
Returns: 1 if process is running 0 if not
Description:
Initiate connection to message queue broker as a client
Syntax:
connect(host, port, [clientId], [callback()], [enableTls], [willTopic], [willPayload])
Parameters:
host
port
clientId
callback()
enableTls
willTopic
willPayload
willPayload
willTopic
Description:
Subscribe to a topic. Must be run after connect
function.
Syntax:
subscribe(topic, [callback()], [enableTls])
Parameters:
topic
callback()
enableTls
Description:
Subscribe to a topic. Must be run after connect
function.
Syntax:
publish(topic, payload, [enableTls])
Parameters:
Parameters:
topic
payload
enableTls
Currently, it’s only possible to exit an Oboo Runtime Javascript program in the JS loop()
function by returning -1
.
Example:
function loop() {
if (globalVar === true) {
// exit this program
return -1;
} else {
print('Still running!');
}
}
All received MQTT messages call the onRecvMessage()
function that’s defined in oboo-runtime/js/card-lib.js
.
This function will then call onInput()
or onMessage()
functions that must be defined in each Oboo Runtime Javascript program to function properly.
Regular MQTT messages will be passed as follows:
onMessage({
topic: messageTopic,
payload: messagePayload
})
User input from the touch pad or gesture sensor will be passed to the Oboo Runtime Javascript program through the onInput()
.
The Hardware supports multi-touch (detection of simultaneous presses of multiple buttons) and tracks the duration of the button press. The message will be sent out when the button is released.
For single touch button presses, it will be invoked as follows:
onInput({
source: 'button',
payload: {
id: buttonId, // defines buttons left to right as 0 to 3
action: 'press',
duration: 123, // time in milliseconds button was pressed
multitouch: false
}
});
For multi-touch, the function will be invoked as follows:
onInput({
source: 'button',
payload: {
id: buttonByte, // see description below
action: 'press',
duration: 123, // time in milliseconds button was pressed
multitouch: true
}
});
The buttonByte
is an integer, with each bit representing a different button:
Bit 3 | Bit 2 | Bit 1 | Bit 0 |
---|---|---|---|
Button 3 (Farthest Right) | Button 2 | Button 1 | Button 0 (Farthest Left) |
So a value of 14
or 0xe
in hex would be 0b1110
, meaning buttons 1-3 were pressed.
For gesture input, it will be invoked as follows:
onInput({
source: 'gesture',
payload: {
direction: ['left'|'right'|'up'|'down'|'none']
}
});