<commit_before>#include "Adafruit_SSD1306.h"

#include "FiniteStateMachine.h"
#include "AlarmManager.h"

/*==================== MAIN ====================*/

State Start = State(enterStart, updateStart, NULL);
State Clock = State(updateClock);
State Alarm = State(enterAlarm, updateAlarm, NULL);

FSM stateMachine = FSM(Start);

// use hardware SPI
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 Display(OLED_DC, OLED_RESET, OLED_CS);

#define ALARM_LENGTH 10000
AlarmManager alarms = AlarmManager();

#define STARTUP_LENGTH 10000
#define INTERVAL 100

unsigned long stateMillis;
unsigned long previousMillis;

uint8_t previousMinute;

void setup() {
  Serial.begin(9600);

  Display.begin(SSD1306_SWITCHCAPVCC);

  Spark.function("add", add);
  Spark.function("remove", remove);
  Spark.function("clear", clear);

  Display.display();
  Display.setTextColor(WHITE);

  Time.zone(-5);

  alarms.load();
  Serial.print(alarms);
}

void loop() {
  stateMachine.update();
}

void enterStart() {
  stateMillis = millis();
}

void updateStart() {
  unsigned long currentMillis = millis();

  if(currentMillis - stateMillis >= STARTUP_LENGTH) {
    stateMachine.transitionTo(Clock);
  }
}

void updateClock() {
  unsigned long currentMillis = millis();
  uint8_t currentMinute = Time.minute();

  if(currentMinute != previousMinute) {
    previousMinute = currentMinute;

    if(alarms.check()) {
      stateMachine.transitionTo(Alarm);
      return;
    }
  }

  if(currentMillis - previousMillis > INTERVAL) {
    previousMillis = currentMillis;
    int hour   = Time.hourFormat12();
    int minute = Time.minute();
    int second = Time.second();

    Display.clearDisplay();
    Display.setTextSize(3);
    Display.setCursor(0, 22);

    if(hour < 10) Display.print(' ');
    Display.print(hour);
    Display.print(second % 2 == 0 ? ' ' : ':');
    if(minute < 10) Display.print('0');
    Display.print(minute);
    Display.print(' ');
    if(Time.isAM()) Display.print('A');
    if(Time.isPM()) Display.print('P');

    Display.display();
  }
}

void enterAlarm() {
  stateMillis = millis();
}

void updateAlarm() {
  unsigned long currentMillis = millis();

  if(currentMillis - stateMillis >= ALARM_LENGTH) {
    stateMachine.transitionTo(Clock);
    return;<commit_msg>Additional formatting<commit_after>#include "Adafruit_SSD1306.h"

#include "FiniteStateMachine.h"
#include "AlarmManager.h"

/*==================== MAIN ====================*/

State Start = State(enterStart, updateStart, NULL);
State Clock = State(updateClock);
State Alarm = State(enterAlarm, updateAlarm, NULL);

FSM stateMachine = FSM(Start);

// use hardware SPI
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 Display(OLED_DC, OLED_RESET, OLED_CS);

#define ALARM_LENGTH 10000
AlarmManager alarms = AlarmManager();

#define STARTUP_LENGTH 10000
#define INTERVAL 100

unsigned long stateMillis;
unsigned long previousMillis;

uint8_t previousMinute;

void setup() {
  Serial.begin(9600);

  Display.begin(SSD1306_SWITCHCAPVCC);

  Spark.function("add", add);
  Spark.function("remove", remove);
  Spark.function("clear", clear);

  Display.display();
  Display.setTextColor(WHITE);

  Time.zone(-5);

  alarms.load();
  Serial.print(alarms);
}

void loop() {
  stateMachine.update();
}

void enterStart() {
  stateMillis = millis();
}

void updateStart() {
  unsigned long currentMillis = millis();

  if(currentMillis - stateMillis >= STARTUP_LENGTH) {
    stateMachine.transitionTo(Clock);
  }
}

void updateClock() {
  unsigned long currentMillis = millis();
  uint8_t currentMinute = Time.minute();

  if(currentMinute != previousMinute) {
    previousMinute = currentMinute;

    if(alarms.check()) {
      stateMachine.transitionTo(Alarm);
      return;
    }
  }

  if(currentMillis - previousMillis > INTERVAL) {
    previousMillis = currentMillis;
    int hour   = Time.hourFormat12();
    int minute = Time.minute();
    int second = Time.second();

    Display.clearDisplay();
    Display.setTextSize(3);
    Display.setCursor(12, 22);

    if(hour < 10) Display.print(' ');
    Display.print(hour);
    Display.print(second % 2 == 0 ? ' ' : ':');
    if(minute < 10) Display.print('0');
    Display.print(minute);
    /*Display.print(' ');*/

    Display.setTextSize(1);

    if(Time.isAM()) {
      Display.print("AM");
    } else {
      Display.setCursor(102, 37);
      Display.print("PM");
    }

    Display.display();
  }
}

void enterAlarm() {
  stateMillis = millis();
}

void updateAlarm() {
  unsigned long currentMillis = millis();

  if(currentMillis - stateMillis >= ALARM_LENGTH) {
    stateMachine.transitionTo(Clock);
    return;
{'fraction_non_alphanumeric': 0.1532908704883227, 'fraction_numerical': 0.02186836518046709, 'mean_word_length': 4.04389721627409, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4279474', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1556, 'n_words': 317}