]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/scale/scale_rptparser.cpp
1 /* Parser for standard HID scale (usage page 0x8d) data input report (ID 3) */
2 #include "scale_rptparser.h"
4 const char* UNITS
[13] = {
5 "units", // unknown unit
13 "tonnes", // metric tons
20 ScaleReportParser::ScaleReportParser(ScaleEvents
*evt
) :
24 void ScaleReportParser::Parse(HID
*hid
, bool is_rpt_id
, uint8_t len
, uint8_t *buf
)
28 // Checking if there are changes in report since the method was last called
29 for (uint8_t i
=0; i
<RPT_SCALE_LEN
; i
++) {
30 if( buf
[i
] != oldScale
[i
] ) {
35 // Calling Game Pad event handler
36 if (!match
&& scaleEvents
) {
37 scaleEvents
->OnScaleChanged((const ScaleEventData
*)buf
);
39 for (uint8_t i
=0; i
<RPT_SCALE_LEN
; i
++) oldScale
[i
] = buf
[i
];
43 ScaleEvents::ScaleEvents( Max_LCD
* pLCD
) :
49 void ScaleEvents::LcdPrint( const char* str
)
54 pLcd
->write( *str
++ );
59 void ScaleEvents::OnScaleChanged(const ScaleEventData
*evt
)
66 if( evt
->reportID
!= 3 ) {
68 const char inv_report
[]="Invalid report!";
70 Serial
.println(inv_report
);
75 }//if( evt->reportID != 3...
77 switch( evt
->status
) {
80 Serial
.println(F("Report fault"));
84 Serial
.println(F("Scale zero set"));
89 const char progress
[] = "Weighing...";
90 Serial
.println(progress
);
98 double weight
= evt
->weight
* pow( 10, evt
->exp
);
102 Serial
.print(F("Weight: "));
103 Serial
.print( weight
);
104 Serial
.print(F(" "));
105 Serial
.println( UNITS
[ evt
->unit
]);
107 LcdPrint("Weight: ");
108 dtostrf( weight
, 4, 2, buf
);
110 LcdPrint( UNITS
[ evt
->unit
]);
114 }//case WEIGHT_VALID...
116 case WEIGHT_NEGATIVE
: {
118 const char negweight
[] = "Negative weight";
119 Serial
.println(negweight
);
126 const char overweight
[] = "Max.weight reached";
127 Serial
.println(overweight
);
128 LcdPrint( overweight
);
134 Serial
.println(F("Scale calibration required"));
139 Serial
.println(F("Scale zeroing required"));
144 Serial
.print(F("Undefined status code: "));
145 Serial
.println( evt
->status
);
148 }//switch( evt->status...