<commit_before>/**
 * Copyright (c) 2016 FirstBuild
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

#include "coldbrew.h"

ColdBrew coldBrew;

void enableInterrupt(void) {
  OCR0A = 0xaf;
  TIMSK0 |= (1 << OCIE0A);
}

SIGNAL(TIMER0_COMPA_vect) {
  coldBrew.tick();
}

void setup(void) {
  coldBrew.setup();
  enableInterrupt();
}

void loop(void) {
  coldBrew.loop();
}
<commit_msg>Merging updated/tested code for board V2 from experimental<commit_after>#include <FiniteStateMachine.h>
#include <Adafruit_NeoPixel.h>

#define DRAIN_MTR 6
#define VALV_ATM 7
#define VACU_PUMP	8
#define CAP_TCH     A6
#define PRS_SEN 10
#define NEOPIX  5
#define NUM_OF_PIX 12

//  Tell compiler that functions exist, just implementated later
extern void idled();
extern void vacuum();
extern void dwell();
extern void drain();
extern void vacuumUpdate();
extern void dwellUpdate();
extern void drainUpdate();

////	Define the states within the SM

// Idle state
State idle_state = State(idled);			

// Vacuum state, with accompanying update function for specific behaviours and controls 
State vacu_state = State(vacuum, vacuumUpdate, NULL);	

// Dwell state, with accompanying update function for extra dwell state behaviours	
State dwll_state = State(dwell, dwellUpdate, NULL);		

// Drain state, with timeout of X seconds
State drin_state = State(drain, drainUpdate, NULL);	


FSM stateMachine = FSM(idle_state);		//	Initial SM with beginning state

unsigned long startTime;			//	Used to track times for Vacuum/Dwell timer
unsigned long setTimeLimit = 120000;		//	User defined time limit

unsigned long stateStartTime;			//	Used to track times for entering Vacuum/Dwell states
unsigned long stateDebounceLimit = 30000;	//	Used to define state debounce time limit
unsigned long vacuDebounceLimit = 1000;    //  Used to define state debounce time limit

unsigned long drainTimeout = 60000;

int buttonState;             // the current reading from the input pin
int lastButtonState = HIGH;   // the previous reading from the input pin
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 100;    // the debounce time; increase if the output flickers

// Different states of the machine: Idle, Vacuum, Dwell, and Drain
enum states {IDLED, VACU, DWLL, DRIN};
const byte NUM_OF_STATES = 4;	//	Number of total states

Adafruit_NeoPixel ledStat = Adafruit_NeoPixel(NUM_OF_PIX, NEOPIX, NEO_GRB + NEO_KHZ800);		//	Neopixel initializiation 

/*************************** COLOR FOR MODES  ***************************/
uint32_t idleLEDColor = ledStat.Color(0, 255, 0);			// Green
uint32_t vacuumLEDColor = ledStat.Color(255, 255, 0);		// Yellow
uint32_t dwellLEDColor = ledStat.Color(238, 130, 238);   // Purple
uint32_t drainLEDColor = ledStat.Color(255, 0, 0);		// Red

void setup() {
	Serial.begin(9600);
	pinMode(DRAIN_MTR, OUTPUT);
	pinMode(VALV_ATM, OUTPUT);
	pinMode(VACU_PUMP, OUTPUT);
	pinMode(PRS_SEN, INPUT_PULLUP);
	pinMode(CAP_TCH, INPUT);
	ledStat.begin();
}

//	Keeps track of button presses to direct button states
//	Value only exists within this function; Value exists between iterations
static int buttonPresses = 0; 

void loop() {

    // read the state of the switch into a local variable:
    int reading = digitalRead(CAP_TCH);
    
    // If the switch changed, due to noise or pressing:
    if (reading != lastButtonState) {
        // reset the debouncing timer
        lastDebounceTime = millis();
    }
    
    if ((millis() - lastDebounceTime) > debounceDelay) {
        // if the button state has changed:
        if (reading != buttonState) {
          buttonState = reading;
    
          // only toggle the LED if the new button state is HIGH
          if (buttonState == LOW) {
            //    Buttons used to manipulate states in SM
            
        
            //  Increment buttonPresses and constrain it to [0, NUM_OF_STATES - 1]
            buttonPresses = ++buttonPresses % NUM_OF_STATES; 
            
            Serial.print("This is what: ");
            Serial.println(buttonPresses);
            switch (buttonPresses){
                case IDLED:
                	Serial.println("IDLE");
               		stateMachine.transitionTo(idle_state);
                	break;
        
                case VACU:
                	Serial.println("VACU");
                   	//  Begin timer for total time between Vacuum and Dwell states
                   	startTime = millis(); 
					stateStartTime = millis();

					//	Ensure next button press will lead to DRAIN state.
					buttonPresses = 2; 

                    stateMachine.transitionTo(vacu_state);
                    break;
        
                case DWLL:
                    Serial.println("DWLL");
                    stateMachine.transitionTo(drin_state);
                    break;
        
                case DRIN:
                	Serial.println("DRIN");
					stateStartTime = millis();
                	stateMachine.transitionTo(drin_state);
                	break;
            }
          }
        }
    }

    lastButtonState = reading;

	//	Updates the SM for every loop -- APPLICATION CRITICAL
    stateMachine.update();
}

