<commit_before>/*  
 *  Controller
 *  
 *  Controller - Software for the Arduino to be used for Design E344 
 *  Updated on 12/07/2016
 *  Author: <NAME> (<EMAIL>)
 *  
 *  This is free software - you may redistribute and modify it freely.
 *  This software is provided without any warranty.
 */


#include "SimpleTimer.h"
#include <EEPROM.h>

// declaration and initialization of variables and constants

// time between samples in milliseconds
const int sampleInterval = 200; 
// digital & analog I/O pin setup
const int pwmVRefPin = 5;
const int pwmIRefPin = 6;
const int VsensePin = A0;
const int IsensePin = A1;
// measurement variables
int sensorBufferLength = 5;
int analogSensorA0Value = 0;
int sensorA0ZeroVoltReference;
int sensorA0ZeroVoltReferenceDef = 80;
int sensorA0OtherReference;
int sensorA0OtherReferenceDef = 800;
int calOtherReferenceVoltage;
int calOtherReferenceVoltageDef = 10000;
int correctedVoltageValue;
int sensorA0SampleBuffer[20];
int sensorA0SampleBufferPosition = 0;
int analogSensorA1Value = 0;
int sensorA1ZeroMilliAReference;
int sensorA1ZeroMilliAReferenceDef = 8;
int sensorA1OtherReference;
int sensorA1OtherReferenceDef = 80;
int calOtherReferenceCurrent;
int calOtherReferenceCurrentDef = 100;
int correctedCurrentValue;
int sensorA1SampleBuffer[20];
int sensorA1SampleBufferPosition = 0;
// output variables
int VRefValue = 0;
int VRefPwmValue = 0;
int IRefValue = 0;
int IRefPwmValue = 0;
// serial communication buffers
char serialInBuffer[64];
// timer variables
SimpleTimer timer;
int serialReceiveTimerID;
int serialTransmitTimerID;
int sensorSampleTimerID;
int timedLoopTimerID;
// status variables
int isStreamingSensorData;
int isStreamingSensorDataDef = 0;
int isFirstRun;
int isFirstRunDef = 101;

// standard Arduino setup function, automatically called before the loop (below) function is called
void setup() {
  clearSampleBuffers();
  Serial.setTimeout(50);
  Serial.begin(9600);
  loadSettings();
  pinSetup();
  startTimedLoop();
}

// standard "loop" function for Arduino (similar to "main" in C program)
void loop() {
  // put your main code here, to run repeatedly:
  timer.run();
}

// setup the timed loop execution
void startTimedLoop() {
  timedLoopTimerID = timer.setInterval(sampleInterval, timedLoop); 
}

// program loop executed at a fixed interval (also the sample rate)
void timedLoop() {    
  receiveSerial();  
  updateVRefPwmValue();
  updateIRefPwmValue();
  sampleSensors();
}

// function for initializing sample buffers to all zeros
void clearSampleBuffers() {
  int i = 0;
  while (i < sensorBufferLength) {
    sensorA0SampleBuffer[i] = 0;
    sensorA1SampleBuffer[i] = 0;
    i = i + 1;
  }
}

// setup pins
void pinSetup() {
  pinMode(pwmVRefPin, OUTPUT);
  analogWrite(pwmVRefPin, 0);
  pinMode(pwmIRefPin, OUTPUT);
  analogWrite(pwmIRefPin, 0);
}

// load settings from EEPROM
void loadSettings() {
  // read from EEPROM
  isFirstRun = int(EEPROM.read(1));
  isStreamingSensorData = int(EEPROM.read(2));
  sensorA0ZeroVoltReference = readSensorValueFromEEPROM(3);
  sensorA0OtherReference = readSensorValueFromEEPROM(5);
  sensorA1ZeroMilliAReference = readSensorValueFromEEPROM(7);
  sensorA1OtherReference = readSensorValueFromEEPROM(9);
  calOtherReferenceVoltage = readSensorValueFromEEPROM(11);
  calOtherReferenceCurrent = readSensorValueFromEEPROM(13);

  // check wether this is the first run
  if (isFirstRun != isFirstRunDef) {
    isFirstRun = isFirstRunDef;
    isStreamingSensorData = isStreamingSensorDataDef;
    sensorA0ZeroVoltReference = sensorA0ZeroVoltReferenceDef;
    sensorA0OtherReference = sensorA0OtherReferenceDef;
    sensorA1ZeroMilliAReference = sensorA1ZeroMilliAReferenceDef;
    sensorA1OtherReference = sensorA1OtherReferenceDef;
    calOtherReferenceVoltage = calOtherReferenceVoltageDef;
    calOtherReferenceCurrent = calOtherReferenceCurrentDef;
    // save defaults to memory
    saveSettings();
  }
}<commit_msg>spelling<commit_after>/*  
 *  Controller
 *  
 *  Controller - Software for the Arduino to be used for Design E344 
 *  Updated on 12/07/2016
 *  Author: <NAME> (<EMAIL>)
 *  
 *  This is free software - you may redistribute and modify it freely.
 *  This software is provided without any warranty.
 */


