Typica is a free program for professional coffee roasters. https://typica.us
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.

scale.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*869:*/
  2. #line 131 "./scales.w"
  3. #include "scale.h"
  4. #include <QStringList>
  5. SerialScale::SerialScale(const QString&port):
  6. QextSerialPort(port,QextSerialPort::EventDriven)
  7. {
  8. connect(this,SIGNAL(readyRead()),this,SLOT(dataAvailable()));
  9. }
  10. /*:869*//*870:*/
  11. #line 149 "./scales.w"
  12. void SerialScale::dataAvailable()
  13. {
  14. responseBuffer.append(readAll());
  15. if(responseBuffer.contains("\x0D"))
  16. {
  17. if(responseBuffer.contains("!"))
  18. {
  19. responseBuffer.clear();
  20. }
  21. else
  22. {
  23. /*871:*/
  24. #line 189 "./scales.w"
  25. QStringList responseParts= QString(responseBuffer.simplified()).split(' ');
  26. if(responseParts.size()> 2)
  27. {
  28. responseParts.removeFirst();
  29. responseParts.replace(0,QString("-%1").arg(responseParts[0]));
  30. }
  31. double weight= responseParts[0].toDouble();
  32. Units::Unit unit= Units::Unitless;
  33. if(responseParts[1]=="lb")
  34. {
  35. unit= Units::Pound;
  36. }
  37. else if(responseParts[1]=="kg")
  38. {
  39. unit= Units::Kilogram;
  40. }
  41. else if(responseParts[1]=="g")
  42. {
  43. unit= Units::Gram;
  44. }
  45. else if(responseParts[1]=="oz")
  46. {
  47. unit= Units::Ounce;
  48. }
  49. emit newMeasurement(weight,unit);
  50. /*:871*/
  51. #line 161 "./scales.w"
  52. responseBuffer.clear();
  53. }
  54. }
  55. }
  56. /*:870*//*872:*/
  57. #line 220 "./scales.w"
  58. void SerialScale::tare()
  59. {
  60. write("!KT\x0D");
  61. }
  62. void SerialScale::weigh()
  63. {
  64. write("!KP\x0D");
  65. }
  66. /*:872*/