From 0a8cd3b35b18a6d98ed14dff0a6e2418b377f67a Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Fri, 15 May 2020 23:21:54 -0700 Subject: [PATCH 1/9] adde bluetooth and wifi mode --- .../LIS3DHGestureRecorder.ino | 147 ++++- .../Arduino/LIS3DHGestureRecorder/common.h | 29 + .../GestureRecorder/GestureRecorder.pde | 500 ++++++++++-------- 3 files changed, 435 insertions(+), 241 deletions(-) create mode 100644 Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino index 6c4b181..4d42b71 100644 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino @@ -1,57 +1,98 @@ /* - * Reads in the x, y, and z accelerometer values from the LIS3DH and a "record gesture" button - * state and prints the following CSV to serial: timestamp, x, y, z, buttonState - * - * By Jon E. Froehlich - * @jonfroehlich - * http://makeabilitylab.io - * - */ + Reads in the x, y, and z accelerometer values from the LIS3DH and a "record gesture" button + state and prints the following CSV to serial: timestamp, x, y, z, buttonState + By Jon E. Froehlich + @jonfroehlich + http://makeabilitylab.io + +*/ +#include #include #include +#include "common.h" #include #include +#include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino // Used for LIS3DH hardware & software SPI #define LIS3DH_CS 10 Adafruit_LIS3DH lis = Adafruit_LIS3DH(); const boolean INCLUDE_TIMESTAMP = true; // print out timestamp to serial -const int BUTTON_INPUT_PIN = 21; // hooked up with pull-up configuration -const int SERIAL_BAUD_RATE = 115200; // make sure this matches the value in GestureRecorder.pde -const int DELAY_MS = 10; // the loop delay +const int BUTTON_INPUT_PIN = 21; // hooked up with pull-up configuration +const int DELAY_MS = 10; // the loop delay + +// Common data objects +BluetoothSerial ESP_BT; //Object for Bluetooth +// Use WiFiClient class to create TCP connections +WiFiClient ESP_WIFI; -void setup() { + +void setup() +{ Serial.begin(SERIAL_BAUD_RATE); Serial.println("Initializing accelerometer..."); - if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address + if (!lis.begin(0x18)) + { // change this to 0x19 for alternative i2c address Serial.println("Couldnt start"); - while (1) yield(); + while (1) + yield(); } Serial.println("LIS3DH found!"); - lis.setRange(LIS3DH_RANGE_4_G); // 2, 4, 8 or 16 G! + lis.setRange(LIS3DH_RANGE_4_G); // 2, 4, 8 or 16 G! Serial.print("Range = "); Serial.print(2 << lis.getRange()); Serial.println("G"); + // Setup Bluetooth if we want + if (CURRENT_MODE == RECORDER_BLUETOOTH) { + if (!ESP_BT.begin(ARDUINO_BT_NAME)) { + Serial.println("We failed to start Bluetooth"); + } + ESP_BT.setPin("1234"); + Serial.println("Bluetooth started"); + while (!ESP_BT.isReady()) { + Serial.println("Waiting for Bluetooth..."); + vTaskDelay(1000); // this is similar to yield and allows the device to go to low power mode + } + } + else if (CURRENT_MODE == RECORDER_WIFI) { + WiFi.begin(WIFI_SSID, WIFI_PASS); + Serial.print("Connecting."); + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + vTaskDelay(500); // this is similar to yield and allows the device to go to low power mode + } + Serial.print("WiFi connected - IP address: "); + Serial.println(WiFi.localIP()); + if (!ESP_WIFI.connect(WIFI_HOST_IP_ADDRESS, WIFI_HOST_PORT)) { + Serial.print("Failed to connect to "); + Serial.print(WIFI_HOST_IP_ADDRESS); + Serial.print(":"); + Serial.print(WIFI_HOST_PORT); + Serial.println(); + while(1) vTaskDelay(5000); + } + Serial.println("Connected to host"); + ESP_WIFI.println("Hello"); + } + pinMode(BUTTON_INPUT_PIN, INPUT_PULLUP); } -void loop() { - - // Read accel data - lis.read(); - +void serial_output() +{ int buttonVal = digitalRead(BUTTON_INPUT_PIN); - if(INCLUDE_TIMESTAMP){ + if (INCLUDE_TIMESTAMP) + { Serial.print(millis()); Serial.print(", "); } - + Serial.print(lis.x); Serial.print(", "); Serial.print(lis.y); @@ -60,8 +101,68 @@ void loop() { Serial.print(", "); Serial.print(!buttonVal); // because pull-up Serial.println(); +} + +void bluetooth_output() +{ + int buttonVal = digitalRead(BUTTON_INPUT_PIN); + + if (INCLUDE_TIMESTAMP) + { + ESP_BT.print(millis()); + ESP_BT.print(", "); + } + ESP_BT.print(lis.x); + ESP_BT.print(", "); + ESP_BT.print(lis.y); + ESP_BT.print(", "); + ESP_BT.print(lis.z); + ESP_BT.print(", "); + ESP_BT.print(!buttonVal); // because pull-up + ESP_BT.println(); +} + +void wifi_output() +{ + int buttonVal = digitalRead(BUTTON_INPUT_PIN); + + if (INCLUDE_TIMESTAMP) + { + ESP_WIFI.print(millis()); + ESP_WIFI.print(", "); + } + ESP_WIFI.print(lis.x); + ESP_WIFI.print(", "); + ESP_WIFI.print(lis.y); + ESP_WIFI.print(", "); + ESP_WIFI.print(lis.z); + ESP_WIFI.print(", "); + ESP_WIFI.print(!buttonVal); // because pull-up + ESP_WIFI.println(); +} + +void loop() +{ + + // Read accel data + lis.read(); + + // Then output our stuff + switch (CURRENT_MODE) + { + case RECORDER_SERIAL: + serial_output(); + break; + case RECORDER_BLUETOOTH: + bluetooth_output(); + break; + case RECORDER_WIFI: + wifi_output(); + break; + } - if(DELAY_MS > 0){ + if (DELAY_MS > 0) + { delay(DELAY_MS); } } diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h new file mode 100644 index 0000000..cce2fb4 --- /dev/null +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h @@ -0,0 +1,29 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +enum RecoderMode { + RECORDER_SERIAL, + RECORDER_BLUETOOTH, + RECORDER_WIFI +}; +// By default we use serial +const RecoderMode CURRENT_MODE = RECORDER_BLUETOOTH; + +// ------------------------------------------- +// Serial info +const int SERIAL_BAUD_RATE = 115200; + +// ------------------------------------------- +// Bluetooth settings +const char* ARDUINO_BT_NAME = "ESP32 Gesture Recorder"; +// Bluetooth uses the serial baud rate and port index above + +// ------------------------------------------- +// WIFI +// If using wifi, make sure to put your credentials there if you're using WIFI mode +const char* WIFI_SSID = ""; +const char* WIFI_PASS = ""; +const char* WIFI_HOST_IP_ADDRESS = ""; // The IP address of the host you want to connect to +const int WIFI_HOST_PORT = 10002; // The IP address of the host you want to connect to + +#endif diff --git a/Processing/GestureRecorder/GestureRecorder.pde b/Processing/GestureRecorder/GestureRecorder.pde index 7f8c28d..0ee1bae 100644 --- a/Processing/GestureRecorder/GestureRecorder.pde +++ b/Processing/GestureRecorder/GestureRecorder.pde @@ -24,11 +24,12 @@ * - GUI to select which gesture to record * */ - + import processing.serial.*; import java.awt.Rectangle; import java.io.BufferedWriter; import java.io.FileWriter; +import processing.net.*; final String GESTURE_DIR_NAME = "Gestures"; final String FULL_DATASTREAM_RECORDING_FILENAME = "fulldatastream.csv"; @@ -45,7 +46,13 @@ final int DISPLAY_TIMEWINDOW_MS = 1000 * 20; // 20 secs. You can change this to // Make sure to change this! If you're not sure what port your Arduino is using // Run this Processing sketch and look in the console, then change the number accordingly -final int ARDUINO_SERIAL_PORT_INDEX = 0; // CHANGE THIS TO APPROPRIATE PORT! + +final String ARDUINO_SERIAL_PORT_NAME = "COM5"; // CHANGE THIS TO APPROPRIATE PORT! +// WIFI SETTINGS +// This should be false even in bluetooth mode since that just emulates a com port +final boolean ARDUINO_WIFI_MODE = false; // CHANGE THIS TO TRUE IF AND ONLY IF YOU ARE USING WIFI MODE +final int ARDUINO_WIFI_PORT = 10002; // THIS IS THE PORT THAT THEY WILL TRY TO COMMUNICATE OVER + // Set the baud rate to same as Arduino (e.g., 9600 or 115200) final int SERIAL_BAUD_RATE = 115200; // CHANGE THIS TO MATCH BAUD RATE ON ARDUINO @@ -64,6 +71,10 @@ PrintWriter _printWriterAllData; // The serial port is necessary to read data in from the Arduino Serial _serialPort; +// Wifi server +Server myServer; + + long _currentXMin; // the far left x-axis value on the graph Rectangle _legendRect; // location and drawing area of the legend boolean _dynamicYAxis = true; @@ -79,8 +90,8 @@ final int NUM_SAMPLES_TO_RECORD_PER_GESTURE = 5; // Feel free to rename "Custom" to something that is more semantically meaningful describing your custom gesture // For example, I did "Bunny Hops" final String [] GESTURES = { "Backhand Tennis", "Forehand Tennis", "Underhand Bowling", - "Baseball Throw", "Midair Clockwise 'O'", "At Rest", "Midair Counter-clockwise 'O'", - "Midair Zorro 'Z'", "Midair 'S'", "Shake", "Custom" }; + "Baseball Throw", "Midair Clockwise 'O'", "At Rest", "Midair Counter-clockwise 'O'", + "Midair Zorro 'Z'", "Midair 'S'", "Shake", "Custom" }; int _curGestureIndex = 0; HashMap _mapGestureNameToRecordedCount = new HashMap(); // tracks recorded gesture counts ArrayList _gestureRecordings = new ArrayList(); // sensor data to dump to file @@ -93,76 +104,91 @@ final int MIN_TIME_BETWEEN_GESTURE_TOGGLE_MS = 500; void setup() { size(1024, 576); - + String filenameNoPath = FULL_DATASTREAM_RECORDING_FILENAME; - - if(_createNewFullDatastreamFileOnEveryExecution){ + + if (_createNewFullDatastreamFileOnEveryExecution) { String filenameWithoutExt = filenameNoPath.substring(0, filenameNoPath.length()-4); String filenameExt = filenameNoPath.substring(filenameNoPath.length()-4, filenameNoPath.length()); filenameNoPath = filenameWithoutExt + System.currentTimeMillis() + filenameExt; } - + File fDir = new File(sketchPath(GESTURE_DIR_NAME)); - if(!fDir.exists()){ - fDir.mkdirs(); + if (!fDir.exists()) { + fDir.mkdirs(); } File file = new File(fDir, filenameNoPath); - + _fullDataStreamFilenameWithPath = file.getAbsolutePath(); println("Saving accel data to: " + _fullDataStreamFilenameWithPath); - + try { - // We save all incoming sensor data to a file (by appending) + // We save all incoming sensor data to a file (by appending`) // Appending text to a file: // - https://stackoverflow.com/questions/17010222/how-do-i-append-text-to-a-csv-txt-file-in-processing // - https://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html // - Use sketchPath(string) to store in local sketch folder: https://stackoverflow.com/a/36531925 _printWriterAllData = new PrintWriter(new BufferedWriter(new FileWriter(file, true))); - }catch (IOException e){ - e.printStackTrace(); } - - // Print to console all the available serial ports - String [] serialPorts = getAndPrintSerialPortInfo(); - - if(serialPorts.length <= 0){ - println("You appear to have *ZERO* active serial ports. Make sure your Arduino is plugged in. Exiting..."); - exit(); - }else if(ARDUINO_SERIAL_PORT_INDEX > serialPorts.length){ - println("You set ARDUINO_SERIAL_PORT_INDEX = " + ARDUINO_SERIAL_PORT_INDEX + "; however, you only have " + - serialPorts.length + " total serial ports."); - println("Please make sure your Arduino is plugged in. Then update ARDUINO_SERIAL_PORT_INDEX to the appropriate index."); - println("Exiting..."); - exit(); - return; - } - - // Open the serial port - try{ - println("Attempting to initialize the serial port at index " + ARDUINO_SERIAL_PORT_INDEX + " with baud rate = " + SERIAL_BAUD_RATE); - println("This index corresponds to serial port " + serialPorts[ARDUINO_SERIAL_PORT_INDEX]); - _serialPort = new Serial(this, serialPorts[ARDUINO_SERIAL_PORT_INDEX], SERIAL_BAUD_RATE); - - // We need to clear the port (or sometimes there is leftover data) - // (Yes, this is strange, but once we implemented this clear, - // we were no longer seeing garbage data in the beginning of our printwriter - // strea,) - _serialPort.clear(); - }catch(Exception e){ - println("Serial port exception: " + e); + catch (IOException e) { e.printStackTrace(); - exit(); - return; } - if(_serialPort == null){ - println("Could not initialize the serial port at " + ARDUINO_SERIAL_PORT_INDEX + ". Exiting..."); - exit(); - return; + if (ARDUINO_WIFI_MODE) { + //https://www.processing.org/reference/libraries/net/Server.html + myServer = new Server(this, ARDUINO_WIFI_PORT); + print("Starting server"); + while (!myServer.active()) { + print("."); + delay(50); + } + println("\nWe have started a server at "+Server.ip()); + thread("processServer"); // start a thread that reads for the server + } else { + + // Print to console all the available serial ports + String [] serialPorts = getAndPrintSerialPortInfo(); + + if (serialPorts.length <= 0) { + println("You appear to have *ZERO* active serial ports. Make sure your Arduino is plugged in. Exiting..."); + exit(); + } + + int ARDUINO_SERIAL_PORT_INDEX = getIndexOfArduinoSerialPort(); + + if (ARDUINO_SERIAL_PORT_INDEX == -1) { + println("Could not find the serial port: " + ARDUINO_SERIAL_PORT_NAME + ". Exiting..."); + exit(); + } + + // Open the serial port + try { + println("Attempting to initialize the serial port " + ARDUINO_SERIAL_PORT_NAME + " with baud rate = " + SERIAL_BAUD_RATE); + println("This index corresponds to serial port at index: " + ARDUINO_SERIAL_PORT_INDEX); + _serialPort = new Serial(this, serialPorts[ARDUINO_SERIAL_PORT_INDEX], SERIAL_BAUD_RATE); + + // We need to clear the port (or sometimes there is leftover data) + // (Yes, this is strange, but once we implemented this clear, + // we were no longer seeing garbage data in the beginning of our printwriter + // strea,) + _serialPort.clear(); + } + catch(Exception e) { + println("Serial port exception: " + e); + e.printStackTrace(); + exit(); + return; + } + + if (_serialPort == null) { + println("Could not initialize the serial port at " + ARDUINO_SERIAL_PORT_INDEX + ". Exiting..."); + exit(); + return; + } + + // Don't generate a serialEvent() unless you get a newline character: + _serialPort.bufferUntil('\n'); } - - // Don't generate a serialEvent() unless you get a newline character: - _serialPort.bufferUntil('\n'); _currentXMin = System.currentTimeMillis() - DISPLAY_TIMEWINDOW_MS; @@ -170,7 +196,7 @@ void setup() { int legendWidth = 200; int legendXBuffer = 60; int legendYBuffer = 5; - + //_legendRect = new Rectangle(width - legendWidth - legendXBuffer, legendYBuffer, legendWidth, legendHeight); // legend at top-right _legendRect = new Rectangle(legendXBuffer, legendYBuffer, legendWidth, legendHeight); // legend at top-left @@ -179,40 +205,40 @@ void setup() { } void draw() { - + if (_recordingGesture) { background(RECORDING_BACKGROUND_COLOR); } else { background(DEFAULT_BACKGROUND_COLOR); } - + // Check for new sensor data ArrayList newData = null; - synchronized(_sensorBuffer){ + synchronized(_sensorBuffer) { newData = new ArrayList(_sensorBuffer); _sensorBuffer.clear(); } - + // Dump new data into _displaySensorData and curGestureRecording - for(int i = 0; i < newData.size(); i++){ + for (int i = 0; i < newData.size(); i++) { AccelSensorData accelSensorData = newData.get(i); checkAndSetNewMinMaxSensorValues(accelSensorData); _displaySensorData.add(accelSensorData); - - if(_recordingGesture){ + + if (_recordingGesture) { GestureRecording curGestureRecording = _gestureRecordings.get(_gestureRecordings.size() - 1); curGestureRecording.listSensorData.add(accelSensorData); } } - + // Remove data that is no longer relevant to be displayed - while(_displaySensorData.size() > 0 && - _displaySensorData.get(0).timestamp < _currentXMin){ + while (_displaySensorData.size() > 0 && + _displaySensorData.get(0).timestamp < _currentXMin) { _displaySensorData.remove(0); } - + drawYAxis(); - + //println("Drawing! _displaySensorData.size()=" + _displaySensorData.size() + " _timeWindowMs=" + _timeWindowMs); for (int i = 1; i < _displaySensorData.size(); i++) { AccelSensorData lastAccelSensorData = _displaySensorData.get(i - 1); @@ -222,17 +248,17 @@ void draw() { drawSensorLine(YCOLOR, lastAccelSensorData.timestamp, lastAccelSensorData.y, curAccelSensorData.timestamp, curAccelSensorData.y); drawSensorLine(ZCOLOR, lastAccelSensorData.timestamp, lastAccelSensorData.z, curAccelSensorData.timestamp, curAccelSensorData.z); } - + long curTimestampMs = System.currentTimeMillis(); long elapsedTimeMs = curTimestampMs - _timestampStartCountdownMs; int countdownTimeSecs = (int)((COUNTDOWN_TIME_MS - elapsedTimeMs) / 1000.0); - + if (_timestampStartCountdownMs != -1 && countdownTimeSecs <= 0 && !_recordingGesture) { _recordingGesture = true; GestureRecording gestureRecording = new GestureRecording(GESTURE_DIR_NAME, GESTURES[_curGestureIndex], curTimestampMs); _gestureRecordings.add(gestureRecording); } - + drawInstructions(countdownTimeSecs); drawGestureRecordingAnnotations(); drawLegend(_legendRect); @@ -242,24 +268,24 @@ void draw() { /** * Writes out recording status to the screen - */ -void drawRecordingStatus(){ + */ +void drawRecordingStatus() { textSize(10); float strHeight = textAscent() + textDescent(); float yText = height - (strHeight * GESTURES.length) - 3; noStroke(); - - for(int i = 0; i < GESTURES.length; i++){ + + for (int i = 0; i < GESTURES.length; i++) { int sampleNum = min(getNumGesturesRecordedWithName(GESTURES[i]) + 1, NUM_SAMPLES_TO_RECORD_PER_GESTURE); String str = GESTURES[i] + " (" + sampleNum + "/" + NUM_SAMPLES_TO_RECORD_PER_GESTURE + ")"; float strWidth = textWidth(str) + 10; - - if(_curGestureIndex == i){ + + if (_curGestureIndex == i) { fill(0, 240, 0, 230); - }else{ + } else { fill(255, 255, 255, 200); } - + text(str, width- strWidth, yText); yText += strHeight; } @@ -268,18 +294,17 @@ void drawRecordingStatus(){ /** * Writes out basic instructions for the user */ -void drawInstructions(int countdownTimeSecs){ - - +void drawInstructions(int countdownTimeSecs) { + + String strInstructions = ""; textSize(30); noStroke(); fill(255, 255, 255, 200); - if(_displaySensorData.size() <= 0){ + if (_displaySensorData.size() <= 0) { textSize(50); strInstructions = "Waiting for Serial data..."; - } - else if(_timestampStartCountdownMs != -1){ + } else if (_timestampStartCountdownMs != -1) { // if we're here, the user hit the spacebar and we're either ready to record or recording // draw center of screen String str = ""; @@ -291,15 +316,14 @@ void drawInstructions(int countdownTimeSecs){ float strWidth = textWidth(str); float yText = height / 4.0 + strHeight / 2.0 - textDescent(); text(str, width / 2.0 - strWidth / 2.0, yText); - + textSize(20); str = "Hit SPACEBAR or BUTTON to stop recording."; strWidth = textWidth(str); - + yText += strHeight + 2; - + text(str, width / 2.0 - strWidth / 2.0, yText); - } else { // counting down textSize(35); @@ -307,28 +331,27 @@ void drawInstructions(int countdownTimeSecs){ float strWidth = textWidth(str); float strHeight = textAscent() + textDescent(); text(str, width / 2.0 - strWidth / 2.0, height / 4.0 + strHeight / 2.0 - textDescent()); - + textSize(80); str = String.format("%d", countdownTimeSecs); strHeight = textAscent() + textDescent(); strWidth = textWidth(str); text(str, width / 2.0 - strWidth / 2.0, height / 2.0 + strHeight / 2.0 - textDescent()); } - } - else if(_curGestureIndex < GESTURES.length){ + } else if (_curGestureIndex < GESTURES.length) { textSize(30); fill(255, 255, 255); int sampleNum = getNumGesturesRecordedWithName(GESTURES[_curGestureIndex]) + 1; strInstructions = "Hit SPACEBAR or BUTTON to record sample " + sampleNum + "/" + NUM_SAMPLES_TO_RECORD_PER_GESTURE - + " of gesture:\n'" + GESTURES[_curGestureIndex] + "'"; - }else{ + + " of gesture:\n'" + GESTURES[_curGestureIndex] + "'"; + } else { strInstructions = "You did it! Gesture recording completed!"; } - - if(strInstructions.length() > 0){ + + if (strInstructions.length() > 0) { float strWidth = textWidth(strInstructions); float strHeight = textAscent() + textDescent(); - + text(strInstructions, width / 2.0 - strWidth / 2.0, height / 4.0 + strHeight / 2.0 - textDescent()); } } @@ -342,36 +365,35 @@ void keyPressed() { } } -void toggleGestureRecording(){ +void toggleGestureRecording() { long currentTimestampMs = System.currentTimeMillis(); long elapsedTime = currentTimestampMs - _timestampSinceLastGestureRecordToggle; - - if(elapsedTime > MIN_TIME_BETWEEN_GESTURE_TOGGLE_MS){ + + if (elapsedTime > MIN_TIME_BETWEEN_GESTURE_TOGGLE_MS) { _timestampSinceLastGestureRecordToggle = currentTimestampMs; if (_recordingGesture) { // if the spacebar was pressed and we're currently recording a gesture // then the spacebar just ended the gesture _recordingGesture = false; _timestampStartCountdownMs = -1; - + GestureRecording curGestureRecording = _gestureRecordings.get(_gestureRecordings.size() - 1); curGestureRecording.endTimestamp = currentTimestampMs; curGestureRecording.save(); - - if(!_mapGestureNameToRecordedCount.containsKey(curGestureRecording.name)){ + + if (!_mapGestureNameToRecordedCount.containsKey(curGestureRecording.name)) { _mapGestureNameToRecordedCount.put(curGestureRecording.name, 1); - }else{ + } else { int curRecordingCntForGesture = (int)_mapGestureNameToRecordedCount.get(curGestureRecording.name); int newRecordingCntForGesture = curRecordingCntForGesture + 1; _mapGestureNameToRecordedCount.put(curGestureRecording.name, newRecordingCntForGesture); - - if(newRecordingCntForGesture >= NUM_SAMPLES_TO_RECORD_PER_GESTURE){ - _curGestureIndex++; + + if (newRecordingCntForGesture >= NUM_SAMPLES_TO_RECORD_PER_GESTURE) { + _curGestureIndex++; } } - } else { - if(_curGestureIndex < GESTURES.length){ + if (_curGestureIndex < GESTURES.length) { // if there are still gestures left to record, start countdown timer _timestampStartCountdownMs = System.currentTimeMillis(); } @@ -382,72 +404,72 @@ void toggleGestureRecording(){ /** * Convenience method that returns the number of gestures recoreded with the given name */ -int getNumGesturesRecordedWithName(String name){ +int getNumGesturesRecordedWithName(String name) { return _mapGestureNameToRecordedCount.containsKey(name) ? (int)_mapGestureNameToRecordedCount.get(name) : 0; } -void drawDebugInfo(){ - if(_firstSerialValRcvdTimestamp != -1){ +void drawDebugInfo() { + if (_firstSerialValRcvdTimestamp != -1) { noStroke(); fill(255); textSize(11); - + float strHeight = textAscent() + textDescent(); - + String strSavingTo = "Saving full stream to: " + _fullDataStreamFilenameWithPath; float strWidth = textWidth(strSavingTo) + 10; float yTextLoc = strHeight; text(strSavingTo, width - strWidth, yTextLoc); - + String strDisplayAmt = "Displaying " + nf((DISPLAY_TIMEWINDOW_MS / 1000.0), 2, 1) + " secs"; strDisplayAmt += " (" + _displaySensorData.size() + " values)"; strWidth = textWidth(strDisplayAmt) + 10; yTextLoc += strHeight; text(strDisplayAmt, width - strWidth, yTextLoc); - + long timeElapsedMs = System.currentTimeMillis() - _firstSerialValRcvdTimestamp; float samplingRate = _serialLinesRcvd / (timeElapsedMs / 1000.0); - - + + String strSamplingRate = nf(samplingRate, 3, 1) + " Hz"; strWidth = textWidth(strSamplingRate) + 10; - + yTextLoc += strHeight; text(strSamplingRate, width - strWidth, yTextLoc); - + String strFrameRate = nf(frameRate, 3, 1) + " fps"; yTextLoc += strHeight; text(strFrameRate, width - strWidth, yTextLoc); } } -void drawYAxis(){ +void drawYAxis() { final int numYTickMarks = 5; final int tickMarkWidth = 6; - + textSize(10); float strHeight = textAscent() + textDescent(); float yRange = getYRange(); float yTickStep = yRange / numYTickMarks; - for(int yTickMark = 0; yTickMark < numYTickMarks; yTickMark++){ + for (int yTickMark = 0; yTickMark < numYTickMarks; yTickMark++) { float yVal = map(yTickMark, 0, numYTickMarks, _minSensorVal + yRange * 0.10, _maxSensorVal - yRange * 0.10); float yCurPixelVal = getYPixelFromSensorVal(yVal); noFill(); stroke(GRID_COLOR); line(0, yCurPixelVal, tickMarkWidth, yCurPixelVal); - + fill(GRID_COLOR); noStroke(); text(nfs(yVal, 3, 1), tickMarkWidth + 2, yCurPixelVal + (strHeight / 2.0) * 0.7); } - + color zeroColor = color(255, 255, 255, 50); stroke(zeroColor); float yVal = 0; float yCurPixelVal = getYPixelFromSensorVal(yVal); line(0, yCurPixelVal, width, yCurPixelVal); - + noStroke(); fill(zeroColor); String strZero = "0"; @@ -458,28 +480,35 @@ void drawYAxis(){ /** * Get full yrange */ -float getYRange(){ - return _maxSensorVal - _minSensorVal; +float getYRange() { + return _maxSensorVal - _minSensorVal; } /** * Prints information about the serial port and returns a list of all available serial ports */ -String[] getAndPrintSerialPortInfo(){ +String[] getAndPrintSerialPortInfo() { println("** All Available Serial Ports **"); String[] listOfSerialPorts = Serial.list(); printArray(listOfSerialPorts); println("** END SERIAL PORT LIST**"); - println("Make sure to change ARDUINO_SERIAL_PORT_INDEX to the correct port number!"); - - if(listOfSerialPorts.length > 0){ + + if (listOfSerialPorts.length > 0) { String firstPortName = listOfSerialPorts[0]; println("For example, if your Arduino is on port " + firstPortName + - " then you would set ARDUINO_SERIAL_PORT_INDEX = " + 0); + " then you would set ARDUINO_SERIAL_PORT_NAME = " + firstPortName); } return listOfSerialPorts; } +int getIndexOfArduinoSerialPort() { + String[] listOfSerialPorts = Serial.list(); + for (int i=0; i< listOfSerialPorts.length; i++) { + if (listOfSerialPorts[i].equals(ARDUINO_SERIAL_PORT_NAME)) return i; + } + return -1; +} + /** * Converts a sensor value to a y-pixel value and returns the y-pixel value */ @@ -518,12 +547,12 @@ void drawSensorLine(color col, long timestamp1, int sensorVal1, long timestamp2, * Draws the graph legend, which is dynamic based on the current sensor values */ void drawLegend(Rectangle legendRect) { - if(_displaySensorData.size() <= 0){ + if (_displaySensorData.size() <= 0) { return; } - + color textColor = color(255, 255, 255, 128); - + // draw outline of legend box stroke(textColor); strokeWeight(1); @@ -542,27 +571,27 @@ void drawLegend(Rectangle legendRect) { float yLegendItemPos = legendRect.y + strHeight - textDescent(); AccelSensorData accelSensorData = _displaySensorData.get(_displaySensorData.size() - 1); int [] accelSensorVals = accelSensorData.getSensorValues(); - + float titleWidth = textWidth("X"); float maxValStrWidth = textWidth(Integer.toString(_maxSensorVal)); float minValStrWidth = textWidth(Integer.toString(_minSensorVal)); - + float largestValStrWidth = max(minValStrWidth, maxValStrWidth); - - if(_minSensorVal < 0){ + + if (_minSensorVal < 0) { // if we have values less than zero, then we split the legend in half // and draw the < 0 values to the left of the titles and the > 0 // to the right of the values - + float xMidLegend = legendRect.x + legendRect.width / 2.0; float xTitleStart = xMidLegend - titleWidth / 2.0; float maxBarSize = legendRect.width / 2.0 - (2 * xBuffer + titleWidth + 3 * xBuffer + largestValStrWidth); - + for (int i = 0; i < legendStrs.length; i++) { String legendStr = legendStrs[i]; fill(textColor); text(legendStr, xTitleStart, yLegendItemPos); - + // draw the bar fill(SENSOR_VALUE_COLORS[i]); noStroke(); @@ -570,30 +599,30 @@ void drawLegend(Rectangle legendRect) { float xBar = xTitleStart - xBuffer - barWidth; String strSensorVal = Integer.toString(accelSensorVals[i]); float xSensorTextLoc = xBar - largestValStrWidth; - if(accelSensorVals[i] > 0){ + if (accelSensorVals[i] > 0) { barWidth = map(accelSensorVals[i], 0, _maxSensorVal, 0, maxBarSize); xBar = xMidLegend + titleWidth / 2.0 + xBuffer; xSensorTextLoc = xBar + barWidth + xBuffer; } rect(xBar, yLegendItemPos - strHeight + textDescent() + yBuffer, barWidth, legendItemHeight - yBuffer); - + // draw the sensor val text(strSensorVal, xSensorTextLoc, yLegendItemPos); yLegendItemPos += legendItemHeight + yBuffer; - } - }else{ + } + } else { // no values < 0, so draw legend normally - + float xLegendItemPos = legendRect.x + xBuffer; float xBar = xLegendItemPos + titleWidth + xBuffer; float maxBarSize = legendRect.width - (xBuffer + titleWidth + 3 * xBuffer + maxValStrWidth); - + // Draw each legend item for (int i = 0; i < legendStrs.length; i++) { String legendStr = legendStrs[i]; fill(textColor); text(legendStr, xLegendItemPos, yLegendItemPos); - + // draw dynamic legend values float barWidth = map(accelSensorVals[i], _minSensorVal, _maxSensorVal, 0, maxBarSize); fill(SENSOR_VALUE_COLORS[i]); @@ -610,51 +639,53 @@ void drawLegend(Rectangle legendRect) { * Draws an on-screen annotation for recently recorded annotations */ void drawGestureRecordingAnnotations() { - - while(_gestureRecordings.size() > 0 && - _gestureRecordings.get(0).hasGestureCompleted() && - _gestureRecordings.get(0).endTimestamp < _currentXMin){ + + while (_gestureRecordings.size() > 0 && + _gestureRecordings.get(0).hasGestureCompleted() && + _gestureRecordings.get(0).endTimestamp < _currentXMin) { _gestureRecordings.remove(0); } - - if(_gestureRecordings.size() <= 0) { return; } - - for(GestureRecording gestureRecording : _gestureRecordings){ + + if (_gestureRecordings.size() <= 0) { + return; + } + + for (GestureRecording gestureRecording : _gestureRecordings) { textSize(10); fill(255); stroke(255); strokeWeight(1); - + String strGesture = "Gesture " + (gestureRecording.hasGestureCompleted() ? "Completed:" : "Active:") - + "\n" + gestureRecording.name; + + "\n" + gestureRecording.name; float xPixelStartGesture = getXPixelFromTimestamp(gestureRecording.startTimestamp); line(xPixelStartGesture, 0, xPixelStartGesture, height); text(strGesture, xPixelStartGesture + 2, 20); - - if(gestureRecording.hasGestureCompleted()){ + + if (gestureRecording.hasGestureCompleted()) { String strEndGesture = "Gesture End: \n" + gestureRecording.name; float xPixelEndGesture = getXPixelFromTimestamp(gestureRecording.endTimestamp); - + noStroke(); fill(255, 255, 255, 30); rect(xPixelStartGesture, 0, xPixelEndGesture - xPixelStartGesture, height); - + stroke(255); line(xPixelEndGesture, 0, xPixelEndGesture, height); - + textSize(10); fill(255); - + // null check on savedfilename // this is because a gesture might be completed but the save to file might not be done // see: https://github.com/jonfroehlich/CSE599Sp2019/issues/1 - if(gestureRecording.savedFilename != null){ - text(gestureRecording.savedFilename, xPixelStartGesture + 2, 50); + if (gestureRecording.savedFilename != null) { + text(gestureRecording.savedFilename, xPixelStartGesture + 2, 50); } } - } + } } - //<>// + /** * Called automatically when there is data on the serial port * See: https://processing.org/reference/libraries/serial/serialEvent_.html @@ -664,9 +695,6 @@ void drawGestureRecordingAnnotations() { * Note: this method is called by a different thread (EventThread) than the draw() method (Animation Thread) */ void serialEvent (Serial myPort) { - long currentTimestampMs = System.currentTimeMillis(); - _currentXMin = currentTimestampMs - DISPLAY_TIMEWINDOW_MS; - //println(Thread.currentThread()); String inString = ""; @@ -676,13 +704,43 @@ void serialEvent (Serial myPort) { inString = trim(_serialPort.readStringUntil('\n')); // println(inString); } - catch(Exception e){ + catch(Exception e) { println("Failed to read serial port. Exception below: "); println(e); return; } - - try{ + + processInputFromClient(inString); +} + +void processServer() { + if (myServer == null) return; + Client thisClient = myServer.available(); + // If the client is not null, and says something, display what it said + if (thisClient !=null) { + String whatClientSaid = thisClient.readString(); + if (whatClientSaid != null) { + processInputFromClient(whatClientSaid); + println(thisClient.ip() + "t" + whatClientSaid); + } + } + delay(10); +} + +// ServerEvent message is generated when a new client connects +// to an existing server. +void serverEvent(Server someServer, Client someClient) { + println("We have a new client: " + someClient.ip()); +} + +/** + * This processes data from a client (serial or wifi) + */ +void processInputFromClient(String inString) { + long currentTimestampMs = System.currentTimeMillis(); + _currentXMin = currentTimestampMs - DISPLAY_TIMEWINDOW_MS; + + try { if (inString != null) { int [] data; @@ -690,36 +748,36 @@ void serialEvent (Serial myPort) { if (inString.contains(",")) { String [] strData = split(inString, ','); data = new int[strData.length]; - for(int i=0; i= 4){ + + if (data.length >= 4) { int gestureRecordButtonPressed = data[4]; - if(gestureRecordButtonPressed == 1){ - toggleGestureRecording(); + if (gestureRecordButtonPressed == 1) { + toggleGestureRecording(); } } - + // force the redraw //redraw(); } @@ -733,15 +791,15 @@ void serialEvent (Serial myPort) { /** * Checks for new global min and max data in our sensor values */ -void checkAndSetNewMinMaxSensorValues(AccelSensorData accelSensorData){ +void checkAndSetNewMinMaxSensorValues(AccelSensorData accelSensorData) { int min = min(accelSensorData.x, accelSensorData.y, accelSensorData.z); int max = max(accelSensorData.x, accelSensorData.y, accelSensorData.z); - if(min < _minSensorVal){ - _minSensorVal = min; + if (min < _minSensorVal) { + _minSensorVal = min; } - - if(max > _maxSensorVal){ - _maxSensorVal = max; + + if (max > _maxSensorVal) { + _maxSensorVal = max; } } @@ -750,27 +808,32 @@ void checkAndSetNewMinMaxSensorValues(AccelSensorData accelSensorData){ */ void exit() { println("Flushing PrintWriter, exiting..."); - - if(_serialPort != null){ + + if (_serialPort != null) { _serialPort.clear(); _serialPort.stop(); } - - if(_printWriterAllData != null){ + + if (_printWriterAllData != null) { // We need to synchronize _printWriterAllData because the serial event // where we use _printWriterAllData occurs in a different thread - synchronized(_printWriterAllData){ + synchronized(_printWriterAllData) { _printWriterAllData.flush(); _printWriterAllData.close(); } } + + if (myServer != null) { + myServer.stop(); + } + super.exit(); } // Class for the accelerometer data class AccelSensorData { public final static String CSV_HEADER = "Processing Timestamp (ms), Arduino Timestamp (ms), X, Y, Z"; - + public int x; public int y; public int z; @@ -784,17 +847,17 @@ class AccelSensorData { this.y = y; this.z = z; } - + // Creates a dynamic array on every call - public int[] getSensorValues(){ + public int[] getSensorValues() { return new int[] { this.x, this.y, this.z }; } - - public String toCsvHeaderString(){ + + public String toCsvHeaderString() { return CSV_HEADER; } - - public String toCsvString(){ + + public String toCsvString() { return String.format("%d, %d, %d, %d, %d", this.timestamp, this.arduinoTimestamp, this.x, this.y, this.z); } @@ -803,41 +866,41 @@ class AccelSensorData { } } -class GestureRecording{ +class GestureRecording { public long startTimestamp; public long endTimestamp = -1; public String name; public String savedAbsolutePath; public String savedFilename; public String gestureDir; - + ArrayList listSensorData = new ArrayList(); - - public GestureRecording(String gestureDir, String gestureName, long startTimestamp){ + + public GestureRecording(String gestureDir, String gestureName, long startTimestamp) { this.name = gestureName; this.startTimestamp = startTimestamp; this.gestureDir = gestureDir; } - - public boolean hasGestureCompleted(){ + + public boolean hasGestureCompleted() { return this.endTimestamp != -1; } - - public void save(){ + + public void save() { long currentTimestampMs = System.currentTimeMillis(); String filenameNoPath = this.name + "_" + currentTimestampMs + "_" + this.listSensorData.size() + ".csv"; File fDir = new File(sketchPath(this.gestureDir)); - if(!fDir.exists()){ - fDir.mkdirs(); + if (!fDir.exists()) { + fDir.mkdirs(); } File file = new File(fDir, filenameNoPath); - + println("Attempting to save '" + this.name + "' to " + file.getAbsolutePath()); - + try { PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(file, false))); printWriter.println(AccelSensorData.CSV_HEADER); - for(AccelSensorData accelSensorData : listSensorData){ + for (AccelSensorData accelSensorData : listSensorData) { printWriter.println(accelSensorData.toCsvString()); } printWriter.flush(); @@ -845,7 +908,8 @@ class GestureRecording{ println("Wrote " + listSensorData.size() + " lines to " + file.getAbsolutePath()); this.savedAbsolutePath = file.getAbsolutePath(); this.savedFilename = file.getName(); - }catch (IOException e){ + } + catch (IOException e) { e.printStackTrace(); } } From a3d24662a5e76585793bb4e7d6130b523942f409 Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sat, 16 May 2020 12:58:42 -0700 Subject: [PATCH 2/9] removed common.h and added readme --- .../LIS3DHGestureRecorder/DialogBox.PNG | Bin 0 -> 15659 bytes .../LIS3DHGestureRecorder.ino | 27 +++++++++++++++- .../Arduino/LIS3DHGestureRecorder/common.h | 29 ------------------ .../Arduino/LIS3DHGestureRecorder/readme.md | 27 ++++++++++++++++ 4 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/DialogBox.PNG delete mode 100644 Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h create mode 100644 Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/readme.md diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/DialogBox.PNG b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/DialogBox.PNG new file mode 100644 index 0000000000000000000000000000000000000000..98cde356c2d0fe92a73f970676d1c061226446eb GIT binary patch literal 15659 zcmcJ0dpy(a|G(~}kgQbXG#%ZYNaYw?;!Y)2sVIjfogC&6o8z`3nS@HH9G2u1895tP zjNK9n8D^F_n{CZu!)*J#b$8$2&;7l>-{1G}`2GIyc-!^9uIv50Ugzt2y{_mpwpI#q zs&Z0NQVJ(eSe}!TTEUc(`sK+Q8K7m|_8tlFSmA%p>X=kvoB9OsL;9wnh;4tnZ0S{!&sK0+#<)4BP+*NlBT$KWS-xKFEblZ;gL_GF^LiBlEXD+S2Nm8@}eA zP%SPq`}Nq~8y7RZE@oa>cdU2yJ4>rg8@BrO9@0M57oP5xy?KZ2&Pj)J`Nl^dQ+Ks* z+|U0-bwlZ7!>zIUgO{&>4$;`A{F=&?UbprbB6R)edfvhb==EwS;YPd}KbErn;B+qq zjIFUdmG^csGahp8l*U;EXr+_@23mRaw{R7yJsZeUXU?jT+wqbjtgKYOw)tAAO|n;| za!)LGNRj5jmqxq=isGpXqGS}-A;*opE_JlG*L;a28e(uDi|yDFp(l0;7T7L!xja}~ zw69>L)Wft*WXTY;k1ft3;qP->e1JYH)2=Ziu^MP7lzLTuH!TmBuo6wZ}Mj!FfQEm-^AckPNJ%1xf# zmxcgPDU1NHbriTsE<*^$P;1wjFEPXf5?vI7mEbwzFOoSLya)=*&!d$c&+?GXYxZF^fqR~^yo(EF8!%B7BxzP`6XimT1NKRvt`4|h3;-+5&x?+zCp|%8WKgb=d4XZ6;KgrXIi!elsyaQ8KUr=+Iuqt3< zQrcLPMHsbdp&;c!T$*=+j@qZUb^`(sS(M;S^wPOyAxw%8KI7Yz8MCR#vFB6yvi!h> zIr+QLeRzcS`;i5R+`v57(Rdx}^bOP`CriErNUm+J z4LlFf-97Tf+Bc|_b9XE$mrHDg2Ni4f?TFxqQ8F$bF1^|F;d}L&1h%{!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~+0+;V0Wj%f4 z0C}-&KT3=v2><{9 literal 0 HcmV?d00001 diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino index 4d42b71..0dda226 100644 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino @@ -10,11 +10,36 @@ #include #include #include -#include "common.h" #include #include #include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino +// Settings +enum RecoderMode { + RECORDER_SERIAL, + RECORDER_BLUETOOTH, + RECORDER_WIFI +}; +// By default we use serial +const RecoderMode CURRENT_MODE = RECORDER_SERIAL; // CHANGE THIS IF YOU WANT A DIFFERENT MODE + +// ------------------------------------------- +// Serial info +const int SERIAL_BAUD_RATE = 115200; + +// ------------------------------------------- +// Bluetooth settings +const char* ARDUINO_BT_NAME = "ESP32 Gesture Recorder"; +// Bluetooth uses the serial baud rate and port index above + +// ------------------------------------------- +// WIFI +// If using wifi, make sure to put your credentials there if you're using WIFI mode +const char* WIFI_SSID = ""; +const char* WIFI_PASS = ""; +const char* WIFI_HOST_IP_ADDRESS = ""; // The IP address of the host you want to connect to +const int WIFI_HOST_PORT = 10002; // The IP address of the host you want to connect to + // Used for LIS3DH hardware & software SPI #define LIS3DH_CS 10 Adafruit_LIS3DH lis = Adafruit_LIS3DH(); diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h deleted file mode 100644 index cce2fb4..0000000 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/common.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _COMMON_H_ -#define _COMMON_H_ - -enum RecoderMode { - RECORDER_SERIAL, - RECORDER_BLUETOOTH, - RECORDER_WIFI -}; -// By default we use serial -const RecoderMode CURRENT_MODE = RECORDER_BLUETOOTH; - -// ------------------------------------------- -// Serial info -const int SERIAL_BAUD_RATE = 115200; - -// ------------------------------------------- -// Bluetooth settings -const char* ARDUINO_BT_NAME = "ESP32 Gesture Recorder"; -// Bluetooth uses the serial baud rate and port index above - -// ------------------------------------------- -// WIFI -// If using wifi, make sure to put your credentials there if you're using WIFI mode -const char* WIFI_SSID = ""; -const char* WIFI_PASS = ""; -const char* WIFI_HOST_IP_ADDRESS = ""; // The IP address of the host you want to connect to -const int WIFI_HOST_PORT = 10002; // The IP address of the host you want to connect to - -#endif diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/readme.md b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/readme.md new file mode 100644 index 0000000..16acf03 --- /dev/null +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/readme.md @@ -0,0 +1,27 @@ +# SERIAL MODE + +# BLUETOOTH MODE +Starting the device in this mode will create a new bluetooth device named by default ESP32 Gesture Recorder. +You can change it if you really like. +On windows, the easiest way to add this is as follows: +1. go to bluetooth settings. +2. On the right side it says "More Bluetooth Options". +3. A new dialog box will open and it will say "Com Ports" in one of the tabs at the top. +4. Go to that tab (see image below): + +![dialog box](DialogBox.PNG "The COM Ports Dialog box") + +5. Click Add +6. A new dialog will pop up, giving you different options (it may take a moment to come up) +7. Select outgoing since your PC will be initializing the connection +8. Select the bluetooth device in the dropdown for "Device that will use the com port". +It will be ESP32 Gesture Recorder unless you changed it +9. Hit okay +10. Take note of the name of the COM port that was created. + +# WIFI MODE +Start the processing server with WIFI turned on. +It will spit out a "Started the server at 192.168.x.x" +Put that address in the arduino sketch and upload it to your ESP32. +Make sure to open up the port you've selected in your firewall for the computer running processing. +I had trouble with this even when I added explicit rules. \ No newline at end of file From 3d6446a1d81459c9470943213005305dc1d47ef9 Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sat, 16 May 2020 12:59:22 -0700 Subject: [PATCH 3/9] hit autoformat --- Processing/GestureRecorder/GestureRecorder.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Processing/GestureRecorder/GestureRecorder.pde b/Processing/GestureRecorder/GestureRecorder.pde index 0ee1bae..dc2673d 100644 --- a/Processing/GestureRecorder/GestureRecorder.pde +++ b/Processing/GestureRecorder/GestureRecorder.pde @@ -722,7 +722,7 @@ void processServer() { if (whatClientSaid != null) { processInputFromClient(whatClientSaid); println(thisClient.ip() + "t" + whatClientSaid); - } + } } delay(10); } From 1732d6c569eaf10d396701294369bc4ab7b93296 Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sat, 16 May 2020 13:21:47 -0700 Subject: [PATCH 4/9] tried to fix more formatting --- .../Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino index 0dda226..da8e20c 100644 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino @@ -7,6 +7,7 @@ http://makeabilitylab.io */ + #include #include #include @@ -53,7 +54,6 @@ BluetoothSerial ESP_BT; //Object for Bluetooth // Use WiFiClient class to create TCP connections WiFiClient ESP_WIFI; - void setup() { Serial.begin(SERIAL_BAUD_RATE); From 7f95d7aecdd9156f939639202fc955af4929741a Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sat, 16 May 2020 13:24:19 -0700 Subject: [PATCH 5/9] one more tweak --- .../GestureRecorder/GestureRecorder.pde | 97 +++++++++---------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/Processing/GestureRecorder/GestureRecorder.pde b/Processing/GestureRecorder/GestureRecorder.pde index dc2673d..40c7a0b 100644 --- a/Processing/GestureRecorder/GestureRecorder.pde +++ b/Processing/GestureRecorder/GestureRecorder.pde @@ -47,7 +47,7 @@ final int DISPLAY_TIMEWINDOW_MS = 1000 * 20; // 20 secs. You can change this to // Make sure to change this! If you're not sure what port your Arduino is using // Run this Processing sketch and look in the console, then change the number accordingly -final String ARDUINO_SERIAL_PORT_NAME = "COM5"; // CHANGE THIS TO APPROPRIATE PORT! +final String ARDUINO_SERIAL_PORT_NAME = "COM3"; // CHANGE THIS TO APPROPRIATE PORT! // WIFI SETTINGS // This should be false even in bluetooth mode since that just emulates a com port final boolean ARDUINO_WIFI_MODE = false; // CHANGE THIS TO TRUE IF AND ONLY IF YOU ARE USING WIFI MODE @@ -74,7 +74,6 @@ Serial _serialPort; // Wifi server Server myServer; - long _currentXMin; // the far left x-axis value on the graph Rectangle _legendRect; // location and drawing area of the legend boolean _dynamicYAxis = true; @@ -90,8 +89,8 @@ final int NUM_SAMPLES_TO_RECORD_PER_GESTURE = 5; // Feel free to rename "Custom" to something that is more semantically meaningful describing your custom gesture // For example, I did "Bunny Hops" final String [] GESTURES = { "Backhand Tennis", "Forehand Tennis", "Underhand Bowling", - "Baseball Throw", "Midair Clockwise 'O'", "At Rest", "Midair Counter-clockwise 'O'", - "Midair Zorro 'Z'", "Midair 'S'", "Shake", "Custom" }; + "Baseball Throw", "Midair Clockwise 'O'", "At Rest", "Midair Counter-clockwise 'O'", + "Midair Zorro 'Z'", "Midair 'S'", "Shake", "Custom" }; int _curGestureIndex = 0; HashMap _mapGestureNameToRecordedCount = new HashMap(); // tracks recorded gesture counts ArrayList _gestureRecordings = new ArrayList(); // sensor data to dump to file @@ -107,14 +106,14 @@ void setup() { String filenameNoPath = FULL_DATASTREAM_RECORDING_FILENAME; - if (_createNewFullDatastreamFileOnEveryExecution) { + if(_createNewFullDatastreamFileOnEveryExecution){ String filenameWithoutExt = filenameNoPath.substring(0, filenameNoPath.length()-4); String filenameExt = filenameNoPath.substring(filenameNoPath.length()-4, filenameNoPath.length()); filenameNoPath = filenameWithoutExt + System.currentTimeMillis() + filenameExt; } File fDir = new File(sketchPath(GESTURE_DIR_NAME)); - if (!fDir.exists()) { + if(!fDir.exists()){ fDir.mkdirs(); } File file = new File(fDir, filenameNoPath); @@ -214,26 +213,26 @@ void draw() { // Check for new sensor data ArrayList newData = null; - synchronized(_sensorBuffer) { + synchronized(_sensorBuffer){ newData = new ArrayList(_sensorBuffer); _sensorBuffer.clear(); } // Dump new data into _displaySensorData and curGestureRecording - for (int i = 0; i < newData.size(); i++) { + for(int i = 0; i < newData.size(); i++){ AccelSensorData accelSensorData = newData.get(i); checkAndSetNewMinMaxSensorValues(accelSensorData); _displaySensorData.add(accelSensorData); - if (_recordingGesture) { + if(_recordingGesture){ GestureRecording curGestureRecording = _gestureRecordings.get(_gestureRecordings.size() - 1); curGestureRecording.listSensorData.add(accelSensorData); } } // Remove data that is no longer relevant to be displayed - while (_displaySensorData.size() > 0 && - _displaySensorData.get(0).timestamp < _currentXMin) { + while(_displaySensorData.size() > 0 && + _displaySensorData.get(0).timestamp < _currentXMin){ _displaySensorData.remove(0); } @@ -269,7 +268,7 @@ void draw() { /** * Writes out recording status to the screen */ -void drawRecordingStatus() { +void drawRecordingStatus(){ textSize(10); float strHeight = textAscent() + textDescent(); float yText = height - (strHeight * GESTURES.length) - 3; @@ -280,9 +279,9 @@ void drawRecordingStatus() { String str = GESTURES[i] + " (" + sampleNum + "/" + NUM_SAMPLES_TO_RECORD_PER_GESTURE + ")"; float strWidth = textWidth(str) + 10; - if (_curGestureIndex == i) { + if(_curGestureIndex == i){ fill(0, 240, 0, 230); - } else { + }else{ fill(255, 255, 255, 200); } @@ -295,16 +294,14 @@ void drawRecordingStatus() { * Writes out basic instructions for the user */ void drawInstructions(int countdownTimeSecs) { - - String strInstructions = ""; textSize(30); noStroke(); fill(255, 255, 255, 200); - if (_displaySensorData.size() <= 0) { + if (_displaySensorData.size() <= 0){ textSize(50); strInstructions = "Waiting for Serial data..."; - } else if (_timestampStartCountdownMs != -1) { + }else if (_timestampStartCountdownMs != -1){ // if we're here, the user hit the spacebar and we're either ready to record or recording // draw center of screen String str = ""; @@ -338,17 +335,17 @@ void drawInstructions(int countdownTimeSecs) { strWidth = textWidth(str); text(str, width / 2.0 - strWidth / 2.0, height / 2.0 + strHeight / 2.0 - textDescent()); } - } else if (_curGestureIndex < GESTURES.length) { + }else if (_curGestureIndex < GESTURES.length){ textSize(30); fill(255, 255, 255); int sampleNum = getNumGesturesRecordedWithName(GESTURES[_curGestureIndex]) + 1; strInstructions = "Hit SPACEBAR or BUTTON to record sample " + sampleNum + "/" + NUM_SAMPLES_TO_RECORD_PER_GESTURE - + " of gesture:\n'" + GESTURES[_curGestureIndex] + "'"; - } else { + + " of gesture:\n'" + GESTURES[_curGestureIndex] + "'"; + }else{ strInstructions = "You did it! Gesture recording completed!"; } - if (strInstructions.length() > 0) { + if(strInstructions.length() > 0){ float strWidth = textWidth(strInstructions); float strHeight = textAscent() + textDescent(); @@ -365,11 +362,11 @@ void keyPressed() { } } -void toggleGestureRecording() { +void toggleGestureRecording(){ long currentTimestampMs = System.currentTimeMillis(); long elapsedTime = currentTimestampMs - _timestampSinceLastGestureRecordToggle; - if (elapsedTime > MIN_TIME_BETWEEN_GESTURE_TOGGLE_MS) { + if(elapsedTime > MIN_TIME_BETWEEN_GESTURE_TOGGLE_MS){ _timestampSinceLastGestureRecordToggle = currentTimestampMs; if (_recordingGesture) { // if the spacebar was pressed and we're currently recording a gesture @@ -381,19 +378,19 @@ void toggleGestureRecording() { curGestureRecording.endTimestamp = currentTimestampMs; curGestureRecording.save(); - if (!_mapGestureNameToRecordedCount.containsKey(curGestureRecording.name)) { + if(!_mapGestureNameToRecordedCount.containsKey(curGestureRecording.name)){ _mapGestureNameToRecordedCount.put(curGestureRecording.name, 1); } else { int curRecordingCntForGesture = (int)_mapGestureNameToRecordedCount.get(curGestureRecording.name); int newRecordingCntForGesture = curRecordingCntForGesture + 1; _mapGestureNameToRecordedCount.put(curGestureRecording.name, newRecordingCntForGesture); - if (newRecordingCntForGesture >= NUM_SAMPLES_TO_RECORD_PER_GESTURE) { + if(newRecordingCntForGesture >= NUM_SAMPLES_TO_RECORD_PER_GESTURE){ _curGestureIndex++; } } } else { - if (_curGestureIndex < GESTURES.length) { + if(_curGestureIndex < GESTURES.length){ // if there are still gestures left to record, start countdown timer _timestampStartCountdownMs = System.currentTimeMillis(); } @@ -404,13 +401,13 @@ void toggleGestureRecording() { /** * Convenience method that returns the number of gestures recoreded with the given name */ -int getNumGesturesRecordedWithName(String name) { +int getNumGesturesRecordedWithName(String name){ return _mapGestureNameToRecordedCount.containsKey(name) ? (int)_mapGestureNameToRecordedCount.get(name) : 0; } -void drawDebugInfo() { - if (_firstSerialValRcvdTimestamp != -1) { +void drawDebugInfo(){ + if(_firstSerialValRcvdTimestamp != -1){ noStroke(); fill(255); textSize(11); @@ -444,7 +441,7 @@ void drawDebugInfo() { } } -void drawYAxis() { +void drawYAxis(){ final int numYTickMarks = 5; final int tickMarkWidth = 6; @@ -452,7 +449,7 @@ void drawYAxis() { float strHeight = textAscent() + textDescent(); float yRange = getYRange(); float yTickStep = yRange / numYTickMarks; - for (int yTickMark = 0; yTickMark < numYTickMarks; yTickMark++) { + for(int yTickMark = 0; yTickMark < numYTickMarks; yTickMark++){ float yVal = map(yTickMark, 0, numYTickMarks, _minSensorVal + yRange * 0.10, _maxSensorVal - yRange * 0.10); float yCurPixelVal = getYPixelFromSensorVal(yVal); noFill(); @@ -480,20 +477,20 @@ void drawYAxis() { /** * Get full yrange */ -float getYRange() { +float getYRange(){ return _maxSensorVal - _minSensorVal; } /** * Prints information about the serial port and returns a list of all available serial ports */ -String[] getAndPrintSerialPortInfo() { +String[] getAndPrintSerialPortInfo(){ println("** All Available Serial Ports **"); String[] listOfSerialPorts = Serial.list(); printArray(listOfSerialPorts); println("** END SERIAL PORT LIST**"); - if (listOfSerialPorts.length > 0) { + if(listOfSerialPorts.length > 0){ String firstPortName = listOfSerialPorts[0]; println("For example, if your Arduino is on port " + firstPortName + " then you would set ARDUINO_SERIAL_PORT_NAME = " + firstPortName); @@ -547,7 +544,7 @@ void drawSensorLine(color col, long timestamp1, int sensorVal1, long timestamp2, * Draws the graph legend, which is dynamic based on the current sensor values */ void drawLegend(Rectangle legendRect) { - if (_displaySensorData.size() <= 0) { + if(_displaySensorData.size() <= 0){ return; } @@ -578,7 +575,7 @@ void drawLegend(Rectangle legendRect) { float largestValStrWidth = max(minValStrWidth, maxValStrWidth); - if (_minSensorVal < 0) { + if(_minSensorVal < 0){ // if we have values less than zero, then we split the legend in half // and draw the < 0 values to the left of the titles and the > 0 // to the right of the values @@ -599,7 +596,7 @@ void drawLegend(Rectangle legendRect) { float xBar = xTitleStart - xBuffer - barWidth; String strSensorVal = Integer.toString(accelSensorVals[i]); float xSensorTextLoc = xBar - largestValStrWidth; - if (accelSensorVals[i] > 0) { + if(accelSensorVals[i] > 0){ barWidth = map(accelSensorVals[i], 0, _maxSensorVal, 0, maxBarSize); xBar = xMidLegend + titleWidth / 2.0 + xBuffer; xSensorTextLoc = xBar + barWidth + xBuffer; @@ -610,7 +607,7 @@ void drawLegend(Rectangle legendRect) { text(strSensorVal, xSensorTextLoc, yLegendItemPos); yLegendItemPos += legendItemHeight + yBuffer; } - } else { + }else{ // no values < 0, so draw legend normally float xLegendItemPos = legendRect.x + xBuffer; @@ -640,24 +637,22 @@ void drawLegend(Rectangle legendRect) { */ void drawGestureRecordingAnnotations() { - while (_gestureRecordings.size() > 0 && - _gestureRecordings.get(0).hasGestureCompleted() && - _gestureRecordings.get(0).endTimestamp < _currentXMin) { + while(_gestureRecordings.size() > 0 && + _gestureRecordings.get(0).hasGestureCompleted() && + _gestureRecordings.get(0).endTimestamp < _currentXMin){ _gestureRecordings.remove(0); } - if (_gestureRecordings.size() <= 0) { - return; - } + if(_gestureRecordings.size() <= 0){ return; } - for (GestureRecording gestureRecording : _gestureRecordings) { + for(GestureRecording gestureRecording : _gestureRecordings){ textSize(10); fill(255); stroke(255); strokeWeight(1); String strGesture = "Gesture " + (gestureRecording.hasGestureCompleted() ? "Completed:" : "Active:") - + "\n" + gestureRecording.name; + + "\n" + gestureRecording.name; float xPixelStartGesture = getXPixelFromTimestamp(gestureRecording.startTimestamp); line(xPixelStartGesture, 0, xPixelStartGesture, height); text(strGesture, xPixelStartGesture + 2, 20); @@ -679,13 +674,13 @@ void drawGestureRecordingAnnotations() { // null check on savedfilename // this is because a gesture might be completed but the save to file might not be done // see: https://github.com/jonfroehlich/CSE599Sp2019/issues/1 - if (gestureRecording.savedFilename != null) { + if(gestureRecording.savedFilename != null){ text(gestureRecording.savedFilename, xPixelStartGesture + 2, 50); } } } } - + //<>// /** * Called automatically when there is data on the serial port * See: https://processing.org/reference/libraries/serial/serialEvent_.html @@ -748,7 +743,7 @@ void processInputFromClient(String inString) { if (inString.contains(",")) { String [] strData = split(inString, ','); data = new int[strData.length]; - for (int i=0; i Date: Sun, 17 May 2020 06:50:43 -0700 Subject: [PATCH 6/9] updated comments, variable names, some coding style --- .../LIS3DHGestureRecorder.ino | 4 +- .../GestureRecorder/GestureRecorder.pde | 45 ++++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino index da8e20c..0cf0a3b 100644 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino @@ -16,13 +16,13 @@ #include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino // Settings -enum RecoderMode { +enum CommunicationMode { RECORDER_SERIAL, RECORDER_BLUETOOTH, RECORDER_WIFI }; // By default we use serial -const RecoderMode CURRENT_MODE = RECORDER_SERIAL; // CHANGE THIS IF YOU WANT A DIFFERENT MODE +const CommunicationMode CURRENT_MODE = RECORDER_SERIAL; // CHANGE THIS IF YOU WANT A DIFFERENT MODE // ------------------------------------------- // Serial info diff --git a/Processing/GestureRecorder/GestureRecorder.pde b/Processing/GestureRecorder/GestureRecorder.pde index 40c7a0b..2a9f07c 100644 --- a/Processing/GestureRecorder/GestureRecorder.pde +++ b/Processing/GestureRecorder/GestureRecorder.pde @@ -22,6 +22,7 @@ * Future ideas: * - Shows capture snapshot? * - GUI to select which gesture to record + * - Print out which mode we are using for comm (BLUETOOTH, Serial, WiFi) * */ @@ -48,6 +49,7 @@ final int DISPLAY_TIMEWINDOW_MS = 1000 * 20; // 20 secs. You can change this to // Run this Processing sketch and look in the console, then change the number accordingly final String ARDUINO_SERIAL_PORT_NAME = "COM3"; // CHANGE THIS TO APPROPRIATE PORT! + // WIFI SETTINGS // This should be false even in bluetooth mode since that just emulates a com port final boolean ARDUINO_WIFI_MODE = false; // CHANGE THIS TO TRUE IF AND ONLY IF YOU ARE USING WIFI MODE @@ -72,7 +74,7 @@ PrintWriter _printWriterAllData; Serial _serialPort; // Wifi server -Server myServer; +Server _wifiServer; long _currentXMin; // the far left x-axis value on the graph Rectangle _legendRect; // location and drawing area of the legend @@ -122,7 +124,7 @@ void setup() { println("Saving accel data to: " + _fullDataStreamFilenameWithPath); try { - // We save all incoming sensor data to a file (by appending`) + // We save all incoming sensor data to a file (by appending) // Appending text to a file: // - https://stackoverflow.com/questions/17010222/how-do-i-append-text-to-a-csv-txt-file-in-processing // - https://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html @@ -134,10 +136,10 @@ void setup() { } if (ARDUINO_WIFI_MODE) { - //https://www.processing.org/reference/libraries/net/Server.html - myServer = new Server(this, ARDUINO_WIFI_PORT); + // https://www.processing.org/reference/libraries/net/Server.html + _wifiServer = new Server(this, ARDUINO_WIFI_PORT); print("Starting server"); - while (!myServer.active()) { + while (!_wifiServer.active()) { print("."); delay(50); } @@ -151,13 +153,15 @@ void setup() { if (serialPorts.length <= 0) { println("You appear to have *ZERO* active serial ports. Make sure your Arduino is plugged in. Exiting..."); exit(); + return; } - int ARDUINO_SERIAL_PORT_INDEX = getIndexOfArduinoSerialPort(); + int ARDUINO_SERIAL_PORT_INDEX = getIndexOfArduinoSerialPort(ARDUINO_SERIAL_PORT_NAME); if (ARDUINO_SERIAL_PORT_INDEX == -1) { println("Could not find the serial port: " + ARDUINO_SERIAL_PORT_NAME + ". Exiting..."); exit(); + return; } // Open the serial port @@ -168,8 +172,7 @@ void setup() { // We need to clear the port (or sometimes there is leftover data) // (Yes, this is strange, but once we implemented this clear, - // we were no longer seeing garbage data in the beginning of our printwriter - // strea,) + // we were no longer seeing garbage data in the beginning of our printwriter stream) _serialPort.clear(); } catch(Exception e) { @@ -399,7 +402,7 @@ void toggleGestureRecording(){ } /** - * Convenience method that returns the number of gestures recoreded with the given name + * Convenience method that returns the number of gestures recorded with the given name */ int getNumGesturesRecordedWithName(String name){ return _mapGestureNameToRecordedCount.containsKey(name) ? (int)_mapGestureNameToRecordedCount.get(name) : 0; @@ -441,6 +444,9 @@ void drawDebugInfo(){ } } +/** + * Draws the y-axis ticks and labels + */ void drawYAxis(){ final int numYTickMarks = 5; final int tickMarkWidth = 6; @@ -498,10 +504,15 @@ String[] getAndPrintSerialPortInfo(){ return listOfSerialPorts; } -int getIndexOfArduinoSerialPort() { +/** + * Convenience method that returns index of serialPortName or -1 if not found + */ +int getIndexOfArduinoSerialPort(String serialPortName) { String[] listOfSerialPorts = Serial.list(); for (int i=0; i< listOfSerialPorts.length; i++) { - if (listOfSerialPorts[i].equals(ARDUINO_SERIAL_PORT_NAME)) return i; + if (listOfSerialPorts[i].equals(serialPortName)){ + return i; + } } return -1; } @@ -709,8 +720,12 @@ void serialEvent (Serial myPort) { } void processServer() { - if (myServer == null) return; - Client thisClient = myServer.available(); + if (_wifiServer == null){ + return; + } + + Client thisClient = _wifiServer.available(); + // If the client is not null, and says something, display what it said if (thisClient !=null) { String whatClientSaid = thisClient.readString(); @@ -818,8 +833,8 @@ void exit() { } } - if (myServer != null) { - myServer.stop(); + if (_wifiServer != null) { + _wifiServer.stop(); } super.exit(); From 30a258e5b22aab279cc0e08b968632ad0966ebe5 Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sun, 17 May 2020 13:12:25 -0700 Subject: [PATCH 7/9] added gitignore so gestures don't get checked in --- Processing/GestureRecorder/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 Processing/GestureRecorder/.gitignore diff --git a/Processing/GestureRecorder/.gitignore b/Processing/GestureRecorder/.gitignore new file mode 100644 index 0000000..bb0754e --- /dev/null +++ b/Processing/GestureRecorder/.gitignore @@ -0,0 +1 @@ +/Gestures \ No newline at end of file From 2998a61bf55efbd69fb13fc63dd52e3f550f5598 Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sun, 17 May 2020 13:35:23 -0700 Subject: [PATCH 8/9] added method to get commProtocol --- .../LIS3DHGestureRecorder.ino | 102 ++++++------------ 1 file changed, 30 insertions(+), 72 deletions(-) diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino index 0cf0a3b..e49c7d6 100644 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino @@ -13,6 +13,7 @@ #include #include #include +#include "Stream.h" #include "BluetoothSerial.h" //Header File for Serial Bluetooth, will be added by default into Arduino // Settings @@ -47,7 +48,7 @@ Adafruit_LIS3DH lis = Adafruit_LIS3DH(); const boolean INCLUDE_TIMESTAMP = true; // print out timestamp to serial const int BUTTON_INPUT_PIN = 21; // hooked up with pull-up configuration -const int DELAY_MS = 10; // the loop delay +const int DELAY_MS = 2; // the loop delay // Common data objects BluetoothSerial ESP_BT; //Object for Bluetooth @@ -93,77 +94,30 @@ void setup() } Serial.print("WiFi connected - IP address: "); Serial.println(WiFi.localIP()); - if (!ESP_WIFI.connect(WIFI_HOST_IP_ADDRESS, WIFI_HOST_PORT)) { + while (!ESP_WIFI.connect(WIFI_HOST_IP_ADDRESS, WIFI_HOST_PORT)) { Serial.print("Failed to connect to "); Serial.print(WIFI_HOST_IP_ADDRESS); Serial.print(":"); Serial.print(WIFI_HOST_PORT); Serial.println(); - while(1) vTaskDelay(5000); + vTaskDelay(5000); // wait 5 seconds } Serial.println("Connected to host"); - ESP_WIFI.println("Hello"); } - pinMode(BUTTON_INPUT_PIN, INPUT_PULLUP); } -void serial_output() -{ - int buttonVal = digitalRead(BUTTON_INPUT_PIN); - - if (INCLUDE_TIMESTAMP) - { - Serial.print(millis()); - Serial.print(", "); - } - - Serial.print(lis.x); - Serial.print(", "); - Serial.print(lis.y); - Serial.print(", "); - Serial.print(lis.z); - Serial.print(", "); - Serial.print(!buttonVal); // because pull-up - Serial.println(); -} - -void bluetooth_output() -{ - int buttonVal = digitalRead(BUTTON_INPUT_PIN); - - if (INCLUDE_TIMESTAMP) - { - ESP_BT.print(millis()); - ESP_BT.print(", "); - } - ESP_BT.print(lis.x); - ESP_BT.print(", "); - ESP_BT.print(lis.y); - ESP_BT.print(", "); - ESP_BT.print(lis.z); - ESP_BT.print(", "); - ESP_BT.print(!buttonVal); // because pull-up - ESP_BT.println(); -} - -void wifi_output() -{ - int buttonVal = digitalRead(BUTTON_INPUT_PIN); - - if (INCLUDE_TIMESTAMP) +// We return a pointer to the object since we can't return an abstract class +Stream* getCommProtocol() { + switch (CURRENT_MODE) { - ESP_WIFI.print(millis()); - ESP_WIFI.print(", "); + case RECORDER_SERIAL: + return &Serial; + case RECORDER_BLUETOOTH: + return &ESP_BT; + case RECORDER_WIFI: + return &ESP_WIFI; } - ESP_WIFI.print(lis.x); - ESP_WIFI.print(", "); - ESP_WIFI.print(lis.y); - ESP_WIFI.print(", "); - ESP_WIFI.print(lis.z); - ESP_WIFI.print(", "); - ESP_WIFI.print(!buttonVal); // because pull-up - ESP_WIFI.println(); } void loop() @@ -172,21 +126,25 @@ void loop() // Read accel data lis.read(); - // Then output our stuff - switch (CURRENT_MODE) + int buttonVal = digitalRead(BUTTON_INPUT_PIN); + + Stream* stream = getCommProtocol(); + + if (INCLUDE_TIMESTAMP) { - case RECORDER_SERIAL: - serial_output(); - break; - case RECORDER_BLUETOOTH: - bluetooth_output(); - break; - case RECORDER_WIFI: - wifi_output(); - break; + stream->print(millis()); + stream->print(", "); } - - if (DELAY_MS > 0) + stream->print(lis.x); + stream.print(", "); + stream.print(lis.y); + stream.print(", "); + stream.print(lis.z); + stream.print(", "); + stream.print(!buttonVal); // because pull-up + stream.println(); + + while (!lis.haveNewData()) { delay(DELAY_MS); } From 76f4c4fc1aeeaab71cb1ebdee7f82f91674e276a Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Sun, 17 May 2020 13:37:50 -0700 Subject: [PATCH 9/9] VSCode +Arduino = :( --- .../LIS3DHGestureRecorder.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino index e49c7d6..53c7049 100644 --- a/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino +++ b/Processing/GestureRecorder/Arduino/LIS3DHGestureRecorder/LIS3DHGestureRecorder.ino @@ -136,13 +136,13 @@ void loop() stream->print(", "); } stream->print(lis.x); - stream.print(", "); - stream.print(lis.y); - stream.print(", "); - stream.print(lis.z); - stream.print(", "); - stream.print(!buttonVal); // because pull-up - stream.println(); + stream->print(", "); + stream->print(lis.y); + stream->print(", "); + stream->print(lis.z); + stream->print(", "); + stream->print(!buttonVal); // because pull-up + stream->println(); while (!lis.haveNewData()) {