Refactor JavaScript interpreter
| This is a project issue to track progress | Add functions from the flipper zero JavaScript https://github.com/jamisonderek/flipper-zero-tutorials/wiki/JavaScript
Update
Progress so far: I've created docs for new API: https://github.com/Tawank/bruce-js-tooling/blob/master/packages/bruce-sdk/DOCS.md Added new functions and fixed existing functions.
I created dino game, http browser for bruce and tried to run NES emulator (failed). https://github.com/Tawank/bruce-js-tooling/tree/master/examples
To do:
- [ ] create test script to test all "new" API and "old" API. We need to be sure that old and new is working, and we will have testing so we see regress.
- [ ] give more examples in the docs
- [ ] add permissions, show dialog if script uses
httporstorageAPI, so user can agree, store permissions in the config file.
Legend
- π΄ Function does nothing on ESP32, e.g.,
startAnalogandstopAnalog. There's no need to initialize or deinitialize analog functions. These functions are implemented as placeholders - you can use them in code, but they won't do anything. - π¦ Function does not exist in FZ JS but is implemented in Bruce JS.
Functions
- Globals
- [x] console
- [x] delay
- [x] parse_int
- [x] print
- [x] require
- [x] to_string
- [x] to_hex_string
- [x] to_lower_case
- [x] to_upper_case
- [x] random π¦(does not exist in fz js)
- [x] filepath
- [x] dirpath
- badusb
- [x] setup
- [ ] quit
- [ ] isConnected
- [x] press
- [x] hold
- [x] release
- [x] releaseAll π¦(does not exist in fz js)
- [x] print
- [x] println
- [x] pressRaw π¦(does not exist in fz js)
- [x] runFile π¦(does not exist in fz js)
- [ ] altPrint
- [ ] altPrintln
- blebeacon
- [ ] isActive
- [ ] setConfig
- [ ] setData
- [ ] start
- [ ] stop
- [ ] keepAlive
- dialog
- [x] message
- [x] error π¦(does not exist in fz js)
- [x] choice π¦(does not exist in fz js)
- [ ] custom
- [x] pickFile
- [x] viewFile π¦(does not exist in fz js)
- flipper/device
- [x] getModel - alias to
getBoard - [x] getBoard π¦(does not exist in fz js) shows m5stack model
- [x] getName (shows
bruceConfig.wifiAp.ssid) - [x] getBatteryCharge
- [x] getModel - alias to
- gpio
- [x] init - arduino and fz syntax possible:
gpio.init(25, INPUT); gpio.init("G26", "outputPushPull", "no"); - [x] read
- [x] write
- [x] startAnalog(reference?: double)π΄(reference voltage not possible on esp32)
- [x] stopAnalog π΄ (on esp32 there is no need to init analog)
- [x] readAnalog
- [x] writeAnalog π¦(does not exist in fz js)
- [x] dacWrite π¦(does not exist in fz js)
- [x] init - arduino and fz syntax possible:
- keyboard/input
- [x] setHeader
- [x] text
selected: booleanis not implemented, but it can be passed - it will just be ignored- bruce and fz js syntax works
(title: string, maxlen: number, initval: string): stringand(allocSize: number, defaultText: string, selected: boolean)
- [ ] byte
- [x] getKeysPressed π¦(does not exist in fz js)
- [x] getPrevPress π¦(does not exist in fz js)
- [x] getSelPress π¦(does not exist in fz js)
- [x] getNextPress π¦(does not exist in fz js)
- [x] getAnyPress π¦(does not exist in fz js)
- math
- [x] abs
- [x] acos
- [x] acosh
- [x] asin
- [x] asinh
- [x] atan
- [x] atan2
- [x] atanh
- [x] cbrt
- [x] ceil
- [x] clz32
- [x] cos
- [x] exp
- [x] floor
- [x] is_equal
- [x] log
- [x] max
- [x] min
- [x] pow
- [x] random
- [x] sign
- [x] sin
- [x] sqrt
- [x] trunc
- [x] PI
- [x] E
- [ ] EPSILON
- notification
- [ ] success
- [ ] error
- [x] blink - ignores first parameter, as m5 stick has only red diode
- serial
- [ ] setup
- [ ] end
- [x] write alias to
serial.print - [x] print π¦(does not exist in fz js)
- [x] println π¦(does not exist in fz js)
- [ ] read
- [x] readln
- [ ] readBytes
- [ ] readAny
- [ ] expect
- storage
- [x] read
- [x] write
- [x] rename
- [x] remove
- [x] readdir
- [x] mkdir
- [x] rmdir
- [ ] append
- [ ] copy
- [ ] move
- [ ] exists
- maybe api for FS on PSRAM
- subghz
- [ ] end
- [ ] getFrequency
- [ ] getRssi
- [ ] getState
- [ ] isExternal
- [x] setFrequency
- [x] setIdle π΄
- [ ] setRx
- [x] setup π΄
- [x] transmitFile
- usbdisk
- [ ] createImage
- [ ] start
- [ ] stop
- [ ] wasEjected
- sensors
- [ ] readAccelData (needs new name)
- [ ] readGyroData (needs new name)
- [ ] readMagData (needs new name)
Copy existing global functions to adequate require modules (π¦these functions does not exist in fz js):
- ir
- [x] read
- [x] readRaw
- [x] transmitFile
- display
- [x] color
- [x] fillScreen
- [x] setTextColor
- [x] setTextSize
- [x] drawString
- [x] setCursor
- [x] print
- [x] println
- [x] drawPixel
- [x] drawLine
- [x] drawRect
- [x] drawFillRect
- [x] drawJpg
- [x] drawGif
- [x] gifOpen
- [x] width
- [x] height
- fetch
- [x] implement
node-fetch.- I changed
httpfromfetch, because nodejs havehttpmodule which is creating a WebServer. - If we want to use node scripts or libraries from npm or other sources we need to comply to nodejs API.
- I changed
- [x] implement
- wifi
- [x] connect
- [x] connectDialog
- [x] disconnect
- [x] scan
- audio
- [x] playAudioFile
- [x] tone
Instead of a full refactoring , you could simply add a compatibility layer while keeping the old functions.
I didn't removed existing functions, old scripts are working normally.
I said refactor because in some cases I refratored some older functions to accept flipper zero syntax, but old syntax is working normally.
You know the mantra: "never break userspace" :-)
Progress so far: I've created docs for new API: https://github.com/Tawank/bruce-js-tooling/blob/master/packages/bruce-sdk/DOCS.md Added new functions and fixed existing functions.
I created dino game, http browser for bruce and tried to run NES emulator (failed). https://github.com/Tawank/bruce-js-tooling/tree/master/examples
To do:
- [ ] create test script to test all "new" API and "old" API. We need to be sure that old and new is working, and we will have testing so we see regress.
- [ ] give more examples in the docs
- [ ] add permissions, show dialog if script uses
httporstorageAPI, so user can agree, store permissions in the config file.