@@ -10,12 +10,30 @@ void ECController::handle_error(int code, const std::string &msg) {
1010 case EC_ERR_READMEM: reason = " EC memory read failed" ; break ;
1111 case EC_ERR_EC_COMMAND: reason = " EC command failed" ; break ;
1212 case EC_ERR_INVALID_PARAM: reason = " Invalid parameter" ; break ;
13+ case EC_ERR_SENSOR_UNAVAILABLE:
14+ reason = " Sensor unavailable or not calibrated/powered" ;
15+ break ;
16+ case EC_ERR_UNSUPPORTED_VER:
17+ reason = " Unsupported EC command version" ;
18+ break ;
19+
20+ case EC_ERR_INVALID_RESPONSE:
21+ reason = " Invalid response from EC" ;
22+ break ;
1323 default : reason = " Unknown error" ; break ;
1424 }
1525
1626 throw std::runtime_error (msg + " (" + reason + " , code " + std::to_string (code) + " )" );
1727}
1828
29+ int ECController::hello () {
30+ int ret = ec_hello ();
31+ return ret;
32+ }
33+
34+ // -----------------------------------------------------------------------------
35+ // Top-level Power Functions
36+ // -----------------------------------------------------------------------------
1937
2038bool ECController::is_on_ac () {
2139 int ac;
@@ -24,26 +42,116 @@ bool ECController::is_on_ac() {
2442 return ac;
2543}
2644
27- void ECController::auto_fan_control () {
28- int ret = ec_auto_fan_control ();
45+ ec_charge_state_info ECController::get_charge_state () {
46+ ec_charge_state_info info;
47+ int ret = ec_get_charge_state (&info);
48+ handle_error (ret, " Failed to get charge state" );
49+ return info;
50+ }
51+
52+ // -----------------------------------------------------------------------------
53+ // Top-level fan control Functions
54+ // -----------------------------------------------------------------------------
55+
56+ int ECController::get_num_fans () {
57+ int val = 0 ;
58+ int ret = ec_get_num_fans (&val);
59+ handle_error (ret, " Failed to get number of fans" );
60+ return val;
61+ }
62+
63+ void ECController::enable_fan_auto_ctrl (int fan_idx) {
64+ int ret = ec_enable_fan_auto_ctrl (fan_idx);
2965 handle_error (ret, " Failed to enable auto fan control" );
3066}
3167
32- void ECController::set_fan_duty (int duty) {
33- int ret = ec_set_fan_duty (duty);
68+ void ECController::enable_all_fans_auto_ctrl () {
69+ int ret = ec_enable_all_fans_auto_ctrl ();
70+ handle_error (ret, " Failed to enable auto control for all fans" );
71+ }
72+
73+ void ECController::set_fan_duty (int percent, int fan_idx) {
74+ int ret = ec_set_fan_duty (percent, fan_idx);
3475 handle_error (ret, " Failed to set fan duty" );
3576}
3677
37- float ECController::get_max_temperature () {
38- float t;
39- int ret = ec_get_max_temperature (&t);
78+ void ECController::set_all_fans_duty (int percent) {
79+ int ret = ec_set_all_fans_duty (percent);
80+ handle_error (ret, " Failed to set duty for all fans" );
81+ }
82+
83+ void ECController::set_fan_rpm (int target_rpm, int fan_idx) {
84+ int ret = ec_set_fan_rpm (target_rpm, fan_idx);
85+ handle_error (ret, " Failed to set fan RPM" );
86+ }
87+
88+ void ECController::set_all_fans_rpm (int target_rpm) {
89+ int ret = ec_set_all_fans_rpm (target_rpm);
90+ handle_error (ret, " Failed to set RPM for all fans" );
91+ }
92+
93+ int ECController::get_fan_rpm (int fan_idx) {
94+ int rpm = 0 ;
95+ int ret = ec_get_fan_rpm (&rpm, fan_idx);
96+ handle_error (ret, " Failed to get fan RPM" );
97+ return rpm;
98+ }
99+
100+ std::vector<int > ECController::get_all_fans_rpm () {
101+ int num_fans = get_num_fans ();
102+ std::vector<int > rpms (num_fans);
103+ int num_fans_out = 0 ;
104+
105+ int ret = ec_get_all_fans_rpm (rpms.data (), num_fans, &num_fans_out);
106+ handle_error (ret, " Failed to get all fan RPMs" );
107+ return rpms;
108+ }
109+
110+ // -----------------------------------------------------------------------------
111+ // Top-level temperature Functions
112+ // -----------------------------------------------------------------------------
113+ int ECController::get_num_temp_sensors () {
114+ int val = 0 ;
115+ int ret = ec_get_num_temp_sensors (&val);
116+ handle_error (ret, " Failed to get number of temp sensors" );
117+ return val;
118+ }
119+
120+ int ECController::get_temp (int sensor_idx) {
121+ int temp = 0 ;
122+ int ret = ec_get_temp (sensor_idx, &temp);
123+ handle_error (ret, " Failed to get temperature" );
124+ return temp;
125+ }
126+
127+ std::vector<int > ECController::get_all_temps () {
128+ int max_entries = get_num_temp_sensors ();
129+ std::vector<int > temps (max_entries);
130+ int num_sensors = 0 ;
131+
132+ int ret = ec_get_all_temps (temps.data (), max_entries, &num_sensors);
133+ handle_error (ret, " Failed to get all temperatures" );
134+ temps.resize (num_sensors); // Trim unused entries
135+ return temps;
136+ }
137+
138+ int ECController::get_max_temp () {
139+ int temp = 0 ;
140+ int ret = ec_get_max_temp (&temp);
40141 handle_error (ret, " Failed to get max temperature" );
41- return t;
142+ return temp;
143+ }
144+
145+ int ECController::get_max_non_battery_temp () {
146+ int temp = 0 ;
147+ int ret = ec_get_max_non_battery_temp (&temp);
148+ handle_error (ret, " Failed to get max non-battery temperature" );
149+ return temp;
42150}
43151
44- float ECController::get_max_non_battery_temperature ( ) {
45- float t ;
46- int ret = ec_get_max_non_battery_temperature (&t );
47- handle_error (ret, " Failed to get non-battery temperature " );
48- return t ;
152+ ec_temp_info ECController::get_temp_info ( int sensor_idx ) {
153+ ec_temp_info info ;
154+ int ret = ec_get_temp_info (sensor_idx, &info );
155+ handle_error (ret, " Failed to get temp sensor info " );
156+ return info ;
49157}
0 commit comments