<commit_before>// The googly eye effect is based on a physical model of a pendulum.
// The pendulum motion is driven by accelerations in 2 axis.
// Eye color varies with orientation of the magnetometer
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Simple_AHRS.h>
#include <FastLED.h>

#define DATAPIN_LEFT    0
#define CLOCKPIN_LEFT   1
#define DATAPIN_RIGHT    6
#define CLOCKPIN_RIGHT   9
#define NUM_LEDS 21

#define FRAMES_PER_SECOND  5
#define BRIGHTNESS         120

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

CRGB leftLense[NUM_LEDS];
CRGB rightLense[NUM_LEDS];

Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();
sensors_event_t accel, mag, gyro, temp;


float pos = 6;  // Starting center position of pupil
float increment = 2 * 3.14159 / NUM_LEDS; // distance between pixels in radians
float MomentumH = 0; // horizontal component of pupil rotational inertia
float MomentumV = 0; // vertical component of pupil rotational inertia

// Tuning constants. (a.k.a. "Fudge Factors)
// These can be tweaked to adjust the liveliness and sensitivity of the eyes.
const float friction = 0.985; // frictional damping constant.  1.0 is no friction.
const float swing = 20;  // arbitrary divisor for gravitational force
const float gravity = 100;  // arbitrary divisor for lateral acceleration
const float gestureThreshold = -0.80; // accelerometer threshold for toggling modes
const float pupilRadius = 2; // half-width of pupil (in pixels)

long gestureStart = 0;
long gestureHoldTime = 1700;

uint8_t hue = 0;
uint8_t currentPatternNumber = 1;

typedef void (*SimplePattern)();

typedef void (*Action)();

typedef struct {
    SimplePattern pattern;
    Action action;
} PatternDefinition;
typedef PatternDefinition PatternDefinitionList[];

const PatternDefinitionList patterns = {
        {nothing,       pendulum},
        {nothing,       pendulumAntiGravity},
        {nothing,       bpm},
        {nothing,       juggle},
        {nothing,       sinelon},
        {lowKeyRainbow, rotateClockwise},
        {meteor,        rotateClockwise}
};


void setup(void) {
    FastLED.addLeds<APA102, DATAPIN_LEFT, CLOCKPIN_LEFT>(leftLense, NUM_LEDS).setCorrection(TypicalLEDStrip);
    FastLED.addLeds<APA102, DATAPIN_RIGHT, CLOCKPIN_RIGHT>(rightLense, NUM_LEDS).setCorrection(TypicalLEDStrip);
    FastLED.setBrightness(BRIGHTNESS);

    setupSensor();
    patterns[currentPatternNumber].pattern();
}

void setupSensor() {
    if (!lsm.begin()) {
        while (1);
    }
    lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G); // 2G, 4G, 6G, 8G, 16G
    lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS); //2GAUSS,4GAUSS,8GAUSS,12GAUSS
    lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS); //245DPS,500DPS,2000DPS
}

void loop(void) {
    lsm.getEvent(&accel, &mag, &gyro, &temp);

    checkForGestures(accel);

    patterns[currentPatternNumber].action();
}

void nextPattern() {
    currentPatternNumber = wrapAround(currentPatternNumber + 1, ARRAY_SIZE(patterns));
    patterns[currentPatternNumber].pattern();
}

void previousPattern() {
    currentPatternNumber = wrapAround(currentPatternNumber - 1, ARRAY_SIZE(patterns));
    patterns[currentPatternNumber].pattern();
}

//Constrains a number to to range 0-maxValue exclusive
int wrapAround(int value) {
    return wrapAround(value, NUM_LEDS);
}

int wrapAround(int value, int maxValue) {
    if (value < 0) {
        return value + maxValue;
    }
    if (value > NUM_LEDS - 1) {
        return value - maxValue;
    }
    return value;
}

