<commit_before>#include "Arduino.h"
#include "LegoTrain.h"


#define MAX_SPEED 1
#define STOP 0
#define ACCELLERATION 1300
#define STOP_TIME 300 // Stay on station for 5 minutes

LegoTrain::LegoTrain(const PowerFunctions& train, uint8_t sensorPin) : _train(train)
{
  _train = train;
  _nextUpdateMillis = 0;
  _state = ACCELERATING;
  _currentSpeed = STOP;
  _sensorPin = sensorPin;
  pinMode(_sensorPin, INPUT);
}

void LegoTrain::sendState()
{
  _train.single_pwm(BLUE, _speeds[_currentSpeed]);
}

void LegoTrain::update()
{
  uint32_t currentMillis = millis();
  if ((int32_t)(currentMillis - _nextUpdateMillis) < 0) { return; }

  switch(_state) {
    case ACCELERATING:
      if (_currentSpeed == MAX_SPEED) {
        _state = RUNNING;
        _nextUpdateMillis = 0;
        break;
      }
      _currentSpeed++;
      sendState();
      _nextUpdateMillis = currentMillis + ACCELLERATION;
      break;
    case RUNNING:
      _nextUpdateMillis = 0;
      if (digitalRead(_sensorPin) == HIGH) {
        _state = BREAKING;
        break;
      }
      break;
    case BREAKING:
      if (_currentSpeed == STOP) {
        _state = STOPPED;
        _nextUpdateMillis = currentMillis + 1000 * (uint32_t)STOP_TIME;
        break;
      }
      _currentSpeed--;
      sendState();
      _nextUpdateMillis = currentMillis + ACCELLERATION;
      break;
    case STOPPED:<commit_msg>Tweaks to train logic and timing<commit_after>#include "Arduino.h"
#include "LegoTrain.h"


#define MAX_SPEED 3
#define STOP 0
#define ACCELLERATION 500
#define STOP_TIME 300 // Stay on station for 5 minutes

LegoTrain::LegoTrain(const PowerFunctions& train, uint8_t sensorPin) : _train(train) {
  _train = train;
  _nextUpdateMillis = 0;
  _state = ACCELERATING;
  _currentSpeed = STOP;
  _sensorPin = sensorPin;
  pinMode(_sensorPin, INPUT);
}

void LegoTrain::sendState() {
  _train.single_pwm(BLUE, _speeds[_currentSpeed]);
}

void LegoTrain::update() {
  uint32_t currentMillis = millis();
  if ((int32_t)(currentMillis - _nextUpdateMillis) < 0) { return; }

  switch(_state) {
    case ACCELERATING:
      if (_currentSpeed == MAX_SPEED) {
        _state = RUNNING;
        _nextUpdateMillis = currentMillis + 5000;
        break;
      }
      _currentSpeed++;
      sendState();
      _nextUpdateMillis = currentMillis + ACCELLERATION;
      break;
    case RUNNING:
      _nextUpdateMillis = 0;
      if (digitalRead(_sensorPin) == HIGH) {
        _state = BREAKING;
        break;
      }
      break;
    case BREAKING:
      if (_currentSpeed == STOP) {
        _state = STOPPED;
        _nextUpdateMillis = currentMillis + 1000 * (uint32_t)STOP_TIME;
        break;
      }
      _currentSpeed--;
      sendState();
      _nextUpdateMillis = currentMillis + ACCELLERATION;
      break;
    case STOPPED:
{'fraction_non_alphanumeric': 0.10196779964221825, 'fraction_numerical': 0.018604651162790697, 'mean_word_length': 2.9491525423728815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4010103', 'n_tokens_mistral': 1012, 'n_tokens_neox': 958, 'n_words': 209}