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

Unified Diff: dart/pkg/lk/lib/leds.dart

Issue 1684433003: Add a small LED interface and demo app. (Closed) Base URL: git@github.com:domokit/sod.git@master
Patch Set: added comment Created 4 years, 10 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
« no previous file with comments | « dart/examples/led/led.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « dart/examples/led/led.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698