Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Unified Diff: pkg/gpio/lib/gpio_mock.dart

Issue 1389573002: Refactor Raspberry Pi GPIO and add GPIO mock (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: Removed unused code Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/gpio/lib/gpio_mock.dart
diff --git a/pkg/gpio/lib/gpio_mock.dart b/pkg/gpio/lib/gpio_mock.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a2c0c53854d8a6e626f24126c09ba44c8c5834a9
--- /dev/null
+++ b/pkg/gpio/lib/gpio_mock.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE.md file.
+library gpio_mock;
+
+import 'package:gpio/gpio.dart';
+
+/// Mock implementation of the GPIO interface.
+class MockGPIO extends GPIOBase {
+ Function _setPin;
+ Function _getPin;
+
+ List<bool> _pinValues;
+
+ MockGPIO([int pins = GPIO.defaultPins]) : super(pins) {
+ _pinValues = new List.filled(pins, false);
+ }
+
+ /// The simulated values of the pins.
+ ///
+ /// The default ´getPin´ will return the value in this `List`. The default
+ /// ´setPin´ will update it. Initially all values are ´false´.
+ List<bool> get pinValues => _pinValues;
+
+ void setMode(int pin, Mode mode) {
+ checkPinRange(pin);
wibling 2015/10/05 07:43:37 NIT: You could enforce the mode on get/set pin, e.
+ print('Setting mode for pin $pin to $mode');
+ }
+
+ Mode getMode(int pin) {
+ checkPinRange(pin);
+ print('Reading mode of pin $pin');
+ }
+
+ void setPin(int pin, bool value) {
+ checkPinRange(pin);
+ if (_setPin == null) {
+ _pinValues[pin] = value;
+ print('Writing pin $pin value $value');
+ } else {
+ _setPin(pin, value);
+ }
+ }
+
+ bool getPin(int pin) {
+ checkPinRange(pin);
+ if (_getPin == null) {
+ bool value = _pinValues[pin];
+ print('Reading pin $pin value $value');
+ return value;
+ } else {
+ return _getPin(pin);
+ }
+ }
+
+ /// Register ´callback´ to be called for ´setPin´.
+ void registerSetPin(void callback(int pin, bool value)) {
+ _setPin = callback;
+ }
+
+ /// Register ´callback´ to be called for ´getPin´.
+ void registerGetPin(bool callback(int pin)) {
+ _getPin = callback;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698