Chromium Code Reviews| Index: dart/pkg/lk/lib/leds.dart |
| diff --git a/dart/pkg/lk/lib/leds.dart b/dart/pkg/lk/lib/leds.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2207e2741eb830f5ec64976a744a6e96661878e6 |
| --- /dev/null |
| +++ b/dart/pkg/lk/lib/leds.dart |
| @@ -0,0 +1,32 @@ |
| +// Copyright (c) 2016, the SoD 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. |
| + |
| +import 'dart:dartino.ffi'; |
| + |
| +final ForeignFunction _setGpio = ForeignLibrary.main.lookup('gpio_set'); |
| +final ForeignFunction _getGpio = ForeignLibrary.main.lookup('gpio_get'); |
| +final ForeignFunction _getLedGpio = ForeignLibrary.main.lookup('led_get_gpio'); |
| + |
| +class LED { |
| + final int _id; |
| + |
| + const LED._internal(this._id); |
| + |
| + int get _gpio { |
| + int gpio = _getLedGpio.icall$1(_id); |
| + if (gpio < 0) throw new ArgumentError(); |
| + return gpio; |
| + } |
| + |
| + set state(bool value) => _setGpio.vcall$2(_gpio, value ? 1 : 0); |
| + |
| + bool get state => _getGpio.icall$1(_gpio) == 1 ? true : false; |
| + |
| + toggle() => state = ! state; |
|
Søren Gjesse
2016/02/09 10:40:31
Remove space after !.
|
| +} |
| + |
| +const LED0 = const LED._internal(0); |
| +const LED1 = const LED._internal(1); |
| +const LED2 = const LED._internal(2); |
| +const LED3 = const LED._internal(3); |