Skip to content

Instantly share code, notes, and snippets.

@epietrowicz
epietrowicz / main.c
Last active October 8, 2020 14:31
main ble config
uint8 timerNotify = 0;
uint8 bleConnected = 0;
uint8 count = 0;
CYBLE_CONN_HANDLE_T connectionHandle;
static volatile uint32_t millisecondTimerCount = 0u;
/************************************************************
* This function is the handler for BLE stack events
*
* Arguments:
FloatingActionButton(
onPressed: () {
_ledChar.write([0xff, 0xff, 0xff, 0x10]);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
@epietrowicz
epietrowicz / defines.dart
Created May 13, 2020 15:05
characteristics
final FlutterBlue flutterBlue = FlutterBlue.instance;
BluetoothCharacteristic _ledChar;
var _myService = "bb89ad38-c3a8-4e49-8c9f-b15573ee9a70";
var _myChar = "a404a877-90d8-44ae-af73-92a17ede3d11";
@epietrowicz
epietrowicz / getledchar.dart
Created May 13, 2020 15:00
get characteristics
bool _getLEDChar(List<BluetoothService> services) {
for (BluetoothService s in services) {
if (s.uuid.toString() == _myService) {
var characteristics = s.characteristics;
for (BluetoothCharacteristic c in characteristics) {
if (c.uuid.toString() == _myChar) {
_ledChar = c;
return true;
}
}
void _connectDevice(BluetoothDevice device) async {
flutterBlue.stopScan();
try {
await device.connect();
} catch (e) {
if (e.code != 'already_connected') {
throw e;
}
} finally {
List<BluetoothService> services = await device.discoverServices();
void _incrementCounter() {
flutterBlue.scanResults.listen((List<ScanResult> results) {
for (ScanResult result in results) {
if (result.device.name == "customGlow") {
_connectDevice(result.device);
}
}
});
flutterBlue.startScan();
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
flutter_blue: ^0.7.2
@epietrowicz
epietrowicz / upload.dart
Last active May 1, 2020 14:19
filling in upload function
final String endPoint = 'http://10.0.2.2:8000/analyze';
void _upload(File file) async {
String fileName = file.path.split('/').last;
print(fileName);
FormData data = FormData.fromMap({
"file": await MultipartFile.fromFile(
file.path,
filename: fileName,
),
@epietrowicz
epietrowicz / picture.dart
Last active May 1, 2020 14:15
picture function
void _choose() async {
File file;
file = await ImagePicker.pickImage(
source: ImageSource.camera,
);
if (file != null) {
haveImg = true;
futureImg = _upload(file);
setState(() {});
@epietrowicz
epietrowicz / functions.dart
Last active May 1, 2020 14:14
renaming original functions
void _choose() async {
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(