Add overheat protection
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/* Copyright (c) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ntc.h"
|
||||
|
||||
|
||||
36
barista/test/test_overheat.c
Normal file
36
barista/test/test_overheat.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright (c) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "overheat.h"
|
||||
|
||||
/* Read a CSV from the stdin in the format
|
||||
* <time_in_seconds> <state> <temp_in_C>
|
||||
* skipping the first row (header).
|
||||
*
|
||||
* Outputs overheat state. */
|
||||
|
||||
#define MAX_LINE 1024
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[MAX_LINE];
|
||||
fgets(buf, MAX_LINE, stdin);
|
||||
|
||||
float t, temp;
|
||||
int st;
|
||||
|
||||
struct overheat ovh;
|
||||
overheat_init(&ovh);
|
||||
|
||||
while (scanf("%f %d %f", &t, &st, &temp) == 3) {
|
||||
|
||||
overheat_input(&ovh, t * 1000.0, temp);
|
||||
float delta = overheat_delta(&ovh);
|
||||
int panic = overheat_panic(&ovh);
|
||||
|
||||
printf("%.3f %d %.2f %.1f %s\n", t, st, temp, delta, panic ? "PANIC" : "OK");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user