From a1c65fd3d538e930a1c0bee82e33c35cf6e5a924 Mon Sep 17 00:00:00 2001
From: Bob-the-Kuhn <bob.kuhn@att.net>
Date: Tue, 13 Jun 2017 21:42:40 -0500
Subject: [PATCH] convert DAC percent to uint8_t

=====================

add test to Travis
---
 .travis.yml                    |  5 +++--
 Marlin/stepper_dac.cpp         |  4 ++--
 Marlin/stepper_dac.h           |  4 ++--
 Marlin/ultralcd.cpp            | 12 +++++++-----
 Marlin/ultralcd_impl_DOGM.h    |  1 +
 Marlin/ultralcd_impl_HD44780.h |  1 +
 Marlin/utility.cpp             | 15 ++++++++-------
 Marlin/utility.h               | 10 +++++-----
 8 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 127faef49..57fcefcd1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -228,10 +228,11 @@ script:
   #- opt_enable MAKRPANEL
   #- build_marlin
   #
-  # REPRAP_DISCOUNT_SMART_CONTROLLER, SDSUPPORT, and BABYSTEPPING
+  # REPRAP_DISCOUNT_SMART_CONTROLLER, SDSUPPORT, BABYSTEPPING, RIGIDBOARD_V2, and DAC_MOTOR_CURRENT_DEFAULT
   #
   - restore_configs
-  - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT BABYSTEPPING
+  - opt_set MOTHERBOARD BOARD_RIGIDBOARD_V2
+  - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT BABYSTEPPING DAC_MOTOR_CURRENT_DEFAULT
   - build_marlin
   #
   # G3D_PANEL with SDCARD_SORT_ALPHA and STATUS_MESSAGE_SCROLLING
diff --git a/Marlin/stepper_dac.cpp b/Marlin/stepper_dac.cpp
index 322a9403f..6ea8b83bc 100644
--- a/Marlin/stepper_dac.cpp
+++ b/Marlin/stepper_dac.cpp
@@ -94,8 +94,8 @@
   static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
   static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0 / (DAC_STEPPER_SENSE)); }
 
