Skip to content

Commit

Permalink
convert DAC percent to uint8_t
Browse files Browse the repository at this point in the history
=====================

add test to Travis
  • Loading branch information
Bob-the-Kuhn authored and thinkyhead committed Jun 19, 2017
1 parent 43c96eb commit a1c65fd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Marlin/stepper_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/stepper_dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions Marlin/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Marlin/ultralcd_impl_DOGM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Marlin/ultralcd_impl_HD44780.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions Marlin/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions Marlin/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a1c65fd

Please sign in to comment.