Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int spline_battery_level(const int p[], const int v[], const size_t size, uint16

// if not last
if (i < size - 1 && voltage >= v[i + 1]) {
percent = p[i + 1] + (voltage - v[i + 1]) / (v[i] - v[i + 1]) * (p[i] - p[i + 1]);
percent = p[i + 1] + (float)(voltage - v[i + 1]) / (float)(v[i] - v[i + 1]) * (p[i] - p[i + 1]);
break;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ unsigned int round_to_multiples(unsigned int number, unsigned int multiple);
/**
* @brief This function calculates the estimate batttery level in percent using splines.
*
* Example:
* @code{.c}
* static const int battery_estimate_percentages[] = { 100, 50, 30, 20, 5, 0 };
* static const int battery_estimate_voltages[] = { 4175, 3817, 3766, 3730, 3664, 3310 };
* static size_t battery_estimate_size = sizeof(battery_estimate_percentages)/sizeof(battery_estimate_percentages[0]);
* int level = spline_battery_level(battery_estimate_percentages, battery_estimate_voltages, battery_estimate_size, voltage_read);
* @endcode
*
* @param p percentage values to be associated with voltage values
* @param v voltage values associated with percentage values
* @param size number of percentage and voltage associations
Expand Down