Skip to content

Commit 9da0cdc

Browse files
author
AhmedYasserrr
committed
refactor: implement libectool library with core functionality and testing
1 parent 7b3959b commit 9da0cdc

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build ectool
33

44
on:
55
push:
6-
branches: [ main ]
6+
branches: [main, dev]
77
pull_request:
88

99
jobs:
@@ -52,4 +52,4 @@ jobs:
5252
name: ectool-linux
5353
path: |
5454
_build/src/core/ectool
55-
_build/src/core/libectool.so
55+
_build/src/core/libectool.so

src/core/ectool_wrapper.cc renamed to src/core/libectool.cc

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdlib.h>
33
#include <string.h>
44

5+
#include "libectool.h"
56
#include "battery.h"
67
#include "comm-host.h"
78
#include "comm-usb.h"
@@ -11,7 +12,6 @@
1112
#include "ec_panicinfo.h"
1213
#include "ec_flash.h"
1314
#include "ec_version.h"
14-
// #include "ectool.h"
1515
#include "i2c.h"
1616
#include "lightbar.h"
1717
#include "lock/gec_lock.h"
@@ -30,21 +30,9 @@
3030
#define GEC_LOCK_TIMEOUT_SECS 30 /* 30 secs */
3131
#define interfaces COMM_ALL
3232

33-
int libectool_init();
34-
void libectool_release();
35-
int read_mapped_temperature(int id);
36-
static uint8_t read_mapped_mem8(uint8_t offset);
37-
38-
39-
extern "C" {
40-
int ascii_mode = 0;
41-
bool is_on_ac();
42-
void pause_fan_control();
43-
void set_fan_speed(int speed);
44-
float get_max_temperature();
45-
float get_max_non_battery_temperature();
46-
47-
33+
// int read_mapped_temperature(int id);
34+
// static uint8_t read_mapped_mem8(uint8_t offset);
35+
// int ascii_mode;
4836

4937
// -----------------------------------------------------------------------------
5038
// Top-level endpoint functions

src/core/libectool.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef LIBECTOOL_H
2+
#define LIBECTOOL_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
// Library init/release
9+
int libectool_init();
10+
void libectool_release();
11+
12+
// API functions to expose
13+
bool is_on_ac();
14+
void pause_fan_control();
15+
void set_fan_speed(int speed);
16+
float get_max_temperature();
17+
float get_max_non_battery_temperature();
18+
19+
#ifdef __cplusplus
20+
}
21+
#endif
22+
23+
#endif // LIBECTOOL_H

tests/test_libectool.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include "libectool.h"
3+
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);
17+
18+
// Test temperature functions
19+
float max_temp = get_max_temperature();
20+
printf("Max temperature = %.2f C\n", max_temp);
21+
22+
float max_non_batt_temp = get_max_non_battery_temperature();
23+
printf("Max non-battery temperature = %.2f C\n", max_non_batt_temp);
24+
25+
printf("Test complete.\n");
26+
return 0;
27+
}

0 commit comments

Comments
 (0)