#include "SimpleTimer.h"
#include <EEPROM.h>

// declaration and initialization of variables and constants

// time between samples in milliseconds
const int sampleInterval = 200; 
// digital & analog I/O pin setup
const int pwmVRefPin = 5;
const int pwmIRefPin = 6;
const int VsensePin = A0;
const int IsensePin = A1;
// measurement variables
int sensorBufferLength = 5;
int analogSensorA0Value = 0;
int sensorA0ZeroVoltReference;
int sensorA0ZeroVoltReferenceDef = 80;
int sensorA0OtherReference;
int sensorA0OtherReferenceDef = 800;
int calOtherReferenceVoltage;
int calOtherReferenceVoltageDef = 10000;
int correctedVoltageValue;
int sensorA0SampleBuffer[20];
int sensorA0SampleBufferPosition = 0;
int analogSensorA1Value = 0;
int sensorA1ZeroMilliAReference;
int sensorA1ZeroMilliAReferenceDef = 8;
int sensorA1OtherReference;
int sensorA1OtherReferenceDef = 80;
int calOtherReferenceCurrent;
int calOtherReferenceCurrentDef = 100;
int correctedCurrentValue;
int sensorA1SampleBuffer[20];
int sensorA1SampleBufferPosition = 0;
// output variables
int VRefValue = 0;
int VRefPwmValue = 0;
int IRefValue = 0;
int IRefPwmValue = 0;
// serial communication buffers
char serialInBuffer[64];
// timer variables
SimpleTimer timer;
int serialReceiveTimerID;
int serialTransmitTimerID;
int sensorSampleTimerID;
int timedLoopTimerID;
// status variables
int isStreamingSensorData;
int isStreamingSensorDataDef = 0;
int isFirstRun;
int isFirstRunDef = 101;

// standard Arduino setup function, automatically called before the loop (below) function is called
void setup() {
  clearSampleBuffers();
  Serial.setTimeout(50);
  Serial.begin(9600);
  loadSettings();
  pinSetup();
  startTimedLoop();
}

// standard "loop" function for Arduino (similar to "main" in C program)
void loop() {
  // put your main code here, to run repeatedly:
  timer.run();
}

// setup the timed loop execution
void startTimedLoop() {
  timedLoopTimerID = timer.setInterval(sampleInterval, timedLoop); 
}

// program loop executed at a fixed interval (also the sample rate)
void timedLoop() {    
  receiveSerial();  
  updateVRefPwmValue();
  updateIRefPwmValue();
  sampleSensors();
}

// function for initializing sample buffers to all zeros
void clearSampleBuffers() {
  int i = 0;
  while (i < sensorBufferLength) {
    sensorA0SampleBuffer[i] = 0;
    sensorA1SampleBuffer[i] = 0;
    i = i + 1;
  }
}

// setup pins
void pinSetup() {
  pinMode(pwmVRefPin, OUTPUT);
  analogWrite(pwmVRefPin, 0);
  pinMode(pwmIRefPin, OUTPUT);
  analogWrite(pwmIRefPin, 0);
}

// load settings from EEPROM
void loadSettings() {
  // read from EEPROM
  isFirstRun = int(EEPROM.read(1));
  isStreamingSensorData = int(EEPROM.read(2));
  sensorA0ZeroVoltReference = readSensorValueFromEEPROM(3);
  sensorA0OtherReference = readSensorValueFromEEPROM(5);
  sensorA1ZeroMilliAReference = readSensorValueFromEEPROM(7);
  sensorA1OtherReference = readSensorValueFromEEPROM(9);
  calOtherReferenceVoltage = readSensorValueFromEEPROM(11);
  calOtherReferenceCurrent = readSensorValueFromEEPROM(13);

  // check whether this is the first run
  if (isFirstRun != isFirstRunDef) {
    isFirstRun = isFirstRunDef;
    isStreamingSensorData = isStreamingSensorDataDef;
    sensorA0ZeroVoltReference = sensorA0ZeroVoltReferenceDef;
    sensorA0OtherReference = sensorA0OtherReferenceDef;
    sensorA1ZeroMilliAReference = sensorA1ZeroMilliAReferenceDef;
    sensorA1OtherReference = sensorA1OtherReferenceDef;
    calOtherReferenceVoltage = calOtherReferenceVoltageDef;
    calOtherReferenceCurrent = calOtherReferenceCurrentDef;
    // save defaults to memory
    saveSettings();
  }
}
{'fraction_non_alphanumeric': 0.08229616459232919, 'fraction_numerical': 0.026162052324104648, 'mean_word_length': 5.109387121799845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7455917', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2455, 'n_words': 674}