summaryrefslogtreecommitdiff
path: root/src/rocketUtils.cpp
blob: 45fcfc3c4af0ddca8fe422506ad7dc082c734408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "../include/rocketUtils.hpp"

double deploy_percentage_to_angle(double percentage) {

    return (MAX_ANGLE - MIN_ANGLE) / 100.0 * percentage + MIN_ANGLE;
}


std::string format_data(std::string prefix, double data, int precision) {

    std::stringstream stream;
    stream << std::fixed << std::setprecision(precision) << data;
    std::string s = stream.str();
    return prefix + s;
}

bool led_out(Vehicle *vehicle) {

    std::ofstream file;
    file.open(LED_FILENAME);
    if (!file.is_open()) {
        return false;
    }

    file << std::to_string(vehicle->led_brightness);
    file.close();

    vehicle->led_time = time(nullptr);
    vehicle->led_brightness = (vehicle->led_brightness + 1) % 2;

    return true;
}

std::string state_for_log[5] = {"ON_PAD", "BOOST", "GLIDE", "APOGEE", "DONE"};