la10compat.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "la10compat.h"
  2. #include "Marlin.h"
  3. static LA10C_MODE la10c_mode = LA10C_UNKNOWN;
  4. void la10c_mode_change(LA10C_MODE mode)
  5. {
  6. if(mode == la10c_mode) return;
  7. SERIAL_ECHOPGM("LA10C: Linear Advance mode: ");
  8. switch(mode)
  9. {
  10. case LA10C_UNKNOWN: SERIAL_ECHOLNPGM("UNKNOWN"); break;
  11. case LA10C_LA15: SERIAL_ECHOLNPGM("1.5"); break;
  12. case LA10C_LA10: SERIAL_ECHOLNPGM("1.0"); break;
  13. }
  14. la10c_mode = mode;
  15. }
  16. // Approximate a LA10 value to a LA15 equivalent.
  17. static float la10c_convert(float k)
  18. {
  19. float new_K = k * 0.004 - 0.06;
  20. return (new_K < 0? 0: new_K);
  21. }
  22. float la10c_value(float k)
  23. {
  24. if(la10c_mode == LA10C_UNKNOWN)
  25. {
  26. // do not autodetect until a valid value is seen
  27. if(k == 0)
  28. return 0;
  29. else if(k < 0)
  30. return -1;
  31. la10c_mode_change(k < 10? LA10C_LA15: LA10C_LA10);
  32. }
  33. if(la10c_mode == LA10C_LA15)
  34. return (k >= 0 && k < 10? k: -1);
  35. else
  36. return (k >= 0? la10c_convert(k): -1);
  37. }