OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the SoD project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 |
| 5 import 'dart:dartino.ffi'; |
| 6 |
| 7 final ForeignFunction _setGpio = ForeignLibrary.main.lookup('gpio_set'); |
| 8 final ForeignFunction _getGpio = ForeignLibrary.main.lookup('gpio_get'); |
| 9 final ForeignFunction _getLedGpio = ForeignLibrary.main.lookup('led_get_gpio'); |
| 10 |
| 11 class LED { |
| 12 final int _id; |
| 13 |
| 14 const LED._internal(this._id); |
| 15 |
| 16 int get _gpio { |
| 17 int gpio = _getLedGpio.icall$1(_id); |
| 18 if (gpio < 0) throw new ArgumentError(); |
| 19 return gpio; |
| 20 } |
| 21 |
| 22 set state(bool value) => _setGpio.vcall$2(_gpio, value ? 1 : 0); |
| 23 |
| 24 bool get state => _getGpio.icall$1(_gpio) == 1 ? true : false; |
| 25 |
| 26 toggle() => state = !state; |
| 27 } |
| 28 |
| 29 const LED0 = const LED._internal(0); |
| 30 const LED1 = const LED._internal(1); |
| 31 const LED2 = const LED._internal(2); |
| 32 const LED3 = const LED._internal(3); |
OLD | NEW |