Skip to content

Commit d36c050

Browse files
committed
feat: implement interactive CLI for libectool testing
1 parent 6a1aa54 commit d36c050

File tree

1 file changed

+61
-20
lines changed

1 file changed

+61
-20
lines changed

tests/test_libectool.c

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,68 @@
11
#include <stdio.h>
2+
#include <stdbool.h>
23
#include "libectool.h"
34

4-
int main() {
5-
printf("Testing libectool...\n");
6-
7-
// Test is_on_ac
8-
bool ac = is_on_ac();
9-
printf("is_on_ac() = %d\n", ac);
10-
11-
// // Test fan control functions
12-
// printf("Pausing fan control...\n");
13-
// pause_fan_control();
14-
15-
// printf("Setting fan speed to 50%%...\n");
16-
// set_fan_speed(50);
5+
void print_menu() {
6+
printf("\n=== libectool Testing CLI ===\n");
7+
printf("1. Check if on AC power\n");
8+
printf("2. Pause fan control\n");
9+
printf("3. Set fan speed\n");
10+
printf("4. Get max temperature\n");
11+
printf("5. Get max non-battery temperature\n");
12+
printf("0. Exit\n");
13+
printf("Choose an option: ");
14+
}
1715

18-
// Test temperature functions
19-
float max_temp = get_max_temperature();
20-
printf("Max temperature = %.2f C\n", max_temp);
16+
int main() {
17+
int choice;
18+
int speed;
2119

22-
float max_non_batt_temp = get_max_non_battery_temperature();
23-
printf("Max non-battery temperature = %.2f C\n", max_non_batt_temp);
20+
while (1) {
21+
print_menu();
22+
if (scanf("%d", &choice) != 1) {
23+
// clear invalid input
24+
int c;
25+
while ((c = getchar()) != '\n' && c != EOF);
26+
printf("Invalid input. Try again.\n");
27+
continue;
28+
}
2429

25-
printf("Test complete.\n");
26-
return 0;
30+
switch (choice) {
31+
case 1: {
32+
bool ac = is_on_ac();
33+
printf("is_on_ac() = %d\n", ac);
34+
break;
35+
}
36+
case 2:
37+
printf("Pausing fan control...\n");
38+
pause_fan_control();
39+
break;
40+
case 3:
41+
printf("Enter fan speed (0-100): ");
42+
if (scanf("%d", &speed) == 1) {
43+
set_fan_speed(speed);
44+
} else {
45+
printf("Invalid speed.\n");
46+
// clear invalid input
47+
int c;
48+
while ((c = getchar()) != '\n' && c != EOF);
49+
}
50+
break;
51+
case 4: {
52+
float max_temp = get_max_temperature();
53+
printf("Max temperature = %.2f C\n", max_temp);
54+
break;
55+
}
56+
case 5: {
57+
float max_non_batt_temp = get_max_non_battery_temperature();
58+
printf("Max non-battery temperature = %.2f C\n", max_non_batt_temp);
59+
break;
60+
}
61+
case 0:
62+
printf("Exiting.\n");
63+
return 0;
64+
default:
65+
printf("Invalid choice. Try again.\n");
66+
}
67+
}
2768
}

0 commit comments

Comments
 (0)