Initialize structs
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 28 Aug 2016 06:20:23 +0000 (23:20 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 28 Aug 2016 06:20:23 +0000 (23:20 -0700)
14 files changed:
src/command.c
src/hardware.c
src/homing.c
src/huanyang.c
src/machine.c
src/machine.h
src/plan/arc.c
src/plan/calibrate.c
src/plan/exec.c
src/plan/line.c
src/plan/planner.c
src/probing.c
src/stepper.c
src/tmc2660.c

index 21c467989d562edd99f40acb34f240fc8d54e6ef..9fe4ef1ec4eef9770ed1440c6aea588e5cf0d773 100644 (file)
@@ -160,7 +160,7 @@ int command_parser(char *cmd) {
   // Parse line
   char *p = cmd + 1; // Skip `$`
   int argc = 0;
-  char *argv[MAX_ARGS] = {};
+  char *argv[MAX_ARGS] = {0};
 
   if (cmd[1] == '$' && !cmd[2]) {
     report_request_full(); // Full report
index f920a6f1b2392f95d4259beb4ef5868a2ddec0b0..d31a382888fdb09653ebe9e17cc2fca815f15493 100644 (file)
@@ -47,7 +47,7 @@ typedef struct {
   bool bootloader;         // flag to enter the bootloader
 } hw_t;
 
-static hw_t hw = {};
+static hw_t hw = {{0}};
 
 
 #define PROD_SIGS (*(NVM_PROD_SIGNATURES_t *)0x0000)
index 30e55dacd8d7f746ac98f646817efca3a8029bd1..ff02ae9d4acf157805b180da2377a4b48e83dff5 100644 (file)
@@ -46,7 +46,7 @@ typedef void (*homing_func_t)(int8_t axis);
 static void _homing_axis_start(int8_t axis);
 
 
-typedef enum {          // applies to mach.homing_state
+typedef enum {
   HOMING_NOT_HOMED,     // machine is not homed
   HOMING_HOMED,         // machine is homed
   HOMING_WAITING,       // machine waiting to be homed
@@ -94,7 +94,7 @@ struct hmHomingSingleton {
 };
 
 
-static struct hmHomingSingleton hm = {0,};
+static struct hmHomingSingleton hm = {0};
 
 
 // G28.2 homing cycle
@@ -201,8 +201,8 @@ static void _homing_error_exit(stat_t status) {
 
 /// helper that actually executes the above moves
 static void _homing_axis_move(int8_t axis, float target, float velocity) {
-  float vect[] = {};
-  float flags[] = {};
+  float vect[AXES] = {0};
+  float flags[AXES] = {0};
 
   vect[axis] = target;
   flags[axis] = true;
index 7ec670825343849f5c29d14483480473459f28c6..7c3e51854378d0bfce2596ba5999f5da157ac2aa 100644 (file)
@@ -132,7 +132,7 @@ typedef struct {
 } huanyang_t;
 
 
-static huanyang_t ha = {};
+static huanyang_t ha = {0};
 
 
 #define CTRL_STATUS_RESPONSE(R) ((uint16_t)R[4] << 8 | R[5])
index 2d5846a5013a1c83b2e0d5bee3fc04a45d55794c..8b86bf50f0780de156b2b8ce81d8d743ce8895d9 100644 (file)
@@ -271,8 +271,7 @@ void mach_set_axis_jerk(uint8_t axis, float jerk) {
  *
  * Functions to get, set and report coordinate systems and work offsets
  * These functions are not part of the NIST defined functions
- */
-/*
+ *
  * Notes on Coordinate System and Offset functions
  *
  * All positional information in the machine is kept as
@@ -482,7 +481,7 @@ void mach_calc_move_time(const float axis_length[], const float axis_square[]) {
     }
   }
 
-  for (uint8_t axis = 0; axis < AXES; axis++) {
+  for (int axis = 0; axis < AXES; axis++) {
     if (mach.gm.motion_mode == MOTION_MODE_STRAIGHT_TRAVERSE)
       tmp_time = fabs(axis_length[axis]) / mach.a[axis].velocity_max;
 
@@ -605,8 +604,8 @@ stat_t mach_test_soft_limits(float target[]) {
 
 void machine_init() {
   // Init 1/jerk
-  for (uint8_t axis = 0; axis < AXES; axis++)
-    mach.a[axis].recip_jerk = 1 / (mach.a[axis].jerk_max * JERK_MULTIPLIER);
+  for (int axis = 0; axis < AXES; axis++)
+    mach_set_axis_jerk(axis, mach.a[axis].jerk_max);
 
   // Set gcode defaults
   mach_set_units_mode(GCODE_DEFAULT_UNITS);
@@ -1130,7 +1129,7 @@ void mach_pallet_change_stop() {
 
 /// M2, M30
 void mach_program_end() {
-  float value[AXES] = {};
+  float value[AXES] = {0};
   mp_queue_command(_exec_program_end, value, value);
 }
 
index 4be3355bed0ec42465f96ddb788aaa15c8427efc..4c5d33f5100c621c72bbc7a4d700d94d7b3e5cea 100644 (file)
@@ -308,8 +308,6 @@ typedef struct { // struct to manage mach globals and cycles
   float g30_position[AXES];            // stored machine position for G30
 
   AxisConfig_t a[AXES];                // settings for axes
-
-  // Model states
   MoveState_t ms;
   GCodeState_t gm;                     // core gcode model state
   GCodeState_t gn;                     // gcode input values
index c4c6bfc36cda5ae1e0fd5341ba2990667299f16b..e97398decff17310ea6e2ec2acb03e6ca33dea0c 100644 (file)
@@ -77,7 +77,7 @@ typedef struct arArcSingleton {     // persistent planner and runtime variables
   MoveState_t ms;
 } arc_t;
 
-arc_t arc = {};
+arc_t arc = {0};
 
 
 /* Returns a naive estimate of arc execution time to inform segment
@@ -101,15 +101,15 @@ static void _estimate_arc_time() {
   } else arc.arc_time = arc.length / mach.gm.feed_rate;
 
   // Downgrade the time if there is a rate-limiting axis
-  arc.arc_time =
-    max(arc.arc_time, arc.planar_travel/mach.a[arc.plane_axis_0].feedrate_max);
-  arc.arc_time =
-    max(arc.arc_time, arc.planar_travel/mach.a[arc.plane_axis_1].feedrate_max);
+  arc.arc_time = max(arc.arc_time,
+                     arc.planar_travel / mach.a[arc.plane_axis_0].feedrate_max);
+  arc.arc_time = max(arc.arc_time,
+                     arc.planar_travel / mach.a[arc.plane_axis_1].feedrate_max);
 
   if (0 < fabs(arc.linear_travel))
     arc.arc_time =
       max(arc.arc_time,
-          fabs(arc.linear_travel/mach.a[arc.linear_axis].feedrate_max));
+          fabs(arc.linear_travel / mach.a[arc.linear_axis].feedrate_max));
 }
 
 
@@ -498,6 +498,4 @@ bool mach_arc_active() {return arc.run_state != MOVE_OFF;}
 
 /// Stop arc movement without maintaining position
 /// OK to call if no arc is running
-void mach_abort_arc() {
-  arc.run_state = MOVE_OFF;
-}
+void mach_abort_arc() {arc.run_state = MOVE_OFF;}
index 01a957728ef13b6e899354b0eb0880c3b48ffa0e..9346b9d7fd6b1f2a583120d1a0fe3d03e1bd40a1 100644 (file)
@@ -73,7 +73,7 @@ typedef struct {
   uint16_t stallguard;
 } calibrate_t;
 
-static calibrate_t cal = {};
+static calibrate_t cal = {0};
 
 
 static stat_t _exec_calibrate(mpBuf_t *bf) {
@@ -130,7 +130,7 @@ static stat_t _exec_calibrate(mpBuf_t *bf) {
   if (!cal.velocity) return STAT_OK;
 
   // Compute travel
-  float travel[AXES] = {}; // In mm
+  float travel[AXES] = {0}; // In mm
   travel[cal.axis] = time * cal.velocity * (cal.reverse ? -1 : 1);
 
   // Convert to steps
index 984120f7229f55e82dbb022ab6b3be268a66672a..9be4d7d4b23d086527aa7c623ba2c37cb2eb3ea0 100644 (file)
@@ -743,7 +743,7 @@ stat_t mp_exec_aline(mpBuf_t *bf) {
     copy_vector(mr.final_target, bf->ms.target); // save move final target
 
     // generate the waypoints for position correction at section ends
-    for (uint8_t axis = 0; axis < AXES; axis++) {
+    for (int axis = 0; axis < AXES; axis++) {
       mr.waypoint[SECTION_HEAD][axis] =
         mr.position[axis] + mr.unit[axis] * mr.head_length;
 
index 44130ba05c16c963f61643ebf44eb1ffcbf0f8bd..1b65a249678423fe9b4803b7a20c5ff3674902f3 100644 (file)
@@ -51,7 +51,7 @@ typedef struct mpMoveMasterSingleton {
 } mpMoveMasterSingleton_t;
 
 
-mpMoveMasterSingleton_t mm = {};     // context for line planning
+mpMoveMasterSingleton_t mm = {{0}}; // context for line planning
 
 
 /// Set planner position for a single axis
@@ -187,7 +187,7 @@ stat_t mp_aline(MoveState_t *ms) {
   float axis_square[AXES];
   float length_square = 0;
 
-  for (uint8_t axis = 0; axis < AXES; axis++) {
+  for (int axis = 0; axis < AXES; axis++) {
     axis_length[axis] = ms->target[axis] - mm.position[axis];
     axis_square[axis] = square(axis_length[axis]);
     length_square += axis_square[axis];
index 0e8981f4ee019da8a0eee267f033cdc0aa07e080..ea21eab0289c90f4fbd63bda397f93c745ac7a49 100644 (file)
@@ -71,7 +71,7 @@
 #include <stdio.h>
 
 
-mpMoveRuntimeSingleton_t mr = {}; // context for line runtime
+mpMoveRuntimeSingleton_t mr = {0}; // context for line runtime
 
 
 void planner_init() {
@@ -128,7 +128,7 @@ void mp_set_steps_to_runtime_position() {
   // convert lengths to steps in floating point
   mp_kinematics(mr.position, step_position);
 
-  for (uint8_t motor = 0; motor < MOTORS; motor++) {
+  for (int motor = 0; motor < MOTORS; motor++) {
     mr.target_steps[motor] = step_position[motor];
     mr.position_steps[motor] = step_position[motor];
     mr.commanded_steps[motor] = step_position[motor];
index e035e3967a830d022f9e52ea86ff1ac92550de0f..f372155d476819c8a0936cdb84eaa53b28ff9ec0 100644 (file)
@@ -45,7 +45,7 @@
 #define MINIMUM_PROBE_TRAVEL 0.254
 
 
-typedef enum {          // applies to mach.probe_state
+typedef enum {
   PROBE_FAILED,         // probe reached endpoint without triggering
   PROBE_SUCCEEDED,      // probe was triggered, pb.results has position
   PROBE_WAITING,        // probe is waiting to be started
@@ -70,7 +70,7 @@ struct pbProbingSingleton {       // persistent probing runtime variables
 };
 
 
-static struct pbProbingSingleton pb = {0,};
+static struct pbProbingSingleton pb = {0};
 
 
 /* Note: When coding a cycle (like this one) you get to perform one
index 8118fa1d6f0161cc08968d570d73eac44d5f3bf5..8518ea0cbb350913954cbda5a2bceaf59d283904 100644 (file)
@@ -58,7 +58,7 @@ typedef struct {
 } stepper_t;
 
 
-static stepper_t st = {};
+static stepper_t st = {0};
 
 
 void stepper_init() {
index 9bc92d7225ddfd9c5ea1546872f80f2a66b8c055..55c252397f26c86375f3a7de615e2c2d185d001a 100644 (file)
@@ -89,7 +89,7 @@ typedef struct {
   volatile uint32_t in;
 } spi_t;
 
-static spi_t spi = {};
+static spi_t spi = {0};