<commit_before>/*
*	Odometer.cpp - Handles the odometer (speed encoder) sensor of the Smartcar.
*	Version: 0.2
*	Author: <NAME> (based on the Smartcar project by Team Pegasus)
* 	License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html
*/
#include "CaroloCup.h"

/* ---- ODOMETER ---- */
void updateCounter1(); //ISR for the odometer
void updateCounter2();
// Macro to convert from odometer pulses to centimeters. (ca. 40 pulses per meter, that's why we multiply by 2.5 to find value in cm)
#define PulsesToCentimeters(pulses) ((pulses << 1)/5)

volatile unsigned long _pulseCounter[2];
static unsigned short odometers = 0;

Odometer::Odometer(){
_odometerID = odometers++;
}

int Odometer::attach(unsigned short odometerPin){
	_odometerInterruptPin = digitalPinToInterrupt(odometerPin);
	if (_odometerInterruptPin != NOT_AN_INTERRUPT){
		if (!_odometerID){
			attachInterrupt(_odometerInterruptPin, updateCounter1, CHANGE);
		}else if (_odometerID == 1){
			attachInterrupt(_odometerInterruptPin, updateCounter2, CHANGE);
		}else{
			return -1; //too many encoders attached
		}
		return 1; //everything went as it should
	}
	return 0; //invalid interrupt pin
}

void Odometer::begin(){
	_pulseCounter[_odometerID] = 0; //initialize the counter
}

unsigned long Odometer::getDistance(){
	noInterrupts();
	unsigned long pulses = _pulseCounter[_odometerID];
	interrupts();
	return PulsesToCentimeters(pulses);
}

void Odometer::detach(){
	_pulseCounter[_odometerID] = 0; //reinitialize the counter so if distance is calculated again, result will be 0 and not what was left from before
	detachInterrupt(_odometerInterruptPin);
}

void updateCounter1(){
	_pulseCounter[0]++;
}
void updateCounter2(){<commit_msg>we don't disable interrupts anymore as this causes disturbances to interrupt based operations<commit_after>/*
*	Odometer.cpp - Handles the odometer (speed encoder) sensor of the Smartcar.
*	Version: 0.2
*	Author: <NAME> (based on the Smartcar project by Team Pegasus)
* 	License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html
*/
#include "CaroloCup.h"

/* ---- ODOMETER ---- */
void updateCounter1(); //ISR for the odometer
void updateCounter2();
// Macro to convert from odometer pulses to centimeters. (ca. 40 pulses per meter, that's why we multiply by 2.5 to find value in cm)
#define PulsesToCentimeters(pulses) ((pulses << 1)/5)

volatile unsigned long _pulseCounter[2];
static unsigned short odometers = 0;

Odometer::Odometer(){
_odometerID = odometers++;
}

int Odometer::attach(unsigned short odometerPin){
	_odometerInterruptPin = digitalPinToInterrupt(odometerPin);
	if (_odometerInterruptPin != NOT_AN_INTERRUPT){
		if (!_odometerID){
			attachInterrupt(_odometerInterruptPin, updateCounter1, CHANGE);
		}else if (_odometerID == 1){
			attachInterrupt(_odometerInterruptPin, updateCounter2, CHANGE);
		}else{
			return -1; //too many encoders attached
		}
		return 1; //everything went as it should
	}
	return 0; //invalid interrupt pin
}

void Odometer::begin(){
	_pulseCounter[_odometerID] = 0; //initialize the counter
}

unsigned long Odometer::getDistance(){
	return PulsesToCentimeters(_pulseCounter[_odometerID]);
}

void Odometer::detach(){
	_pulseCounter[_odometerID] = 0; //reinitialize the counter so if distance is calculated again, result will be 0 and not what was left from before
	detachInterrupt(_odometerInterruptPin);
}

void updateCounter1(){
	_pulseCounter[0]++;
}
void updateCounter2(){
{'fraction_non_alphanumeric': 0.1143106457242583, 'fraction_numerical': 0.015706806282722512, 'mean_word_length': 5.1301247771836005, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1617902', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1100, 'n_words': 339}