summaryrefslogtreecommitdiffstats
path: root/src/device/main.ino
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-03-18 01:49:39 +0200
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2019-03-18 01:49:39 +0200
commit3117096ab99c73f9a51ed46b9447b640d31a652f (patch)
treeb1506de569b6a55cf55d2a4ea14aa24d4699b726 /src/device/main.ino
downloadusurpation-3117096ab99c73f9a51ed46b9447b640d31a652f.tar.gz
usurpation-3117096ab99c73f9a51ed46b9447b640d31a652f.tar.bz2
usurpation-3117096ab99c73f9a51ed46b9447b640d31a652f.zip
Initial commit.
This creates a working buildable dummy template to build the project upon. Everything save for the build system are demonstrational dummies and everything including the build system is written to be easily extendable. This commit closes Ticket 5. Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/device/main.ino')
-rw-r--r--src/device/main.ino62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/device/main.ino b/src/device/main.ino
new file mode 100644
index 0000000..b028d17
--- /dev/null
+++ b/src/device/main.ino
@@ -0,0 +1,62 @@
+/*
+ * Usurpation – wearable device main logic
+ *
+ * Copyright (C) 2019 Gediminas Jakutis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+
+static const unsigned int internal_led = 2;
+
+unsigned int toggleled(void);
+
+void setup(void)
+{
+ pinMode(internal_led, OUTPUT);
+
+ /* don't set pin mode here, it will get toggled at the very start of
+ * the logic loop, either way.
+ */
+}
+
+/* the logic is a placeholder right now */
+void loop(void)
+{
+ /* sleep length to use */
+ static unsigned int delta = 100;
+
+ /* progresivelly grow the time delta while changing state*/
+ delta += delta >> (6 + toggleled());
+
+ /* sleep */
+ delay(delta);
+}
+
+/* toggle the bult-in led and return current state */
+unsigned int toggleled(void)
+{
+ static unsigned int state = 0;
+
+ state = !state;
+ /* as the cathode of the builtin diode is connected to the MCU's pin,
+ * while the anode is connected to Vcc, to turn it off, we need to set
+ * the pin to HIGH.
+ */
+ digitalWrite(internal_led, state ? LOW : HIGH);
+
+ return state;
+}