Cutter Power in percent format (#20410)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Co-authored-by: Jason Smith <jason.inet@gmail.com>
Co-authored-by: Luu Lac <45380455+shitcreek@users.noreply.github.com>
This commit is contained in:
Mike La Spina
2020-12-23 22:50:24 -06:00
committed by GitHub
parent 820cc69d0a
commit 1fc0dcdc97
6 changed files with 33 additions and 12 deletions

View File

@ -34,16 +34,20 @@ char conv[8] = { 0 };
#define INTFLOAT(V,N) (((V) * 10 * pow(10, N) + ((V) < 0 ? -5: 5)) / 10) // pow10?
#define UINTFLOAT(V,N) INTFLOAT((V) < 0 ? -(V) : (V), N)
// Convert a full-range unsigned 8bit int to a percentage
const char* ui8tostr4pctrj(const uint8_t i) {
const uint8_t n = ui8_to_percent(i);
conv[3] = RJDIGIT(n, 100);
conv[4] = RJDIGIT(n, 10);
conv[5] = DIGIMOD(n, 1);
// Format uint8_t (0-100) as rj string with 123% / _12% / __1% format
const char* pcttostrpctrj(const uint8_t i) {
conv[3] = RJDIGIT(i, 100);
conv[4] = RJDIGIT(i, 10);
conv[5] = DIGIMOD(i, 1);
conv[6] = '%';
return &conv[3];
}
// Convert uint8_t (0-255) to a percentage, format as above
const char* ui8tostr4pctrj(const uint8_t i) {
return pcttostrpctrj(ui8_to_percent(i));
}
// Convert unsigned 8bit int to string 123 format
const char* ui8tostr3rj(const uint8_t i) {
conv[4] = RJDIGIT(i, 100);

View File

@ -23,7 +23,10 @@
#include <stdint.h>
// Convert a full-range unsigned 8bit int to a percentage
// Format uint8_t (0-100) as rj string with 123% / _12% / __1% format
const char* pcttostrpctrj(const uint8_t i);
// Convert uint8_t (0-255) to a percentage, format as above
const char* ui8tostr4pctrj(const uint8_t i);
// Convert uint8_t to string with 12 format