Arnaud VALLEY / Mbed 2 deprecated Pinscape_Controller_V2_arnoz

Dependencies:   mbed FastIO FastPWM USBDevice

Revision:
52:8298b2a73eb2
Parent:
48:058ace2aed1d
Child:
53:9b2611964afc
--- a/USBJoystick/USBJoystick.cpp	Tue Mar 01 23:21:45 2016 +0000
+++ b/USBJoystick/USBJoystick.cpp	Sat Mar 05 00:16:52 2016 +0000
@@ -94,7 +94,58 @@
     return writeTO(EP4IN, report.data, report.length, MAX_PACKET_SIZE_EPINT, 100);
 }
  
-bool USBJoystick::updateExposure(int &idx, int npix, const uint8_t *pix)
+bool USBJoystick::sendPlungerStatus(
+    int npix, int edgePos, int dir, uint32_t avgScanTime, uint32_t processingTime)
+{
+    HID_REPORT report;
+    
+    // Set the special status bits to indicate it's an extended
+    // exposure report.
+    put(0, 0x87FF);
+    
+    // start at the second byte
+    int ofs = 2;
+    
+    // write the report subtype (0) to byte 2
+    report.data[ofs++] = 0;
+
+    // write the number of pixels to bytes 3-4
+    put(ofs, uint16_t(npix));
+    ofs += 2;
+    
+    // write the shadow edge position to bytes 5-6
+    put(ofs, uint16_t(edgePos));
+    ofs += 2;
+    
+    // write the flags to byte 7
+    extern bool plungerCalMode;
+    uint8_t flags = 0;
+    if (dir == 1) 
+        flags |= 0x01; 
+    else if (dir == -1)
+        flags |= 0x02;
+    if (plungerCalMode)
+        flags |= 0x04;
+    report.data[ofs++] = flags;
+    
+    // write the average scan time in 10us intervals to bytes 8-10
+    uint32_t t = uint32_t(avgScanTime / 10);
+    report.data[ofs++] = t & 0xff;
+    report.data[ofs++] = (t >> 8) & 0xff;
+    report.data[ofs++] = (t >> 16) & 0xff;
+    
+    // write the processing time to bytes 11-13
+    t = uint32_t(processingTime / 10);
+    report.data[ofs++] = t & 0xff;
+    report.data[ofs++] = (t >> 8) & 0xff;
+    report.data[ofs++] = (t >> 16) & 0xff;
+    
+    // send the report
+    report.length = reportLen;
+    return sendTO(&report, 100);
+}
+
+bool USBJoystick::sendPlungerPix(int &idx, int npix, const uint8_t *pix)
 {
     HID_REPORT report;
     
@@ -107,13 +158,6 @@
     // start at the second byte
     int ofs = 2;
     
-    // in the first report, add the total pixel count as the next two bytes
-    if (idx == 0)
-    {
-        put(ofs, npix);
-        ofs += 2;
-    }
-        
     // now fill out the remaining bytes with exposure values
     report.length = reportLen;
     for ( ; ofs < report.length ; ++ofs)
@@ -123,50 +167,6 @@
     return sendTO(&report, 100);
 }
 
-bool USBJoystick::updateExposureExt(
-    int edgePos, int dir, uint32_t avgScanTime, uint32_t processingTime)
-{
-    HID_REPORT report;
-    
-    // Set the special status bits to indicate it's an extended
-    // exposure report.
-    put(0, 0x87FF);
-    
-    // start at the second byte
-    int ofs = 2;
-    
-    // write the report subtype (0) to byte 2
-    report.data[ofs++] = 0;
-    
-    // write the shadow edge position to bytes 3-4
-    put(ofs, uint16_t(edgePos));
-    ofs += 2;
-    
-    // write the flags to byte 5:
-    //   0x01 -> standard orientation detected (dir == 1)
-    //   0x02 -> reverse orientation detected (dir == -1)
-    uint8_t flags = 0;
-    if (dir == 1) flags |= 0x01;
-    if (dir == -1) flags |= 0x02;
-    report.data[ofs++] = flags;
-    
-    // write the average scan time in 10us intervals to bytes 6-8
-    uint32_t t = uint32_t(avgScanTime / 10);
-    report.data[ofs++] = t & 0xff;
-    report.data[ofs++] = (t >> 8) & 0xff;
-    report.data[ofs++] = (t >> 16) & 0xff;
-    
-    // write the processing time to bytes 9-11
-    t = uint32_t(processingTime / 10);
-    report.data[ofs++] = t & 0xff;
-    report.data[ofs++] = (t >> 8) & 0xff;
-    report.data[ofs++] = (t >> 16) & 0xff;
-    
-    // send the report
-    report.length = reportLen;
-    return sendTO(&report, 100);
-}
-
 
 bool USBJoystick::reportID()
 {
@@ -189,7 +189,30 @@
     return sendTO(&report, 100);
 }
 
-bool USBJoystick::reportConfig(int numOutputs, int unitNo, int plungerZero, int plungerMax, bool configured)
+bool USBJoystick::reportConfigVar(const uint8_t *data)
+{
+    HID_REPORT report;
+
+    // initially fill the report with zeros
+    memset(report.data, 0, sizeof(report.data));
+    
+    // Set the special status bits to indicate that it's a config 
+    // variable report
+    uint16_t s = 0x9800;
+    put(0, s);
+    
+    // Copy the variable data (7 bytes, starting with the variable ID)
+    memcpy(report.data + 2, data, 7);
+    
+    // send the report
+    report.length = reportLen;
+    return sendTO(&report, 100);
+}
+
+bool USBJoystick::reportConfig(
+    int numOutputs, int unitNo, 
+    int plungerZero, int plungerMax, int plungerRlsTime,
+    bool configured)
 {
     HID_REPORT report;
 
@@ -209,10 +232,11 @@
     // write the plunger zero and max values
     put(6, plungerZero);
     put(8, plungerMax);
+    report.data[10] = uint8_t(plungerRlsTime);
     
     // write the status bits: 
     //  0x01  -> configuration loaded
-    report.data[10] = (configured ? 0x01 : 0x00);
+    report.data[11] = (configured ? 0x01 : 0x00);
     
     // send the report
     report.length = reportLen;