|
| 1 | +import 'dart:typed_data'; |
| 2 | + |
| 3 | +import 'package:sane/sane.dart'; |
| 4 | + |
| 5 | +class SaneDev implements Sane { |
| 6 | + @override |
| 7 | + Future<void> cancel(SaneHandle handle) { |
| 8 | + return Future.delayed(const Duration(seconds: 1), () { |
| 9 | + print('sane_cancel()'); |
| 10 | + }); |
| 11 | + } |
| 12 | + |
| 13 | + @override |
| 14 | + Future<void> close(SaneHandle handle) { |
| 15 | + return Future.delayed(const Duration(seconds: 1), () { |
| 16 | + print('sane_close()'); |
| 17 | + }); |
| 18 | + } |
| 19 | + |
| 20 | + @override |
| 21 | + Future<SaneOptionResult<bool>> controlBoolOption({ |
| 22 | + required SaneHandle handle, |
| 23 | + required int index, |
| 24 | + required SaneAction action, |
| 25 | + bool? value, |
| 26 | + }) { |
| 27 | + return Future.delayed(const Duration(seconds: 1), () { |
| 28 | + print('sane_controlBoolOption()'); |
| 29 | + return SaneOptionResult(result: value ?? true, infos: []); |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + @override |
| 34 | + Future<SaneOptionResult<Null>> controlButtonOption({ |
| 35 | + required SaneHandle handle, |
| 36 | + required int index, |
| 37 | + }) { |
| 38 | + return Future.delayed(const Duration(seconds: 1), () { |
| 39 | + print('sane_controlButtonOption()'); |
| 40 | + return SaneOptionResult(result: null, infos: []); |
| 41 | + }); |
| 42 | + } |
| 43 | + |
| 44 | + @override |
| 45 | + Future<SaneOptionResult<double>> controlFixedOption({ |
| 46 | + required SaneHandle handle, |
| 47 | + required int index, |
| 48 | + required SaneAction action, |
| 49 | + double? value, |
| 50 | + }) { |
| 51 | + return Future.delayed(const Duration(seconds: 1), () { |
| 52 | + print('sane_controlFixedOption()'); |
| 53 | + return SaneOptionResult(result: value ?? .1, infos: []); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + @override |
| 58 | + Future<SaneOptionResult<int>> controlIntOption({ |
| 59 | + required SaneHandle handle, |
| 60 | + required int index, |
| 61 | + required SaneAction action, |
| 62 | + int? value, |
| 63 | + }) { |
| 64 | + return Future.delayed(const Duration(seconds: 1), () { |
| 65 | + print('sane_controlIntOption()'); |
| 66 | + return SaneOptionResult(result: value ?? 1, infos: []); |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | + @override |
| 71 | + Future<SaneOptionResult<String>> controlStringOption({ |
| 72 | + required SaneHandle handle, |
| 73 | + required int index, |
| 74 | + required SaneAction action, |
| 75 | + String? value, |
| 76 | + }) { |
| 77 | + return Future.delayed(const Duration(seconds: 1), () { |
| 78 | + print('sane_controlStringOption()'); |
| 79 | + return SaneOptionResult(result: value ?? 'value', infos: []); |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + @override |
| 84 | + Future<void> exit() { |
| 85 | + return Future(() { |
| 86 | + print('sane_exit()'); |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + @override |
| 91 | + Future<List<SaneOptionDescriptor>> getAllOptionDescriptors( |
| 92 | + SaneHandle handle, |
| 93 | + ) { |
| 94 | + return Future.delayed(const Duration(seconds: 1), () { |
| 95 | + print('sane_getAllOptionDescriptors()'); |
| 96 | + return [ |
| 97 | + SaneOptionDescriptor( |
| 98 | + index: 0, |
| 99 | + name: 'name', |
| 100 | + title: 'title', |
| 101 | + desc: 'desc', |
| 102 | + type: SaneOptionValueType.int, |
| 103 | + unit: SaneOptionUnit.none, |
| 104 | + size: 1, |
| 105 | + capabilities: [], |
| 106 | + constraint: null, |
| 107 | + ), |
| 108 | + ]; |
| 109 | + }); |
| 110 | + } |
| 111 | + |
| 112 | + @override |
| 113 | + Future<List<SaneDevice>> getDevices({ |
| 114 | + required bool localOnly, |
| 115 | + }) { |
| 116 | + return Future.delayed(const Duration(seconds: 1), () { |
| 117 | + print('sane_getDevices()'); |
| 118 | + return [ |
| 119 | + for (var i = 0; i < 3; i++) |
| 120 | + SaneDevice( |
| 121 | + name: 'name $i', |
| 122 | + vendor: 'Vendor$i', |
| 123 | + model: 'Model$i', |
| 124 | + type: 'Type$i', |
| 125 | + ), |
| 126 | + ]; |
| 127 | + }); |
| 128 | + } |
| 129 | + |
| 130 | + @override |
| 131 | + Future<SaneOptionDescriptor> getOptionDescriptor( |
| 132 | + SaneHandle handle, |
| 133 | + int index, |
| 134 | + ) { |
| 135 | + return Future.delayed(const Duration(seconds: 1), () { |
| 136 | + print('sane_getOptionDescriptor()'); |
| 137 | + return SaneOptionDescriptor( |
| 138 | + index: index, |
| 139 | + name: 'name', |
| 140 | + title: 'title', |
| 141 | + desc: 'desc', |
| 142 | + type: SaneOptionValueType.int, |
| 143 | + unit: SaneOptionUnit.none, |
| 144 | + size: 1, |
| 145 | + capabilities: [], |
| 146 | + constraint: null, |
| 147 | + ); |
| 148 | + }); |
| 149 | + } |
| 150 | + |
| 151 | + @override |
| 152 | + Future<SaneParameters> getParameters(SaneHandle handle) { |
| 153 | + return Future.delayed(const Duration(seconds: 1), () { |
| 154 | + print('sane_getParameters()'); |
| 155 | + return SaneParameters( |
| 156 | + format: SaneFrameFormat.gray, |
| 157 | + lastFrame: true, |
| 158 | + bytesPerLine: 800, |
| 159 | + pixelsPerLine: 100, |
| 160 | + lines: 100, |
| 161 | + depth: 8, |
| 162 | + ); |
| 163 | + }); |
| 164 | + } |
| 165 | + |
| 166 | + @override |
| 167 | + Future<int> init({ |
| 168 | + AuthCallback? authCallback, |
| 169 | + }) { |
| 170 | + return Future(() { |
| 171 | + print('sane_init()'); |
| 172 | + return 1; |
| 173 | + }); |
| 174 | + } |
| 175 | + |
| 176 | + @override |
| 177 | + Future<SaneHandle> open(String deviceName) { |
| 178 | + return Future.delayed(const Duration(seconds: 1), () { |
| 179 | + print('sane_open()'); |
| 180 | + return SaneHandle(deviceName: deviceName); |
| 181 | + }); |
| 182 | + } |
| 183 | + |
| 184 | + @override |
| 185 | + Future<SaneHandle> openDevice(SaneDevice device) { |
| 186 | + return Future.delayed(const Duration(seconds: 1), () { |
| 187 | + print('sane_openDevice()'); |
| 188 | + return SaneHandle(deviceName: device.name); |
| 189 | + }); |
| 190 | + } |
| 191 | + |
| 192 | + @override |
| 193 | + Future<Uint8List> read(SaneHandle handle, int bufferSize) { |
| 194 | + return Future.delayed(const Duration(seconds: 1), () { |
| 195 | + print('sane_read()'); |
| 196 | + return Uint8List.fromList([]); |
| 197 | + }); |
| 198 | + } |
| 199 | + |
| 200 | + @override |
| 201 | + Future<void> setIOMode(SaneHandle handle, SaneIOMode mode) { |
| 202 | + return Future.delayed(const Duration(seconds: 1), () { |
| 203 | + print('sane_setIOMode()'); |
| 204 | + }); |
| 205 | + } |
| 206 | + |
| 207 | + @override |
| 208 | + Future<void> start(SaneHandle handle) { |
| 209 | + return Future.delayed(const Duration(seconds: 1), () { |
| 210 | + print('sane_start()'); |
| 211 | + }); |
| 212 | + } |
| 213 | +} |
0 commit comments