<commit_before>#include "temperature_manager.h"
#include "periph/gpio.h"
#include <stdio.h>

static float temperatureWindow[WINDOW_SIZE];
static int record_count = 0;
static int current_index = 0;

uint32_t init_fan(void)
{
    uint32_t freq = pwm_init(FAN_DEVICE, MODE, FREQU, STEPS);

    /*if (freq != 0) {
        pwm_set(FAN_DEVICE, FAN_CHAN, 300);
    }*/

    return freq;
}

int manage_temperature(int temperature)
{
    printf("Received temperature %d\n", temperature);
    if (record_count < WINDOW_SIZE) {
        record_count++;
    }
    if (current_index == WINDOW_SIZE) {
        current_index = 0;
    }

    temperatureWindow[current_index++] = temperature;

    int i;

    float temperature_sum = 0;
    for (i = 0; i < record_count; i++) {
        temperature_sum += temperatureWindow[i];
    }

    int average_temp = temperature_sum / record_count;

    if (average_temp < FAN_LOW_TEMP * 100) {
        pwm_set(FAN_DEVICE, FAN_CHAN, (int)(STEPS / 2.5));
    } else {
        if (average_temp < FAN_TEMP * 100) {
            pwm_set(FAN_DEVICE, FAN_CHAN, 2 * STEPS / 3);
        } else {
            pwm_set(FAN_DEVICE, FAN_CHAN, STEPS - 100);
        }
    }

    return 0;
}<commit_msg>Removed hard subtraction in temperature manager for fan<commit_after>#include "temperature_manager.h"
#include "periph/gpio.h"
#include <stdio.h>

static float temperatureWindow[WINDOW_SIZE];
static int record_count = 0;
static int current_index = 0;

uint32_t init_fan(void)
{
    uint32_t freq = pwm_init(FAN_DEVICE, MODE, FREQU, STEPS);

    /*if (freq != 0) {
        pwm_set(FAN_DEVICE, FAN_CHAN, 300);
    }*/

    return freq;
}

int manage_temperature(int temperature)
{
    printf("Received temperature %d\n", temperature);
    if (record_count < WINDOW_SIZE) {
        record_count++;
    }
    if (current_index == WINDOW_SIZE) {
        current_index = 0;
    }

    temperatureWindow[current_index++] = temperature;

    int i;

    float temperature_sum = 0;
    for (i = 0; i < record_count; i++) {
        temperature_sum += temperatureWindow[i];
    }

    int average_temp = temperature_sum / record_count;

    if (average_temp < FAN_LOW_TEMP * 100) {
        pwm_set(FAN_DEVICE, FAN_CHAN, (int)(STEPS / 2.5));
    } else {
        if (average_temp < FAN_TEMP * 100) {
            pwm_set(FAN_DEVICE, FAN_CHAN, 2 * STEPS / 3);
        } else {
            pwm_set(FAN_DEVICE, FAN_CHAN, STEPS - (STEPS / 10));
        }
    }

    return 0;
}
{'fraction_non_alphanumeric': 0.11948157148643175, 'fraction_numerical': 0.021466180639935196, 'mean_word_length': 2.782542113323124, 'pattern_counts': {'":': 0, '<': 13, '<?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': '753889', 'n_tokens_mistral': 945, 'n_tokens_neox': 877, 'n_words': 194}