simple_frame_app 3.0.0 simple_frame_app: ^3.0.0 copied to clipboard
Flutter and Lua quickstart app scaffolding and standard library functions for Brilliant Frame development on Android/iOS
Flutter and Lua quickstart app scaffolding and standard library functions for Brilliant Frame development on Android/iOS. (iOS support intended but untested.)
Images #
Features #
- Connect/disconnect via bluetooth (
flutter_blue_plus
package) - Send and display Sprites on Frame (from both pre-made image assets and also dynamically-sourced)
- Send text for display on Frame (TxPlainText and TxTextSpriteBlock for Unicode/RTL)
- Request and process JPG images from Frame camera (
image
package) - Request magnetometer and accelerometer stream (IMU)
- Automatically loads custom Lua scripts onto Frame on app startup, deletes them on app exit
- Automatically loads sprite assets into Frame memory on app startup
- Framework for custom typed message sending and receiving (pack/parse standard and custom message types) that automatically handles messages larger than bluetooth MTU size
- Library of standard frameside Lua scripts (for generic accumulation of message data, battery, camera, sprites, text, IMU)
- Conventions for the use of minified Lua scripts
- Template for optional simple single-page phoneside Flutter app
- Template for standard frameside Lua app
Getting started #
- Create a Flutter mobile app
flutter pub add simple_frame_app
- Follow the
flutter_blue_plus
instructions for modifying configuration files on Android and iOS for Bluetooth LE support - On Android, also append
|navigation
to the long list inandroid:configChanges
to prevent app activity restarts on bluetooth connect/disconnect. - Copy template files
template/main.dart
andtemplate/frame_app.lua
to your project's lib/ and assets/ directories respectively (also see sample projects for examples of phoneside and frameside apps.) - Add assets to
pubspec.yaml
underflutter:
assets:
, both standard and custom, that you wish to send to Frame on app startup e.g.- packages/simple_frame_app/lua/camera.min.lua
for a standard Lua library, or- assets/sprites/20_mysprite.png
for an app-specific sprite. For the templateframe_app.lua
, add the following:
flutter:
assets:
- packages/simple_frame_app/lua/battery.min.lua
- packages/simple_frame_app/lua/data.min.lua
- packages/simple_frame_app/lua/code.min.lua
- packages/simple_frame_app/lua/plain_text.min.lua
- packages/simple_frame_app/lua/sprite.min.lua
- assets/frame_app.lua
Usage #
Phoneside (Flutter/Dart)
// send some ASCII text to Frame
await frame!.sendMessage(TxPlainText(msgCode: 0x12, text: 'Hello, Frame!'));
// asking Frame to take a photo and send it back
var takePhoto = TxCameraSettings(msgCode: 0x0d);
await frame!.sendMessage(takePhoto);
// synchronously await the image response encoded as a jpeg
Uint8List imageData = await RxPhoto(qualityLevel: 50).attach(frame!.dataResponse).first;
// send a custom message and value to the Lua app running on Frame
await frame!.sendMessage(TxCode(msgCode: 0x0e, value: 1));
// send a sprite to Frame with an identifying message code
var sprite = TxSprite.fromPngBytes(msgCode: 0x2F, pngBytes: bytesFromFileOrWeb);
await frame!.sendMessage(sprite);
Frameside (Lua)
-- Phone to Frame message codes
CAMERA_SETTINGS_MSG = 0x0d
HOTDOG_MSG = 0x0e
-- camera_settings message to take a photo
if (data.app_data[CAMERA_SETTINGS_MSG] ~= nil) then
rc, err = pcall(camera.camera_capture_and_send, data.app_data[CAMERA_SETTINGS_MSG])
if rc == false then
print(err)
end
-- clear the message
data.app_data[CAMERA_SETTINGS_MSG] = nil
end
-- hotdog classification 0 or 1
if (data.app_data[HOTDOG_MSG] ~= nil) then
if (data.app_data[HOTDOG_MSG].value == 1) then
if (data.app_data[HOTDOG_SPRITE] ~= nil) then
local spr = data.app_data[HOTDOG_SPRITE]
frame.display.bitmap(450, 136, spr.width, 2^spr.bpp, 0, spr.pixel_data)
end
end
frame.display.show()
-- clear the message
data.app_data[HOTDOG_MSG] = nil
end
Numerous example projects can be found in the CitizenOneX GitHub.
Additional information #
This is a work-in-progress personal project with limited support and frequent breaking changes; fixes and suggestions with PRs welcome.