wiring 1.0.1 copy "wiring: ^1.0.1" to clipboard
wiring: ^1.0.1 copied to clipboard

PlatformAndroid

OrangePI WiringOP Binding for Flutter Android.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:wiring/wiring.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final WiringOP _wOP;

  @override
  void initState() {
    super.initState();
    // 调用初始化方法初始化WiringOP
    //
    // Init WiringOP
    _onInit();
  }

  void _onInit() async {
    // Setup 1:
    // 获取WiringOP操作对象, 烧录的Android需要具备ROOT权限(一般都具备), 否则su命令不存在,
    // 会自调用Process并执行 'su -c chmod 666 /dev/mem'
    //
    // execute shell 'su -c chmod 666 /dev/mem'
    _wOP = await WiringOP.get();

    // Setup 2:
    // 设置当前使用的模组, 因为 piBoardId 方法在Android中不可用, 所以使用手动方式设置
    //
    // set current model
    _wOP.wiringPiSetModel(PI_MODEL_5_PRO);

    // Setup 3:
    // 之后就可以像C/C++中一样调用方法即可
    //
    // like of C/C++ to call
    _wOP.wiringPiSetup();

    // Example:
    // OrangePI 5 Pro一共40个引脚, 其中28个可作为普通GPIO使用,
    // 具体调用传参请参考自己的板型
    //
    // 40 pin(s) by OrangePI 5 Pro, only 28 pin(s) can use by GPIO,
    // please read your model manual to call WiringOP method(s).
    for (var x = 0; x < 28; x++) {
      _wOP.pinMode(x, INPUT); // or OUTPUT
      _wOP.pullUpDnControl(x, PUD_DOWN); // or PUD_UP/PUD_OFF
    }

    // Read GPIO(s) level value.
    for (var x = 0; x < 28; x++) {
      final value = _wOP.digitalRead(x);
      // _wOP.digitalWrite(x, HIGH); // or LOW
      if (kDebugMode) print('PIN=$x LEVEL=$value');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: Scaffold(body: Container()));
  }
}
0
likes
130
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

OrangePI WiringOP Binding for Flutter Android.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

ffi, flutter, plugin_platform_interface

More

Packages that depend on wiring

Packages that implement wiring