Chromium Code Reviews| 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; |
|
sigurdm
2015/10/05 07:22:18
Should these have a default "do nothing" value?
Ma
Søren Gjesse
2015/10/05 07:43:39
Let's iterate in this. In principle I agree that t
|
| + 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); |
| + 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; |
| + } |
| +} |