void setPixelRingColor(uint32_t val) {
	for (int i = 0; i < NUM_OF_PIX; i++) {
		ledStat.setPixelColor(i, val);
	}
	ledStat.show();
}	

//	Pump is turned off first, pump valve closes, and finally the atm valve
//		closes. LED status is cleared. 
void idled() {
	digitalWrite(VACU_PUMP, LOW);
	digitalWrite(DRAIN_MTR, LOW);
	digitalWrite(VALV_ATM, LOW);

	setPixelRingColor(idleLEDColor);
}

//	The pump valve opens, then the pump turns on. Atm valve is ensured
//		to be closed due to necessary safety redundancy. Displays 
//		Yellow on LED status.
void vacuum() {
	digitalWrite(DRAIN_MTR, LOW);
	digitalWrite(VACU_PUMP, HIGH);
	digitalWrite(VALV_ATM, LOW);
	   
	setPixelRingColor(vacuumLEDColor);
}

//	Keeps track of pressure and transitions to Dwell state if 
//		pressure threshold is met. If time set by setTimeLimit
//		is met, transition immediately to the Drain state.
void vacuumUpdate() {
	//	Keep track of time. Kick into Drain state when time is up. 
	//		Ensures timer has priority over pressure.
	if ((millis() - startTime) > setTimeLimit) {
		stateStartTime = millis();

		//	Ensure that next button press in DRAIN state will lead to IDLE
		buttonPresses = 3;

       	stateMachine.immediateTransitionTo(drin_state);
   	} else if ((digitalRead(PRS_SEN) == LOW) && ((millis() - stateStartTime) > vacuDebounceLimit)) {
    	//	If the pressure is at or above the calibrated sensor threshold
    	//		the pin will read LOW, setting immediate transition to
    	//		the Dwell state. PRS_SEN is NO.
        Serial.print("Vacuum Update:  \t");
        Serial.println((millis() - stateStartTime));

		//  Resets state start time for next state.
        stateStartTime = millis();

		//	Ensure button kicks into DRAIN state if button is pressed
		buttonPresses = 2;

    	stateMachine.immediateTransitionTo(dwll_state);
	}
}

//	Pump is first turned off, then the valve pump is turned off. 
//		Atm valve is ensured to be closed. Displays Red on LED status.
void dwell() {
	digitalWrite(VACU_PUMP, LOW);
	digitalWrite(DRAIN_MTR, LOW);
   	digitalWrite(VALV_ATM, LOW);
	    
	setPixelRingColor(dwellLEDColor);
}

//	If pressure fall threshold, SM transitions immediately to Vacuum state.
//		Similar timer exists as in vacuumUpdate.
void dwellUpdate() {
	//	Keep track of time. Kick into Drain state when time is up. 
	//		Ensures timer has priority over pressure.
	if ((millis() - startTime) > setTimeLimit) {
		stateStartTime = millis();

		//	Ensure that next button press in DRAIN state will lead to IDLE
		buttonPresses = 3;

		stateMachine.immediateTransitionTo(drin_state);
	} else if ((digitalRead(PRS_SEN) == HIGH) && ((millis() - stateStartTime) > stateDebounceLimit)) {
    	//	If pressure is below set pressure threshold, return to 
    	//		Vacuum state to repressurize. 
        Serial.print("Dwell Update: \t");
        Serial.println((millis() - stateStartTime));

        stateStartTime = millis();
		stateMachine.immediateTransitionTo(vacu_state);
	}
} 


//	Pump is turned off first, then the pump valve closes. The atm valve
//		opens, and displays Green as the LED status.
void drain() {  
	// Close pump valve, turn off pump, and open the atmosphere valve
	//	to equalize with external pressure.
	digitalWrite(VACU_PUMP, LOW);
	digitalWrite(DRAIN_MTR, HIGH);
	digitalWrite(VALV_ATM, HIGH);

	setPixelRingColor(drainLEDColor);
}


void drainUpdate() {
	if((millis() - stateStartTime) >  drainTimeout) {
		stateMachine.transitionTo(idle_state);
	}
}


{'fraction_non_alphanumeric': 0.09307851239669422, 'fraction_numerical': 0.009917355371900827, 'mean_word_length': 3.0287141073657926, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, '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': '4365204', 'n_tokens_mistral': 3164, 'n_tokens_neox': 2896, 'n_words': 1021}