<commit_before>#include <limits>
#include <type_traits>

/*
 * Member function definitions of Analog template class.
 * See analog.h for template class declaration.
 */

template <size_t N>
event_source_t Analog<N>::adc_event_source;

template <size_t N>
Analog<N>::Analog() : m_adc_buffer() { }

template <size_t N>
void Analog<N>::start(gptcnt_t sample_rate, bool use_events) {
#ifdef STATIC_SIMULATOR_CONFIG
    /*
     * We manually toggle the Kistler torque sensor measurement line
     * since the output will not be valid unless measurement is enabled _after_
     * the torque sensor is powered on. The analog signal is read from ADC13.
     */
    palClearLine(LINE_TORQUE_MEAS_EN);
    chThdSleepMilliseconds(100);
    palSetLine(LINE_TORQUE_MEAS_EN);
#endif // STATIC_SIMULATOR_CONFIG
    gptStart(&GPTD8, &gpt8cfg1);
    adcStart(&ADCD1, nullptr);
    if (use_events) {
        adcStartConversion(&ADCD1, &adcgrpcfg_events, m_adc_buffer.data(), 1);
    } else {
        adcStartConversion(&ADCD1, &adcgrpcfg, m_adc_buffer.data(), 1);
    }
    gptStartContinuous(&GPTD8, gpt8cfg1.frequency/sample_rate);
}

template <size_t N>
void Analog<N>::stop() {
    gptStopTimer(&GPTD8);
    adcStopConversion(&ADCD1);
    adcStop(&ADCD1);
    gptStop(&GPTD8);
}

template <size_t N>
template <typename T>
T Analog<N>::average_adc_conversion_value(sensor_t channel, T divisor) const {
#ifdef STATIC_SIMULATOR_CONFIG
    channel = static_cast<sensor_t>(static_cast<std::underlying_type_t<sensor_t>>(channel) - 1);
#endif // STATIC_SIMULATOR_CONFIG
    static_assert(4096 * N < std::numeric_limits<adcsample_t>::max(),
            "Template parameter N may result in ADC buffer sum overflow.");
    adcsample_t sum = m_adc_buffer[channel];
    for (unsigned int i = 1; i < m_adc_buffer_depth; ++i) {
        sum += m_adc_buffer[channel + i*m_adc_num_channels];
    }
    return static_cast<T>(sum) / divisor;<commit_msg>Fix Analog conversion buffer depth<commit_after>#include <limits>
#include <type_traits>

/*
 * Member function definitions of Analog template class.
 * See analog.h for template class declaration.
 */

template <size_t N>
event_source_t Analog<N>::adc_event_source;

template <size_t N>
Analog<N>::Analog() : m_adc_buffer() { }

template <size_t N>
void Analog<N>::start(gptcnt_t sample_rate, bool use_events) {
#ifdef STATIC_SIMULATOR_CONFIG
    /*
     * We manually toggle the Kistler torque sensor measurement line
     * since the output will not be valid unless measurement is enabled _after_
     * the torque sensor is powered on. The analog signal is read from ADC13.
     */
    palClearLine(LINE_TORQUE_MEAS_EN);
    chThdSleepMilliseconds(100);
    palSetLine(LINE_TORQUE_MEAS_EN);
#endif // STATIC_SIMULATOR_CONFIG
    gptStart(&GPTD8, &gpt8cfg1);
    adcStart(&ADCD1, nullptr);
    if (use_events) {
        adcStartConversion(&ADCD1, &adcgrpcfg_events,
                m_adc_buffer.data(), m_adc_buffer_depth);
    } else {
        adcStartConversion(&ADCD1, &adcgrpcfg,
                m_adc_buffer.data(), m_adc_buffer_depth);
    }
    gptStartContinuous(&GPTD8, gpt8cfg1.frequency/sample_rate);
}

template <size_t N>
void Analog<N>::stop() {
    gptStopTimer(&GPTD8);
    adcStopConversion(&ADCD1);
    adcStop(&ADCD1);
    gptStop(&GPTD8);
}

template <size_t N>
template <typename T>
T Analog<N>::average_adc_conversion_value(sensor_t channel, T divisor) const {
#ifdef STATIC_SIMULATOR_CONFIG
    channel = static_cast<sensor_t>(static_cast<std::underlying_type_t<sensor_t>>(channel) - 1);
#endif // STATIC_SIMULATOR_CONFIG
    static_assert(4096 * N < std::numeric_limits<adcsample_t>::max(),
            "Template parameter N may result in ADC buffer sum overflow.");
    adcsample_t sum = m_adc_buffer[channel];
    for (unsigned int i = 1; i < m_adc_buffer_depth; ++i) {
        sum += m_adc_buffer[channel + i*m_adc_num_channels];
    }
    return static_cast<T>(sum) / divisor;
{'fraction_non_alphanumeric': 0.1110262286732875, 'fraction_numerical': 0.012732365673542145, 'mean_word_length': 4.329715061058344, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 39, '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': '3773122', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1375, 'n_words': 305}