-  int16_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
-  void dac_current_set_percents(const int8_t pct[XYZE]) {
+  uint8_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
+  void dac_current_set_percents(const uint8_t pct[XYZE]) {
     LOOP_XYZE(i) dac_channel_pct[i] = pct[dac_order[i]];
     mcp4728_setDrvPct(dac_channel_pct);
   }
diff --git a/Marlin/stepper_dac.h b/Marlin/stepper_dac.h
index ab338a271..588035040 100644
--- a/Marlin/stepper_dac.h
+++ b/Marlin/stepper_dac.h
@@ -51,7 +51,7 @@ void dac_current_percent(uint8_t channel, float val);
 void dac_current_raw(uint8_t channel, uint16_t val);
 void dac_print_values();
 void dac_commit_eeprom();
-int16_t dac_current_get_percent(AxisEnum axis);
-void dac_current_set_percents(int16_t pct[XYZE]);
+uint8_t dac_current_get_percent(AxisEnum axis);
+void dac_current_set_percents(const uint8_t pct[XYZE]);
 
 #endif // STEPPER_DAC_H
diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp
index 749274486..847ad80a6 100644
--- a/Marlin/ultralcd.cpp
+++ b/Marlin/ultralcd.cpp
@@ -92,7 +92,7 @@ uint16_t max_display_update_time = 0;
 
 #if ENABLED(DAC_STEPPER_CURRENT)
   #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
-  int16_t driverPercent[XYZE];
+  uint8_t driverPercent[XYZE];
 #endif
 
 #if ENABLED(ULTIPANEL)
@@ -185,6 +185,7 @@ uint16_t max_display_update_time = 0;
     typedef void _name##_void
 
   DECLARE_MENU_EDIT_TYPE(int, int3);
+  DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
   DECLARE_MENU_EDIT_TYPE(float, float3);
   DECLARE_MENU_EDIT_TYPE(float, float32);
   DECLARE_MENU_EDIT_TYPE(float, float43);
@@ -1253,10 +1254,10 @@ void kill_screen(const char* lcd_msg) {
       dac_driver_getValues();
       START_MENU();
       MENU_BACK(MSG_CONTROL);
-      MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
-      MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
-      MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
-      MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
+      MENU_ITEM_EDIT_CALLBACK(int8, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
       MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
       END_MENU();
     }
@@ -3932,6 +3933,7 @@ void kill_screen(const char* lcd_msg) {
     typedef void _name
 
   DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
+  DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
   DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
   DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
   DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h
index 295e27676..6f4ea34e6 100644
--- a/Marlin/ultralcd_impl_DOGM.h
+++ b/Marlin/ultralcd_impl_DOGM.h
@@ -848,6 +848,7 @@ static void lcd_implementation_status_screen() {
     typedef void _name##_void
 
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int, int3, itostr3);
+  DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float43, ftostr43sign);
diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h
index 0521cb2f2..65ad28165 100644
--- a/Marlin/ultralcd_impl_HD44780.h
+++ b/Marlin/ultralcd_impl_HD44780.h
@@ -959,6 +959,7 @@ static void lcd_implementation_status_screen() {
     typedef void _name##_void
 
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int, int3, itostr3);
+  DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
   DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float43, ftostr43sign);
diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp
index ee1bef1c9..0f5919355 100644
--- a/Marlin/utility.cpp
+++ b/Marlin/utility.cpp
@@ -56,15 +56,16 @@ void safe_delay(millis_t ms) {
   #define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ')
   #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
 
-  // Convert unsigned int to string with 12 format
-  char* itostr2(const uint8_t &xx) {
-    conv[5] = DIGIMOD(xx, 10);
+  // Convert unsigned int to string 123 format
+  char* i8tostr3(const uint8_t xx) {
+    conv[4] = RJDIGIT(xx, 100);
+    conv[5] = RJDIGIT(xx, 10);
     conv[6] = DIGIMOD(xx, 1);
-    return &conv[5];
+    return &conv[4];
   }
 
   // Convert signed int to rj string with 123 or -12 format
-  char* itostr3(const int &x) {
+  char* itostr3(const int x) {
     int xx = x;
     conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
     conv[5] = RJDIGIT(xx, 10);
@@ -73,7 +74,7 @@ void safe_delay(millis_t ms) {
   }
 
   // Convert unsigned int to lj string with 123 format
-  char* itostr3left(const int &xx) {
+  char* itostr3left(const int xx) {
     char *str = &conv[6];
     *str = DIGIMOD(xx, 1);
     if (xx >= 10) {
@@ -85,7 +86,7 @@ void safe_delay(millis_t ms) {
   }
 
   // Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format
-  char *itostr4sign(const int &x) {
+  char *itostr4sign(const int x) {
     const bool neg = x < 0;
     const int xx = neg ? -x : x;
     if (x >= 1000) {
diff --git a/Marlin/utility.h b/Marlin/utility.h
index 779b788c7..f88e6943a 100644
--- a/Marlin/utility.h
+++ b/Marlin/utility.h
@@ -31,17 +31,17 @@ void safe_delay(millis_t ms);
 
 #if ENABLED(ULTRA_LCD)
 
-  // Convert unsigned int to string with 12 format
-  char* itostr2(const uint8_t &x);
+  // Convert uint8_t to string with 123 format
+  char* i8tostr3(const uint8_t x);
 
   // Convert signed int to rj string with 123 or -12 format
-  char* itostr3(const int &x);
+  char* itostr3(const int x);
 
   // Convert unsigned int to lj string with 123 format
-  char* itostr3left(const int &xx);
+  char* itostr3left(const int xx);
 
   // Convert signed int to rj string with _123, -123, _-12, or __-1 format
-  char *itostr4sign(const int &x);
+  char *itostr4sign(const int x);
 
   // Convert unsigned float to string with 1.23 format
   char* ftostr12ns(const float &x);