You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "Helpers.h"
  4. #include "Logs.h"
  5. void Helpers::tempToStr(
  6. char* out
  7. , temp_t temp
  8. , signed char width
  9. )
  10. {
  11. LOG_FN_BEGIN(2);
  12. LOG(5, "%s: temp=%i", __FUNCTION__, (int) temp);
  13. if (temp == TEMP_T_INVALID)
  14. {
  15. for (int i = 0; i < width - 4; ++i)
  16. {
  17. out[i] = ' ';
  18. }
  19. strcpy(&out[width - 4], "--.-");
  20. }
  21. else
  22. {
  23. dtostrf((float) temp / 10.0f, width, 1, out);
  24. }
  25. LOG_FN_END(2);
  26. }
  27. void Helpers::fillLine(
  28. char* line
  29. , int length
  30. , char c
  31. )
  32. {
  33. int i = 0;
  34. while (line[i] && i < length)
  35. {
  36. ++i;
  37. }
  38. while (i < length)
  39. {
  40. line[i] = c;
  41. ++i;
  42. }
  43. line[length] = 0;
  44. }
  45. void Helpers::center(
  46. char* line
  47. , const char* text
  48. , int length
  49. , char c
  50. )
  51. {
  52. auto cCount = (length - strlen(text)) / 2;
  53. for (int i = 0; i < cCount; ++i)
  54. {
  55. line[i] = c;
  56. }
  57. strcpy(&line[cCount], text);
  58. fillLine(line, length, c);
  59. }