<commit_before>/*
 * tiny_scope.ino - main application
 * Tiny Scope for Arduino project
 *
 * Copyright (C)2015 <NAME>
 *
 * This file may be redistributed under the terms of the MIT license.
 * A copy of this license has been included with this distribution in the file LICENSE.
 */
#if 0 /* add all necessary libs here or they will not be found on the path */
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#endif
#include <Arduino.h>
#include "adc.h"
#include "scope.h"
#include "capture.h"

/****************************************************************************
 * Configurable parameters
 */

// Which analog input to read the data from.
#define ADC_PIN 1

// ADC reference voltage (mV). Default 5000 for AVR 5V, 3300 for Teensy3
// Change this if AREF is connected to a different voltage reference
#define AREF_MV ADC_AREF_MV

// ADC mode (0-5, 0 = default, 5 = fastest less accurate)
// This is NOT the prescaler value, just an index in a table in adc.cpp
// On a 16MHz UNO R3, the grid is 2ms apart while on 5 it goes down to 0.1ms
#define ADC_MODE 0

// Address of I2C OLED display. If screen looks scaled edit Adafruit_SSD1306.h
// and pick SSD1306_128_64 or SSD1306_128_32 that matches display type.
#define DISPLAY_I2C_ADDRESS 0x3C

// Enable PWM outputs on pins 9 and 5 for testing (see setup()). Comment out to disable.
#define ENABLE_PWM

/*
 * End Configurable parameters
 ****************************************************************************/


extern Display display;
static ADCInput adc;
static Capture capture;

/*
 * Display splash screen
 */
void displaySplash(){
    display.clearDisplay();
    display.setTextColor(WHITE);

    display.setTextSize(2);
    display.print(F("Tiny Scope"));

    display.setTextSize(1);
    display.printf(F("\nINPUT A%d, VREF "), adc.input);
    display.printSmallUnits(1000L*capture.rangemV, "V\n"); // printSmallUnits expects micro[V]
    display.print(F("ADC CLOCK "));
    display.printLargeUnits(adc.getClock(), "Hz\n");
    display.print(F("Sample Rate "));
    display.printLargeUnits(adc.getSampleRate(), "Hz\n");
    display.display();
    delay(4000);
}

void setup(){
    adc.init(ADC_PIN, ADC_MODE);
    int success = capture.init(adc, SCREEN_WIDTH, AREF_MV);
    delay(100);  // give time for display to init; if display blank increase delay
    display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDRESS);
    display.setRotation(2);
    // Configure capture one sample per pixel (SCREEN_WIDTH samples)
    displaySplash();
    if (success){
        display.print(F("Reading A/D data..."));
    } else {
        display.print(F("Out of memory!"));
    }
    display.display();

#ifdef ENABLE_PWM
    /* 
     * set up PWM outputs for testing: 
     * Read http://playground.arduino.cc/Code/PwmFrequency on influence on millis(), delay() etc
     * short: we should really only change 9 or 10 base freq
     * pins 3, 9, 10, and 11: base 31250Hz / 64 = 488Hz
     * pins 5, 6: base 62500 Hz / 64 = 976Hz
     */<commit_msg>Realized ADCInput object was deep-copied into capture.adc so the original was no longer queried for the bits value from within Capture. Don't want to use an adc indirection for capture, so everyone uses that version now.<commit_after>/*
 * tiny_scope.ino - main application
 * Tiny Scope for Arduino project
 *
 * Copyright (C)2015 <NAME>
 *
 * This file may be redistributed under the terms of the MIT license.
 * A copy of this license has been included with this distribution in the file LICENSE.
 */
#if 0 /* add all necessary libs here or they will not be found on the path */
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#endif
#include <Arduino.h>
#include "adc.h"
#include "scope.h"
#include "capture.h"

/****************************************************************************
 * Configurable parameters
 */

// Which analog input to read the data from.
#define ADC_PIN 1

// ADC reference voltage (mV). Default 5000 for AVR 5V, 3300 for Teensy3
// Change this if AREF is connected to a different voltage reference
#define AREF_MV ADC_AREF_MV

// ADC mode (0-5, 0 = default, 5 = fastest less accurate)
// This is NOT the prescaler value, just an index in a table in adc.cpp
// On a 16MHz UNO R3, the grid is 2ms apart while on 5 it goes down to 0.1ms
#define ADC_MODE 0

// Address of I2C OLED display. If screen looks scaled edit Adafruit_SSD1306.h
// and pick SSD1306_128_64 or SSD1306_128_32 that matches display type.
#define DISPLAY_I2C_ADDRESS 0x3C

// Enable PWM outputs on pins 9 and 5 for testing (see setup()). Comment out to disable.
#define ENABLE_PWM

/*
 * End Configurable parameters
 ****************************************************************************/


extern Display display;
static Capture capture;

/*
 * Display splash screen
 */
void displaySplash(){
    display.clearDisplay();
    display.setTextColor(WHITE);

    display.setTextSize(2);
    display.print(F("Tiny Scope"));

    display.setTextSize(1);
    display.printf(F("\nINPUT A%d VREF "), capture.adc.input);
    display.printSmallUnits(1000L*capture.rangemV, "V\n"); // printSmallUnits expects micro[V]
    display.print(F("ADC CLOCK "));
    display.printLargeUnits(capture.adc.getClock(), "Hz\n");
    display.print(F("Sample Rate "));
    display.printLargeUnits(capture.adc.getSampleRate(), "Hz\n");
    display.display();
    delay(4000);
}

void setup(){
    int success = capture.init(ADCInput(), SCREEN_WIDTH, AREF_MV);
    capture.adc.init(ADC_PIN, ADC_MODE);
    delay(100);  // give time for display to init; if display blank increase delay
    display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDRESS);
    display.setRotation(2);
    // Configure capture one sample per pixel (SCREEN_WIDTH samples)
    displaySplash();
    if (success){
        display.print(F("Reading A/D data..."));
    } else {
        display.print(F("Out of memory!"));
    }
    display.display();

#ifdef ENABLE_PWM
    /* 
     * set up PWM outputs for testing: 
     * Read http://playground.arduino.cc/Code/PwmFrequency on influence on millis(), delay() etc
     * short: we should really only change 9 or 10 base freq
     * pins 3, 9, 10, and 11: base 31250Hz / 64 = 488Hz
     * pins 5, 6: base 62500 Hz / 64 = 976Hz
     */
{'fraction_non_alphanumeric': 0.15289648622981955, 'fraction_numerical': 0.03482114593225704, 'mean_word_length': 3.6981412639405202, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2524442', 'n_tokens_mistral': 2184, 'n_tokens_neox': 1944, 'n_words': 684}