From 2861bc52fdc4393daac5df308146b3159d77e2d0 Mon Sep 17 00:00:00 2001 From: sixteenmillimeter Date: Fri, 19 Mar 2021 14:09:46 -0400 Subject: [PATCH] intval2 connector firmware --- .../intval2_connector_firmware.ino | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 ino/intval2_connector_firmware/intval2_connector_firmware.ino diff --git a/ino/intval2_connector_firmware/intval2_connector_firmware.ino b/ino/intval2_connector_firmware/intval2_connector_firmware.ino new file mode 100644 index 0000000..1159fd5 --- /dev/null +++ b/ino/intval2_connector_firmware/intval2_connector_firmware.ino @@ -0,0 +1,123 @@ +/** + * This is a customized firmware originally designed to + * control the intval2. + * + * Pins + * 08 - Trigger for relay + */ + +boolean debug_state = false; +/* ------------------------------------------------ + * pins + * ------------------------------------------------*/ + +const int cam_pin = 8; + +boolean running = false; +boolean cam_dir = true; + +const int cam_time = 850; +const int cam_momentary = 130; +const int cam_delay = 42; + +const char cmd_camera = 'c'; +const char cmd_cam_forward = 'e'; +const char cmd_cam_backward = 'f'; + +const char cmd_debug = 'd'; +const char cmd_connect = 'i'; +volatile char cmd_char = 'z'; +const char cmd_mcopy_identifier = 'm'; +const char cmd_cam_identifier = 'k'; //cam only + +const int serialDelay = 5; + +void setup() { + Serial.begin(57600); + Serial.flush(); + Serial.setTimeout(serialDelay); + + Pins_init(); +} + +void loop() { + if (Serial.available()) { + /* read the most recent byte */ + cmd_char = (char)Serial.read(); + } + if (cmd_char != 'z') { + cmd(cmd_char); + cmd_char = 'z'; + } + + +} + +void cmd (char val) { + if (val == cmd_debug) { + debug(); + } else if (val == cmd_connect) { + connect(); + } else if (val == cmd_mcopy_identifier) { + identify(); + } else if (val == cmd_camera) { + Frame(); + } else if (val == cmd_cam_forward) { + cam_direction(true); //explicit + } else if (val == cmd_cam_backward) { + cam_direction(false); + } +} + +void debug () { + debug_state = true; + Serial.println(cmd_debug); + log("debugging enabled"); +} + +void connect () { + Serial.println(cmd_connect); + log("connect()"); +} + +void identify () { + Serial.println(cmd_cam_identifier); + log("identify()"); +} + +void Pins_init () { + pinMode(cam_pin, OUTPUT); + digitalWrite(cam_pin, LOW); +} + +void Frame () { + if (!running) { + running = true; + + digitalWrite(cam_pin, HIGH); + delay(cam_momentary); + digitalWrite(cam_pin, LOW); + + delay(cam_time - cam_momentary + cam_delay); + + Serial.println(cmd_camera); + log("Frame completed"); + running = false; + } +} + +void cam_direction (boolean state) { + cam_dir = state; + if (state) { + Serial.println(cmd_cam_forward); + log("cam_direction -> true"); + } else { + Serial.println(cmd_cam_backward); + log("cam_direction -> false"); + } +} +void log (String msg) { + if (debug_state) { + Serial.println(msg); + } +}