From 3117096ab99c73f9a51ed46b9447b640d31a652f Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Mon, 18 Mar 2019 01:49:39 +0200 Subject: 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 --- src/device/main.ino | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/device/meson.build | 17 ++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/device/main.ino create mode 100644 src/device/meson.build (limited to 'src/device') 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 + +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; +} diff --git a/src/device/meson.build b/src/device/meson.build new file mode 100644 index 0000000..9bb9b69 --- /dev/null +++ b/src/device/meson.build @@ -0,0 +1,17 @@ +fw_image = 'fw.bin' +if get_option('fwbuild') + espmake = find_program('espmake') + + sourcedir = meson.current_source_dir() + fw_filenames = ['main.ino'] + fw_sources = files(fw_filenames) + fw = custom_target('fw', + output : fw_image, + input : fw_sources, + command : [espmake, '-C', sourcedir, '&&', 'cp', '/tmp/mkESP/main_d1_mini/main.bin', '@OUTDIR@/' + fw_image], install : true, install_dir : resource_dir) + + if get_option('fwflash') + esptool = find_program('esptool.py') + run_target('flash_fw', depends : fw, command : [esptool, 'write_flash', '0x0', fw]) + endif +endif -- cgit v1.2.3