<commit_before>#include <string.h>

#include "mc_board.h"
#include "mc_digital_io.h"
#include "mc_error.h"
#include "mc_io_event.h"

#define MAX_IO_EVENTS 50

static mc_io_event_data io_events[MAX_IO_EVENTS];
static int io_events_pos = 0;

int mc_add_io_event(int time, int pin, int value) {
    if (! mc_is_digital_pin(pin)) { return MC_WRONG_PIN; }
    if (value != VALUE_LOW && value != VALUE_HIGH) { return MC_WRONG_VALUE; }

    io_events[io_events_pos++] = (mc_io_event_data) {
        .time = time,
        .pin = pin,
        .value = value
    };
    return MC_SUCCESS;
}

int mc_get_io_events(int time1, int time2, mc_io_event_data io_ev[], int size) {   
    int count = 0;
    for (int i = 0; i <= io_events_pos; i++) {
        if (time1 <= io_events[i].time && io_events[i].time <= time2) {
            memcpy(&io_ev[count++], &io_events[i], sizeof(mc_io_event_data));<commit_msg>[FIX] microclib: IO event always firing<commit_after>#include <string.h>

#include "mc_board.h"
#include "mc_digital_io.h"
#include "mc_error.h"
#include "mc_io_event.h"

#define MAX_IO_EVENTS 50

static mc_io_event_data io_events[MAX_IO_EVENTS];
static int io_events_pos = -1;

int mc_add_io_event(int time, int pin, int value) {
    if (! mc_is_digital_pin(pin)) { return MC_WRONG_PIN; }
    if (value != VALUE_LOW && value != VALUE_HIGH) { return MC_WRONG_VALUE; }

    io_events[++io_events_pos] = (mc_io_event_data) {
        .time = time,
        .pin = pin,
        .value = value
    };
    return MC_SUCCESS;
}

int mc_get_io_events(int time1, int time2, mc_io_event_data io_ev[], int size) {   
    int count = 0;
    for (int i = 0; i <= io_events_pos; i++) {
        if (time1 <= io_events[i].time && io_events[i].time <= time2) {
            memcpy(&io_ev[count++], &io_events[i], sizeof(mc_io_event_data));
{'fraction_non_alphanumeric': 0.13789299503585217, 'fraction_numerical': 0.009928295642581356, 'mean_word_length': 3.6632390745501286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '4863516', 'n_tokens_mistral': 734, 'n_tokens_neox': 721, 'n_words': 154}