CRGB convertHeadingToColor(float heading, int brightness) {
    int convertedHeading = map(heading, 0, 51, 0, 255);
    return CHSV(convertedHeading, 255, brightness);<commit_msg>Fixed a bug in wrap around where it was using the wrong upper bound.<commit_after>// The googly eye effect is based on a physical model of a pendulum.
// The pendulum motion is driven by accelerations in 2 axis.
// Eye color varies with orientation of the magnetometer
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Simple_AHRS.h>
#include <FastLED.h>

#define DATAPIN_LEFT    0
#define CLOCKPIN_LEFT   1
#define DATAPIN_RIGHT    6
#define CLOCKPIN_RIGHT   9
#define NUM_LEDS 21

#define FRAMES_PER_SECOND  5
#define BRIGHTNESS         120

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

CRGB leftLense[NUM_LEDS];
CRGB rightLense[NUM_LEDS];

Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();
sensors_event_t accel, mag, gyro, temp;


float pos = 6;  // Starting center position of pupil
float increment = 2 * 3.14159 / NUM_LEDS; // distance between pixels in radians
float MomentumH = 0; // horizontal component of pupil rotational inertia
float MomentumV = 0; // vertical component of pupil rotational inertia

// Tuning constants. (a.k.a. "Fudge Factors)
// These can be tweaked to adjust the liveliness and sensitivity of the eyes.
const float friction = 0.985; // frictional damping constant.  1.0 is no friction.
const float swing = 20;  // arbitrary divisor for gravitational force
const float gravity = 100;  // arbitrary divisor for lateral acceleration
const float gestureThreshold = -0.80; // accelerometer threshold for toggling modes
const float pupilRadius = 2; // half-width of pupil (in pixels)

long gestureStart = 0;
long gestureHoldTime = 1700;

uint8_t hue = 0;
uint8_t currentPatternNumber = 1;

typedef void (*SimplePattern)();

typedef void (*Action)();

typedef struct {
    SimplePattern pattern;
    Action action;
} PatternDefinition;
typedef PatternDefinition PatternDefinitionList[];

const PatternDefinitionList patterns = {
        {nothing,       pendulum},
        {nothing,       pendulumAntiGravity},
        {nothing,       bpm},
        {nothing,       juggle},
        {nothing,       sinelon},
        {lowKeyRainbow, rotateClockwise},
        {meteor,        rotateClockwise}
};


void setup(void) {
    FastLED.addLeds<APA102, DATAPIN_LEFT, CLOCKPIN_LEFT>(leftLense, NUM_LEDS).setCorrection(TypicalLEDStrip);
    FastLED.addLeds<APA102, DATAPIN_RIGHT, CLOCKPIN_RIGHT>(rightLense, NUM_LEDS).setCorrection(TypicalLEDStrip);
    FastLED.setBrightness(BRIGHTNESS);

    setupSensor();
    patterns[currentPatternNumber].pattern();
}

void setupSensor() {
    if (!lsm.begin()) {
        while (1);
    }
    lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G); // 2G, 4G, 6G, 8G, 16G
    lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS); //2GAUSS,4GAUSS,8GAUSS,12GAUSS
    lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS); //245DPS,500DPS,2000DPS
}

void loop(void) {
    lsm.getEvent(&accel, &mag, &gyro, &temp);

    checkForGestures(accel);

    patterns[currentPatternNumber].action();
}

void nextPattern() {
    currentPatternNumber = wrapAround(currentPatternNumber + 1, ARRAY_SIZE(patterns));
    patterns[currentPatternNumber].pattern();
}

void previousPattern() {
    currentPatternNumber = wrapAround(currentPatternNumber - 1, ARRAY_SIZE(patterns));
    patterns[currentPatternNumber].pattern();
}

//Constrains a number to to range 0-maxValue exclusive
int wrapAround(int value) {
    return wrapAround(value, NUM_LEDS);
}

int wrapAround(int value, int maxValue) {
    if (value < 0) {
        return value + maxValue;
    }
    if (value > maxValue - 1) {
        return value - maxValue;
    }
    return value;
}

CRGB convertHeadingToColor(float heading, int brightness) {
    int convertedHeading = map(heading, 0, 51, 0, 255);
    return CHSV(convertedHeading, 255, brightness);
{'fraction_non_alphanumeric': 0.10260173448965977, 'fraction_numerical': 0.02828552368245497, 'mean_word_length': 3.9609530112508273, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2313702', 'n_tokens_mistral': 2719, 'n_tokens_neox': 2433, 'n_words': 668}