initial attempt to implement a feedhold.
[clinton/Smoothieware.git] / src / libs / USBDevice / USBSerial / USBSerial.cpp
index 8bdba9b..cd7ab1f 100644 (file)
@@ -137,8 +137,11 @@ bool USBSerial::USBEvent_EPIn(uint8_t bEP, uint8_t bEPStatus)
 
     int l = txbuf.available();
     if (l > 0) {
-        if (l > MAX_PACKET_SIZE_EPBULK)
-            l = MAX_PACKET_SIZE_EPBULK;
+        // Use MAX_PACKET_SIZE_EPBULK-1 below instead of MAX_PACKET_SIZE_EPBULK
+        // to work around a problem sending packets that are exactly MAX_PACKET_SIZE_EPBULK
+        // bytes in length. The problem is that these packets don't flush properly.
+        if (l > MAX_PACKET_SIZE_EPBULK-1)
+            l = MAX_PACKET_SIZE_EPBULK-1;
         int i;
         for (i = 0; i < l; i++) {
             txbuf.dequeue(&b[i]);
@@ -177,8 +180,15 @@ bool USBSerial::USBEvent_EPOut(uint8_t bEP, uint8_t bEPStatus)
     readEP(c, &size);
     iprintf("Read %ld bytes:\n\t", size);
     for (uint8_t i = 0; i < size; i++) {
+
+        // handle backspace and delete by deleting the last character in the buffer if there is one
+        if(c[i] == 0x08 || c[i] == 0x7F) {
+            if(!rxbuf.isEmpty()) rxbuf.pop();
+            continue;
+        }
+
         if(c[i] == 'X' - 'A' + 1) { // ^X
-            THEKERNEL->set_feed_hold(false); // required to free stuff up
+            //THEKERNEL->set_feed_hold(false); // required to free stuff up
             halt_flag = true;
             continue;
         }
@@ -198,10 +208,6 @@ bool USBSerial::USBEvent_EPOut(uint8_t bEP, uint8_t bEPStatus)
                 THEKERNEL->set_feed_hold(false);
                 continue;
             }
-            if(last_char_was_dollar && (c[i] == 'X' || c[i] == 'H')) {
-                // we need to do this otherwise $X/$H won't work if there was a feed hold like when stop is clicked in bCNC
-                THEKERNEL->set_feed_hold(false);
-            }
         }
 
         last_char_was_dollar = (c[i] == '$');
@@ -273,7 +279,7 @@ void USBSerial::on_idle(void *argument)
         halt_flag = false;
         THEKERNEL->call_event(ON_HALT, nullptr);
         if(THEKERNEL->is_grbl_mode()) {
-            puts("ALARM:Abort during cycle\r\n");
+            puts("ALARM: Abort during cycle\r\n");
         } else {
             puts("HALTED, M999 or $X to exit HALT state\r\n");
         }
@@ -309,7 +315,7 @@ void USBSerial::on_main_loop(void *argument)
     }
 
     // if we are in feed hold we do not process anything
-    if(THEKERNEL->get_feed_hold()) return;
+    //if(THEKERNEL->get_feed_hold()) return;
 
     if (nl_in_rx) {
         string received;