Helpers.cpp 814 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "Helpers.h"
  2. char *get_basename(const char *path) {
  3. const char *base = path;
  4. while (*path) {
  5. if (*path++ == '/') {
  6. base = path;
  7. }
  8. }
  9. return (char *) base;
  10. }
  11. void check_ptr(void *p, const char *file, int line, const char *func) {
  12. UNUSED(file);
  13. UNUSED(line);
  14. UNUSED(func);
  15. if (p == NULL) {
  16. FURI_LOG_W("App", "[NULLPTR] %s:%s():%i", get_basename((char *) file), func, line);
  17. }
  18. }
  19. float lerp(float a, float b, float t) {
  20. if (t > 1) return b;
  21. return (1 - t) * a + t * b;
  22. }
  23. LogTimer::LogTimer(const char *n) : name(n) {
  24. start = furi_get_tick();
  25. }
  26. LogTimer::~LogTimer() {
  27. FURI_LOG_D("App", "%s took %fms", name, furi_get_tick() - start);
  28. }
  29. float inverse_tanh(double x) {
  30. return 0.5f * (float)log((1 + x) / (1 - x));
  31. }