Ver código fonte

cmd queue and planner - functions for calculating sd position:
cmdqueue_calc_sd_length
planner_calc_sd_length

Robert Pelnar 6 anos atrás
pai
commit
c4e9e624f5
4 arquivos alterados com 42 adições e 4 exclusões
  1. 17 0
      Firmware/cmdqueue.cpp
  2. 1 0
      Firmware/cmdqueue.h
  3. 18 2
      Firmware/planner.cpp
  4. 6 2
      Firmware/planner.h

+ 17 - 0
Firmware/cmdqueue.cpp

@@ -601,3 +601,20 @@ void get_command()
 
   #endif //SDSUPPORT
 }
+
+uint16_t cmdqueue_calc_sd_length()
+{
+	int _buflen = buflen;
+	int _bufindr = bufindr;
+	uint16_t sdlen = 0;
+	while (_buflen--)
+	{
+		if (cmdbuffer[_bufindr] == CMDBUFFER_CURRENT_TYPE_SDCARD)
+			sdlen += cmdbuffer[_bufindr + 1];
+		//skip header, skip command
+		for (_bufindr += CMDHDRSIZE; cmdbuffer[_bufindr] != 0; ++ _bufindr) ;
+		//skip zeros
+		for (++ _bufindr; _bufindr < sizeof(cmdbuffer) && cmdbuffer[_bufindr] == 0; ++ _bufindr) ;
+	}
+    return sdlen;
+}

+ 1 - 0
Firmware/cmdqueue.h

@@ -62,6 +62,7 @@ extern void enquecommand_front(const char *cmd, bool from_progmem);
 extern void repeatcommand_front();
 extern bool is_buffer_empty();
 extern void get_command();
+extern uint16_t cmdqueue_calc_sd_length();
 
 // Return True if a character was found
 static inline bool    code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }

+ 18 - 2
Firmware/planner.cpp

@@ -593,7 +593,7 @@ float junction_deviation = 0.1;
 // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in 
 // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
 // calculation the caller must also provide the physical length of the line in millimeters.
-void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder)
+void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder, uint8_t sdlen)
 {
     // Calculate the buffer head after we push this byte
   int next_buffer_head = next_block_index(block_buffer_head);
@@ -723,6 +723,9 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
   // Prepare to set up new block
   block_t *block = &block_buffer[block_buffer_head];
 
+  // Set sdlen for calculating sd position
+  block->sdlen = sdlen;
+
   // Mark block as not busy (Not executed by the stepper interrupt, could be still tinkered with.)
   block->busy = false;
 
@@ -1295,4 +1298,17 @@ void planner_queue_min_reset()
 {
   g_cntr_planner_queue_min = moves_planned();
 }
-#endif /* PLANNER_DIAGNOSTICS */
+#endif /* PLANNER_DIAGNOSTICS */
+
+uint16_t planner_calc_sd_length()
+{
+	unsigned char _block_buffer_head = block_buffer_head;
+	unsigned char _block_buffer_tail = block_buffer_tail;
+	uint16_t sdlen = 0;
+	while (_block_buffer_head != _block_buffer_tail)
+	{
+		sdlen += block_buffer[_block_buffer_tail].sdlen;
+	    _block_buffer_tail = (_block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1);  
+	}
+	return sdlen;
+}

+ 6 - 2
Firmware/planner.h

@@ -93,6 +93,8 @@ typedef struct {
   bool use_advance_lead;
   unsigned long abs_adv_steps_multiplier8; // Factorised by 2^8 to avoid float
 #endif
+
+  uint8_t sdlen;
 } block_t;
 
 #ifdef LIN_ADVANCE
@@ -111,12 +113,12 @@ void plan_init();
 // millimaters. Feed rate specifies the speed of the motion.
 
 #ifdef ENABLE_AUTO_BED_LEVELING
-void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
+void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder, uint8_t sdlen = 0);
 
 // Get the position applying the bed level matrix if enabled
 vector_3 plan_get_position();
 #else
-void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder);
+void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate, const uint8_t &extruder, uint8_t sdlen = 0);
 //void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
 #endif // ENABLE_AUTO_BED_LEVELING
 
@@ -217,3 +219,5 @@ extern uint8_t planner_queue_min();
 // Diagnostic function: Reset the minimum planner segments.
 extern void planner_queue_min_reset();
 #endif /* PLANNER_DIAGNOSTICS */
+
+extern uint16_t planner_calc_sd_length();