55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
Dart
|
import 'package:dart_periphery/dart_periphery.dart';
|
||
|
import 'package:logging/logging.dart';
|
||
|
|
||
|
class X9c10x {
|
||
|
int ohm;
|
||
|
late GPIO inc;
|
||
|
late GPIO ud;
|
||
|
late GPIO? ss;
|
||
|
final log = Logger("X9C10X");
|
||
|
late Function() onSelect;
|
||
|
late Function() onRelease;
|
||
|
|
||
|
X9c10x({
|
||
|
required this.ohm,
|
||
|
required int gpioChip,
|
||
|
required int pinInc,
|
||
|
required int pinUd,
|
||
|
int? pinSs}){
|
||
|
inc = GPIO(pinInc, GPIOdirection.gpioDirOutHigh, gpioChip);
|
||
|
ud = GPIO(pinUd, GPIOdirection.gpioDirOutHigh, gpioChip);
|
||
|
ss = pinSs != null ? GPIO(pinSs, GPIOdirection.gpioDirOutHigh, gpioChip) : null;
|
||
|
onSelect = selectChip;
|
||
|
onRelease = releaseChip;
|
||
|
}
|
||
|
|
||
|
void setCallBack(Function() onSelect, Function() onRelease){
|
||
|
this.onSelect = onSelect;
|
||
|
this.onRelease = onRelease;
|
||
|
}
|
||
|
|
||
|
void selectChip()=>ss?.write(false);
|
||
|
void releaseChip()=>ss?.write(true);
|
||
|
|
||
|
void wipeUp(){
|
||
|
onSelect.call();
|
||
|
ud.write(true);
|
||
|
const Duration(microseconds: 3);
|
||
|
inc.write(false);
|
||
|
const Duration(microseconds: 1);
|
||
|
inc.write(true);
|
||
|
onRelease.call();
|
||
|
}
|
||
|
|
||
|
void wipeDown(){
|
||
|
onSelect.call();
|
||
|
ud.write(false);
|
||
|
const Duration(microseconds: 3);
|
||
|
inc.write(false);
|
||
|
const Duration(microseconds: 1);
|
||
|
inc.write(true);
|
||
|
onRelease.call();
|
||
|
}
|
||
|
|
||
|
}
|