Feature file updates

This commit is contained in:
Scott Lahteine 2017-09-06 06:28:32 -05:00
parent d7ee81202f
commit 4a82e95c3e
23 changed files with 1831 additions and 1650 deletions

View File

@ -28,20 +28,19 @@
//todo: consider Marlin-optimized Wire library; i.e. MarlinWire, like MarlinSerial
#include "MarlinConfig.h"
#include "../inc/MarlinConfig.h"
#if ENABLED(I2C_POSITION_ENCODERS)
#include "Marlin.h"
#include "temperature.h"
#include "stepper.h"
#include "I2CPositionEncoder.h"
#include "gcode.h"
#include "I2CPositionEncoder.h"
#include <Wire.h>
#include "../module/temperature.h"
#include "../module/stepper.h"
#include "../gcode/parser.h"
#include <Wire.h>
void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {
void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {
encoderAxis = axis;
i2cAddress = address;
@ -51,9 +50,9 @@
SERIAL_ECHOLNPAIR(" axis, addr = ", address);
position = get_position();
}
}
void I2CPositionEncoder::update() {
void I2CPositionEncoder::update() {
if (!initialised || !homed || !active) return; //check encoder is set up and active
position = get_position();
@ -205,9 +204,9 @@
}
lastPositionTime = positionTime;
}
}
void I2CPositionEncoder::set_homed() {
void I2CPositionEncoder::set_homed() {
if (active) {
reset(); // Reset module's offset to zero (so current position is homed / zero)
delay(10);
@ -222,9 +221,9 @@
SERIAL_ECHOLNPGM(" ticks.");
#endif
}
}
}
bool I2CPositionEncoder::passes_test(const bool report) {
bool I2CPositionEncoder::passes_test(const bool report) {
if (report) {
if (H != I2CPE_MAG_SIG_GOOD) SERIAL_ECHOPGM("Warning. ");
SERIAL_ECHO(axis_codes[encoderAxis]);
@ -241,9 +240,9 @@
}
}
return (H == I2CPE_MAG_SIG_GOOD || H == I2CPE_MAG_SIG_MID);
}
}
float I2CPositionEncoder::get_axis_error_mm(const bool report) {
float I2CPositionEncoder::get_axis_error_mm(const bool report) {
float target, actual, error;
target = stepper.get_axis_position_mm(encoderAxis);
@ -260,9 +259,9 @@
}
return error;
}
}
int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
int32_t I2CPositionEncoder::get_axis_error_steps(const bool report) {
if (!active) {
if (report) {
SERIAL_ECHO(axis_codes[encoderAxis]);
@ -299,9 +298,9 @@
errorPrev = error;
return (suppressOutput ? 0 : error);
}
}
int32_t I2CPositionEncoder::get_raw_count() {
int32_t I2CPositionEncoder::get_raw_count() {
uint8_t index = 0;
i2cLong encoderCount;
@ -326,9 +325,9 @@
if (invert) encoderCount.val *= -1;
return encoderCount.val;
}
}
bool I2CPositionEncoder::test_axis() {
bool I2CPositionEncoder::test_axis() {
//only works on XYZ cartesian machines for the time being
if (!(encoderAxis == X_AXIS || encoderAxis == Y_AXIS || encoderAxis == Z_AXIS)) return false;
@ -368,9 +367,9 @@
}
return trusted;
}
}
void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
if (type != I2CPE_ENC_TYPE_LINEAR) {
SERIAL_ECHOLNPGM("Steps per mm calibration is only available using linear encoders.");
return;
@ -463,9 +462,9 @@
ec = oldec;
SERIAL_ECHOLNPGM("Calculated steps per mm has been set. Please save to EEPROM (M500) if you wish to keep these values.");
}
}
void I2CPositionEncoder::reset() {
void I2CPositionEncoder::reset() {
Wire.beginTransmission(i2cAddress);
Wire.write(I2CPE_RESET_COUNT);
Wire.endTransmission();
@ -473,15 +472,15 @@
#if ENABLED(I2CPE_ERR_ROLLING_AVERAGE)
ZERO(err);
#endif
}
}
bool I2CPositionEncodersMgr::I2CPE_anyaxis;
uint8_t I2CPositionEncodersMgr::I2CPE_addr,
bool I2CPositionEncodersMgr::I2CPE_anyaxis;
uint8_t I2CPositionEncodersMgr::I2CPE_addr,
I2CPositionEncodersMgr::I2CPE_idx;
I2CPositionEncoder I2CPositionEncodersMgr::encoders[I2CPE_ENCODER_CNT];
I2CPositionEncoder I2CPositionEncodersMgr::encoders[I2CPE_ENCODER_CNT];
void I2CPositionEncodersMgr::init() {
void I2CPositionEncodersMgr::init() {
Wire.begin();
#if I2CPE_ENCODER_CNT > 0
@ -638,9 +637,9 @@
encoders[i].set_homed();
#endif
#endif
}
}
void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units, const bool noOffset) {
void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units, const bool noOffset) {
CHECK_IDX();
if (units)
@ -661,9 +660,9 @@
else
SERIAL_ECHOLN(encoders[idx].get_position());
}
}
}
void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const uint8_t newaddr) {
void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const uint8_t newaddr) {
// First check 'new' address is not in use
Wire.beginTransmission(newaddr);
if (!Wire.endTransmission()) {
@ -711,9 +710,9 @@
SERIAL_ECHOLNPGM(" axis encoder was not detected on printer startup. Trying again.");
encoders[idx].set_active(encoders[idx].passes_test(true));
}
}
}
void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
// First check there is a module
Wire.beginTransmission(address);
if (Wire.endTransmission()) {
@ -743,9 +742,9 @@
Wire.write(I2CPE_SET_REPORT_MODE);
Wire.write(I2CPE_REPORT_DISTANCE);
Wire.endTransmission();
}
}
int8_t I2CPositionEncodersMgr::parse() {
int8_t I2CPositionEncodersMgr::parse() {
I2CPE_addr = 0;
if (parser.seen('A')) {
@ -790,9 +789,9 @@
I2CPE_anyaxis = parser.seen_axis();
return I2CPE_PARSE_OK;
};
};
/**
/**
* M860: Report the position(s) of position encoder module(s).
*
* A<addr> Module I2C address. [30, 200].
@ -807,7 +806,7 @@
* E Report on E axis encoder, if present.
*
*/
void I2CPositionEncodersMgr::M860() {
void I2CPositionEncodersMgr::M860() {
if (parse()) return;
const bool hasU = parser.seen('U'), hasO = parser.seen('O');
@ -822,9 +821,9 @@
}
else
report_position(I2CPE_idx, hasU, hasO);
}
}
/**
/**
* M861: Report the status of position encoder modules.
*
* A<addr> Module I2C address. [30, 200].
@ -837,7 +836,7 @@
* E Report on E axis encoder, if present.
*
*/
void I2CPositionEncodersMgr::M861() {
void I2CPositionEncodersMgr::M861() {
if (parse()) return;
if (I2CPE_idx == 0xFF) {
@ -850,9 +849,9 @@
}
else
report_status(I2CPE_idx);
}
}
/**
/**
* M862: Perform an axis continuity test for position encoder
* modules.
*
@ -866,7 +865,7 @@
* E Report on E axis encoder, if present.
*
*/
void I2CPositionEncodersMgr::M862() {
void I2CPositionEncodersMgr::M862() {
if (parse()) return;
if (I2CPE_idx == 0xFF) {
@ -879,9 +878,9 @@
}
else
test_axis(I2CPE_idx);
}
}
/**
/**
* M863: Perform steps-per-mm calibration for
* position encoder modules.
*
@ -896,7 +895,7 @@
* E Report on E axis encoder, if present.
*
*/
void I2CPositionEncodersMgr::M863() {
void I2CPositionEncodersMgr::M863() {
if (parse()) return;
const uint8_t iterations = constrain(parser.byteval('P', 1), 1, 10);
@ -911,9 +910,9 @@
}
else
calibrate_steps_mm(I2CPE_idx, iterations);
}
}
/**
/**
* M864: Change position encoder module I2C address.
*
* A<addr> Module current/old I2C address. If not present,
@ -926,7 +925,7 @@
* Z Use I2CPE_PRESET_ADDR_Z (032).
* E Use I2CPE_PRESET_ADDR_E (033).
*/
void I2CPositionEncodersMgr::M864() {
void I2CPositionEncodersMgr::M864() {
uint8_t newAddress;
if (parse()) return;
@ -961,9 +960,9 @@
SERIAL_ECHOLNPAIR(" to address ", newAddress);
change_module_address(I2CPE_addr, newAddress);
}
}
/**
/**
* M865: Check position encoder module firmware version.
*
* A<addr> Module I2C address. [30, 200].
@ -975,7 +974,7 @@
* Z Check Z axis encoder, if present.
* E Check E axis encoder, if present.
*/
void I2CPositionEncodersMgr::M865() {
void I2CPositionEncodersMgr::M865() {
if (parse()) return;
if (!I2CPE_addr) {
@ -988,9 +987,9 @@
}
else
report_module_firmware(I2CPE_addr);
}
}
/**
/**
* M866: Report or reset position encoder module error
* count.
*
@ -1004,7 +1003,7 @@
* Z Act on Z axis encoder, if present.
* E Act on E axis encoder, if present.
*/
void I2CPositionEncodersMgr::M866() {
void I2CPositionEncodersMgr::M866() {
if (parse()) return;
const bool hasR = parser.seen('R');
@ -1026,9 +1025,9 @@
reset_error_count(I2CPE_idx, encoders[I2CPE_idx].get_axis());
else
report_error_count(I2CPE_idx, encoders[I2CPE_idx].get_axis());
}
}
/**
/**
* M867: Enable/disable or toggle error correction for position encoder modules.
*
* A<addr> Module I2C address. [30, 200].
@ -1042,7 +1041,7 @@
* Z Act on Z axis encoder, if present.
* E Act on E axis encoder, if present.
*/
void I2CPositionEncodersMgr::M867() {
void I2CPositionEncodersMgr::M867() {
if (parse()) return;
const int8_t onoff = parser.seenval('S') ? parser.value_int() : -1;
@ -1062,9 +1061,9 @@
const bool ena = onoff == -1 ? !encoders[I2CPE_idx].get_ec_enabled() : !!onoff;
enable_ec(I2CPE_idx, ena, encoders[I2CPE_idx].get_axis());
}
}
}
/**
/**
* M868: Report or set position encoder module error correction
* threshold.
*
@ -1078,7 +1077,7 @@
* Z Act on Z axis encoder, if present.
* E Act on E axis encoder, if present.
*/
void I2CPositionEncodersMgr::M868() {
void I2CPositionEncodersMgr::M868() {
if (parse()) return;
const float newThreshold = parser.seenval('T') ? parser.value_float() : -9999;
@ -1100,9 +1099,9 @@
set_ec_threshold(I2CPE_idx, newThreshold, encoders[I2CPE_idx].get_axis());
else
get_ec_threshold(I2CPE_idx, encoders[I2CPE_idx].get_axis());
}
}
/**
/**
* M869: Report position encoder module error.
*
* A<addr> Module I2C address. [30, 200].
@ -1114,7 +1113,7 @@
* Z Act on Z axis encoder, if present.
* E Act on E axis encoder, if present.
*/
void I2CPositionEncodersMgr::M869() {
void I2CPositionEncodersMgr::M869() {
if (parse()) return;
if (I2CPE_idx == 0xFF) {
@ -1127,6 +1126,6 @@
}
else
report_error(I2CPE_idx);
}
}
#endif // I2C_POSITION_ENCODERS

View File

@ -23,88 +23,85 @@
#ifndef I2CPOSENC_H
#define I2CPOSENC_H
#include "MarlinConfig.h"
#include "../inc/MarlinConfig.h"
#if ENABLED(I2C_POSITION_ENCODERS)
#include "../module/planner.h"
#include "enum.h"
#include "macros.h"
#include "types.h"
#include <Wire.h>
#include <Wire.h>
//=========== Advanced / Less-Common Encoder Configuration Settings ==========
//=========== Advanced / Less-Common Encoder Configuration Settings ==========
#define I2CPE_EC_THRESH_PROPORTIONAL // if enabled adjusts the error correction threshold
#define I2CPE_EC_THRESH_PROPORTIONAL // if enabled adjusts the error correction threshold
// proportional to the current speed of the axis allows
// for very small error margin at low speeds without
// stuttering due to reading latency at high speeds
#define I2CPE_DEBUG // enable encoder-related debug serial echos
#define I2CPE_DEBUG // enable encoder-related debug serial echos
#define I2CPE_REBOOT_TIME 5000 // time we wait for an encoder module to reboot
#define I2CPE_REBOOT_TIME 5000 // time we wait for an encoder module to reboot
// after changing address.
#define I2CPE_MAG_SIG_GOOD 0
#define I2CPE_MAG_SIG_MID 1
#define I2CPE_MAG_SIG_BAD 2
#define I2CPE_MAG_SIG_NF 255
#define I2CPE_MAG_SIG_GOOD 0
#define I2CPE_MAG_SIG_MID 1
#define I2CPE_MAG_SIG_BAD 2
#define I2CPE_MAG_SIG_NF 255
#define I2CPE_REQ_REPORT 0
#define I2CPE_RESET_COUNT 1
#define I2CPE_SET_ADDR 2
#define I2CPE_SET_REPORT_MODE 3
#define I2CPE_CLEAR_EEPROM 4
#define I2CPE_REQ_REPORT 0
#define I2CPE_RESET_COUNT 1
#define I2CPE_SET_ADDR 2
#define I2CPE_SET_REPORT_MODE 3
#define I2CPE_CLEAR_EEPROM 4
#define I2CPE_LED_PAR_MODE 10
#define I2CPE_LED_PAR_BRT 11
#define I2CPE_LED_PAR_RATE 14
#define I2CPE_LED_PAR_MODE 10
#define I2CPE_LED_PAR_BRT 11
#define I2CPE_LED_PAR_RATE 14
#define I2CPE_REPORT_DISTANCE 0
#define I2CPE_REPORT_STRENGTH 1
#define I2CPE_REPORT_VERSION 2
#define I2CPE_REPORT_DISTANCE 0
#define I2CPE_REPORT_STRENGTH 1
#define I2CPE_REPORT_VERSION 2
// Default I2C addresses
#define I2CPE_PRESET_ADDR_X 30
#define I2CPE_PRESET_ADDR_Y 31
#define I2CPE_PRESET_ADDR_Z 32
#define I2CPE_PRESET_ADDR_E 33
// Default I2C addresses
#define I2CPE_PRESET_ADDR_X 30
#define I2CPE_PRESET_ADDR_Y 31
#define I2CPE_PRESET_ADDR_Z 32
#define I2CPE_PRESET_ADDR_E 33
#define I2CPE_DEF_AXIS X_AXIS
#define I2CPE_DEF_ADDR I2CPE_PRESET_ADDR_X
#define I2CPE_DEF_AXIS X_AXIS
#define I2CPE_DEF_ADDR I2CPE_PRESET_ADDR_X
// Error event counter; tracks how many times there is an error exceeding a certain threshold
#define I2CPE_ERR_CNT_THRESH 3.00
#define I2CPE_ERR_CNT_DEBOUNCE_MS 2000
// Error event counter; tracks how many times there is an error exceeding a certain threshold
#define I2CPE_ERR_CNT_THRESH 3.00
#define I2CPE_ERR_CNT_DEBOUNCE_MS 2000
#if ENABLED(I2CPE_ERR_ROLLING_AVERAGE)
#if ENABLED(I2CPE_ERR_ROLLING_AVERAGE)
#define I2CPE_ERR_ARRAY_SIZE 32
#endif
#endif
// Error Correction Methods
#define I2CPE_ECM_NONE 0
#define I2CPE_ECM_MICROSTEP 1
#define I2CPE_ECM_PLANNER 2
#define I2CPE_ECM_STALLDETECT 3
// Error Correction Methods
#define I2CPE_ECM_NONE 0
#define I2CPE_ECM_MICROSTEP 1
#define I2CPE_ECM_PLANNER 2
#define I2CPE_ECM_STALLDETECT 3
// Encoder types
#define I2CPE_ENC_TYPE_ROTARY 0
#define I2CPE_ENC_TYPE_LINEAR 1
// Encoder types
#define I2CPE_ENC_TYPE_ROTARY 0
#define I2CPE_ENC_TYPE_LINEAR 1
// Parser
#define I2CPE_PARSE_ERR 1
#define I2CPE_PARSE_OK 0
// Parser
#define I2CPE_PARSE_ERR 1
#define I2CPE_PARSE_OK 0
#define LOOP_PE(VAR) LOOP_L_N(VAR, I2CPE_ENCODER_CNT)
#define CHECK_IDX() do{ if (!WITHIN(idx, 0, I2CPE_ENCODER_CNT - 1)) return; }while(0)
#define LOOP_PE(VAR) LOOP_L_N(VAR, I2CPE_ENCODER_CNT)
#define CHECK_IDX() do{ if (!WITHIN(idx, 0, I2CPE_ENCODER_CNT - 1)) return; }while(0)
extern const char axis_codes[XYZE];
extern const char axis_codes[XYZE];
typedef union {
typedef union {
volatile int32_t val = 0;
uint8_t bval[4];
} i2cLong;
} i2cLong;
class I2CPositionEncoder {
class I2CPositionEncoder {
private:
AxisEnum encoderAxis = I2CPE_DEF_AXIS;
@ -229,9 +226,9 @@
FORCE_INLINE void set_current_position(const float newPositionMm) {
set_axis_offset(get_position_mm() - newPositionMm + axisOffset);
}
};
};
class I2CPositionEncodersMgr {
class I2CPositionEncodersMgr {
private:
static bool I2CPE_anyaxis;
static uint8_t I2CPE_addr, I2CPE_idx;
@ -252,7 +249,7 @@
static void report_status(const int8_t idx) {
CHECK_IDX();
SERIAL_ECHOPAIR("Encoder ",idx);
SERIAL_ECHOPAIR("Encoder ", idx);
SERIAL_ECHOPGM(": ");
encoders[idx].get_raw_count();
encoders[idx].passes_test(true);
@ -340,20 +337,19 @@
static void M869();
static I2CPositionEncoder encoders[I2CPE_ENCODER_CNT];
};
};
extern I2CPositionEncodersMgr I2CPEM;
extern I2CPositionEncodersMgr I2CPEM;
FORCE_INLINE static void gcode_M860() { I2CPEM.M860(); }
FORCE_INLINE static void gcode_M861() { I2CPEM.M861(); }
FORCE_INLINE static void gcode_M862() { I2CPEM.M862(); }
FORCE_INLINE static void gcode_M863() { I2CPEM.M863(); }
FORCE_INLINE static void gcode_M864() { I2CPEM.M864(); }
FORCE_INLINE static void gcode_M865() { I2CPEM.M865(); }
FORCE_INLINE static void gcode_M866() { I2CPEM.M866(); }
FORCE_INLINE static void gcode_M867() { I2CPEM.M867(); }
FORCE_INLINE static void gcode_M868() { I2CPEM.M868(); }
FORCE_INLINE static void gcode_M869() { I2CPEM.M869(); }
FORCE_INLINE static void gcode_M860() { I2CPEM.M860(); }
FORCE_INLINE static void gcode_M861() { I2CPEM.M861(); }
FORCE_INLINE static void gcode_M862() { I2CPEM.M862(); }
FORCE_INLINE static void gcode_M863() { I2CPEM.M863(); }
FORCE_INLINE static void gcode_M864() { I2CPEM.M864(); }
FORCE_INLINE static void gcode_M865() { I2CPEM.M865(); }
FORCE_INLINE static void gcode_M866() { I2CPEM.M866(); }
FORCE_INLINE static void gcode_M867() { I2CPEM.M867(); }
FORCE_INLINE static void gcode_M868() { I2CPEM.M868(); }
FORCE_INLINE static void gcode_M869() { I2CPEM.M869(); }
#endif //I2C_POSITION_ENCODERS
#endif //I2CPOSENC_H

View File

@ -3,17 +3,21 @@
* External DAC for Alligator Board
*
****************************************************************/
#include "Marlin.h"
#include "../../inc/MarlinConfig.h"
#if MB(ALLIGATOR)
#include "stepper.h"
#include "dac_dac084s085.h"
dac084s085::dac084s085() {
#include "dac_dac084s085.h"
#include "../../Marlin.h"
#include "../../module/stepper.h"
dac084s085::dac084s085() {
return ;
}
}
void dac084s085::begin() {
void dac084s085::begin() {
uint8_t externalDac_buf[2] = {0x20,0x00};//all off
// All SPI chip-select HIGH
@ -54,9 +58,9 @@
#endif
return;
}
}
void dac084s085::setValue(uint8_t channel, uint8_t value) {
void dac084s085::setValue(uint8_t channel, uint8_t value) {
if(channel >= 7) // max channel (X,Y,Z,E0,E1,E2,E3)
return;
if(value > 255) value = 255;
@ -103,6 +107,6 @@
spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
return;
}
}
#endif
#endif // MB(ALLIGATOR)

View File

@ -1,5 +1,5 @@
#ifndef dac084s085_h
#define dac084s085_h
#ifndef DAC084S085_H
#define DAC084S085_H
class dac084s085 {
public:
@ -8,4 +8,4 @@ class dac084s085 {
static void setValue(uint8_t channel, uint8_t value);
};
#endif //dac084s085_h
#endif // DAC084S085_H

View File

@ -30,11 +30,12 @@
* http://arduino.cc/forum/index.php/topic,51842.0.html
*/
#include "dac_mcp4728.h"
#include "enum.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(DAC_STEPPER_CURRENT)
#include "dac_mcp4728.h"
uint16_t mcp4728_values[XYZE];
/**

View File

@ -27,10 +27,7 @@
#ifndef DAC_MCP4728_H
#define DAC_MCP4728_H
#include "MarlinConfig.h"
#if ENABLED(DAC_STEPPER_CURRENT)
#include "Wire.h"
#include <Wire.h>
#define defaultVDD DAC_STEPPER_MAX //was 5000 but differs with internal Vref
#define BASE_ADDR 0x60
@ -50,7 +47,6 @@
// DAC_OR_ADDRESS defined in pins_BOARD.h file
#define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
void mcp4728_init();
uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value);
uint8_t mcp4728_eepromWrite();
@ -62,5 +58,4 @@ uint8_t mcp4728_simpleCommand(byte simpleCommand);
uint8_t mcp4728_getDrvPct(uint8_t channel);
void mcp4728_setDrvPct(uint8_t pct[XYZE]);
#endif
#endif // DAC_MCP4728_H

View File

@ -41,17 +41,17 @@
along with Marlin. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Marlin.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(DAC_STEPPER_CURRENT)
#include "stepper_dac.h"
#include "stepper_dac.h"
bool dac_present = false;
const uint8_t dac_order[NUM_AXIS] = DAC_STEPPER_ORDER;
uint8_t dac_channel_pct[XYZE] = DAC_MOTOR_CURRENT_DEFAULT;
bool dac_present = false;
const uint8_t dac_order[NUM_AXIS] = DAC_STEPPER_ORDER;
uint8_t dac_channel_pct[XYZE] = DAC_MOTOR_CURRENT_DEFAULT;
int dac_init() {
int dac_init() {
#if PIN_EXISTS(DAC_DISABLE)
OUT_WRITE(DAC_DISABLE_PIN, LOW); // set pin low to enable DAC
#endif
@ -71,36 +71,36 @@
}
return 0;
}
}
void dac_current_percent(uint8_t channel, float val) {
void dac_current_percent(uint8_t channel, float val) {
if (!dac_present) return;
NOMORE(val, 100);
mcp4728_analogWrite(dac_order[channel], val * 0.01 * (DAC_STEPPER_MAX));
mcp4728_simpleCommand(UPDATE);
}
}
void dac_current_raw(uint8_t channel, uint16_t val) {
void dac_current_raw(uint8_t channel, uint16_t val) {
if (!dac_present) return;
NOMORE(val, DAC_STEPPER_MAX);
mcp4728_analogWrite(dac_order[channel], val);
mcp4728_simpleCommand(UPDATE);
}
}
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)); }
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)); }
uint8_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
void dac_current_set_percents(const uint8_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);
}
}
void dac_print_values() {
void dac_print_values() {
if (!dac_present) return;
SERIAL_ECHO_START();
@ -115,11 +115,11 @@
SERIAL_ECHOPAIR(") E:", dac_perc(E_AXIS));
SERIAL_ECHOPAIR(" (", dac_amps(E_AXIS));
SERIAL_ECHOLN(")");
}
}
void dac_commit_eeprom() {
void dac_commit_eeprom() {
if (!dac_present) return;
mcp4728_eepromWrite();
}
}
#endif // DAC_STEPPER_CURRENT

View File

@ -20,11 +20,11 @@
*
*/
#include "MarlinConfig.h"
#include "../inc/MarlinConfig.h"
#if ENABLED(DIGIPOT_I2C) && ENABLED(DIGIPOT_MCP4018)
#include "enum.h"
#include "../core/enum.h"
#include "Stream.h"
#include "utility/twi.h"
#include <SlowSoftI2CMaster.h> //https://github.com/stawel/SlowSoftI2CMaster

View File

@ -20,7 +20,7 @@
*
*/
#include "MarlinConfig.h"
#include "../inc/MarlinConfig.h"
#if ENABLED(DIGIPOT_I2C) && DISABLED(DIGIPOT_MCP4018)

View File

@ -49,15 +49,16 @@
* void Max7219_idle_tasks();
*/
#include "MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(MAX7219_DEBUG)
#include "Marlin.h"
#include "planner.h"
#include "stepper.h"
#include "Max7219_Debug_LEDs.h"
#include "../../module/planner.h"
#include "../../module/stepper.h"
#include "../../Marlin.h"
static uint8_t LEDs[8] = { 0 };
void Max7219_PutByte(uint8_t data) {

View File

@ -25,7 +25,7 @@
* Created by Tim Koster, August 21 2013.
*/
#include "Marlin.h"
#include "../../Marlin.h"
#if ENABLED(BLINKM)

View File

@ -20,12 +20,12 @@
*
*/
/*
/**
* Driver for the Philips PCA9632 LED driver.
* Written by Robert Mendon Feb 2017.
*/
#include "MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(PCA9632)

View File

@ -20,10 +20,12 @@
*
*/
#include "mesh_bed_leveling.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(MESH_BED_LEVELING)
#include "mesh_bed_leveling.h"
mesh_bed_leveling mbl;
uint8_t mesh_bed_leveling::status;

View File

@ -20,30 +20,31 @@
*
*/
#include "Marlin.h"
#ifndef _MESH_BED_LEVELING_H_
#define _MESH_BED_LEVELING_H_
#if ENABLED(MESH_BED_LEVELING)
#include "../../Marlin.h"
enum MeshLevelingState {
enum MeshLevelingState {
MeshReport,
MeshStart,
MeshNext,
MeshSet,
MeshSetZOffset,
MeshReset
};
};
enum MBLStatus {
enum MBLStatus {
MBL_STATUS_NONE = 0,
MBL_STATUS_HAS_MESH_BIT = 0,
MBL_STATUS_ACTIVE_BIT = 1
};
};
#define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
#define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
class mesh_bed_leveling {
public:
class mesh_bed_leveling {
public:
static uint8_t status; // Has Mesh and Is Active bits
static float z_offset,
z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
@ -115,8 +116,8 @@
#endif
;
}
};
};
extern mesh_bed_leveling mbl;
extern mesh_bed_leveling mbl;
#endif // MESH_BED_LEVELING
#endif // _MESH_BED_LEVELING_H_

View File

@ -0,0 +1,157 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130)
#include "tmc2130.h"
#include "../Marlin.h"
#include "../libs/duration_t.h"
#include "../module/stepper_indirection.h"
#include <TMC2130Stepper.h>
#ifdef AUTOMATIC_CURRENT_CONTROL
bool auto_current_control = 0;
#endif
void automatic_current_control(TMC2130Stepper &st, String axisID) {
// Check otpw even if we don't use automatic control. Allows for flag inspection.
const bool is_otpw = st.checkOT();
// Report if a warning was triggered
static bool previous_otpw = false;
if (is_otpw && !previous_otpw) {
char timestamp[10];
duration_t elapsed = print_job_timer.duration();
const bool has_days = (elapsed.value > 60*60*24L);
(void)elapsed.toDigital(timestamp, has_days);
SERIAL_ECHO(timestamp);
SERIAL_ECHOPGM(": ");
SERIAL_ECHO(axisID);
SERIAL_ECHOLNPGM(" driver overtemperature warning!");
}
previous_otpw = is_otpw;
#if ENABLED(AUTOMATIC_CURRENT_CONTROL) && CURRENT_STEP > 0
// Return if user has not enabled current control start with M906 S1.
if (!auto_current_control) return;
/**
* Decrease current if is_otpw is true.
* Bail out if driver is disabled.
* Increase current if OTPW has not been triggered yet.
*/
uint16_t current = st.getCurrent();
if (is_otpw) {
st.setCurrent(current - CURRENT_STEP, R_SENSE, HOLD_MULTIPLIER);
#if ENABLED(REPORT_CURRENT_CHANGE)
SERIAL_ECHO(axisID);
SERIAL_ECHOPAIR(" current decreased to ", st.getCurrent());
#endif
}
else if (!st.isEnabled())
return;
else if (!is_otpw && !st.getOTPW()) {
current += CURRENT_STEP;
if (current <= AUTO_ADJUST_MAX) {
st.setCurrent(current, R_SENSE, HOLD_MULTIPLIER);
#if ENABLED(REPORT_CURRENT_CHANGE)
SERIAL_ECHO(axisID);
SERIAL_ECHOPAIR(" current increased to ", st.getCurrent());
#endif
}
}
SERIAL_EOL();
#endif
}
void tmc2130_checkOverTemp(void) {
static millis_t next_cOT = 0;
if (ELAPSED(millis(), next_cOT)) {
next_cOT = millis() + 5000;
#if ENABLED(X_IS_TMC2130)
automatic_current_control(stepperX, "X");
#endif
#if ENABLED(Y_IS_TMC2130)
automatic_current_control(stepperY, "Y");
#endif
#if ENABLED(Z_IS_TMC2130)
automatic_current_control(stepperZ, "Z");
#endif
#if ENABLED(X2_IS_TMC2130)
automatic_current_control(stepperX2, "X2");
#endif
#if ENABLED(Y2_IS_TMC2130)
automatic_current_control(stepperY2, "Y2");
#endif
#if ENABLED(Z2_IS_TMC2130)
automatic_current_control(stepperZ2, "Z2");
#endif
#if ENABLED(E0_IS_TMC2130)
automatic_current_control(stepperE0, "E0");
#endif
#if ENABLED(E1_IS_TMC2130)
automatic_current_control(stepperE1, "E1");
#endif
#if ENABLED(E2_IS_TMC2130)
automatic_current_control(stepperE2, "E2");
#endif
#if ENABLED(E3_IS_TMC2130)
automatic_current_control(stepperE3, "E3");
#endif
#if ENABLED(E4_IS_TMC2130)
automatic_current_control(stepperE4, "E4");
#endif
#if ENABLED(E4_IS_TMC2130)
automatic_current_control(stepperE4);
#endif
}
}
/**
* TMC2130 specific sensorless homing using stallGuard2.
* stallGuard2 only works when in spreadCycle mode.
* spreadCycle and stealthChop are mutually exclusive.
*/
#if ENABLED(SENSORLESS_HOMING)
void tmc2130_sensorless_homing(TMC2130Stepper &st, bool enable/*=true*/) {
#if ENABLED(STEALTHCHOP)
if (enable) {
st.coolstep_min_speed(1024UL * 1024UL - 1UL);
st.stealthChop(0);
}
else {
st.coolstep_min_speed(0);
st.stealthChop(1);
}
#endif
st.diag1_stall(enable ? 1 : 0);
}
#endif // SENSORLESS_HOMING
#endif // HAVE_TMC2130

View File

@ -0,0 +1,30 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _TMC2130_H_
#define _TMC2130_H_
extern bool auto_current_control;
void tmc2130_checkOverTemp(void);
#endif // _TMC2130_H_

View File

@ -20,11 +20,12 @@
*
*/
#include "Marlin.h"
#include "../inc/MarlinConfig.h"
#if ENABLED(EXPERIMENTAL_I2CBUS)
#include "twibus.h"
#include <Wire.h>
TWIBus::TWIBus() {

View File

@ -23,7 +23,7 @@
#ifndef TWIBUS_H
#define TWIBUS_H
#include "macros.h"
#include "../core/macros.h"
#include <Wire.h>

View File

@ -24,17 +24,18 @@
* Marlin Firmware -- G26 - Mesh Validation Tool
*/
#include "MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_G26_MESH_VALIDATION)
#include "ubl.h"
#include "Marlin.h"
#include "planner.h"
#include "stepper.h"
#include "temperature.h"
#include "ultralcd.h"
#include "gcode.h"
#include "../../Marlin.h"
#include "../../module/planner.h"
#include "../../module/stepper.h"
#include "../../module/temperature.h"
#include "../../lcd/ultralcd.h"
#include "../../gcode/parser.h"
#define EXTRUSION_MULTIPLIER 1.0
#define RETRACTION_MULTIPLIER 1.0
@ -140,8 +141,8 @@
inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
inline void set_current_to_destination() { COPY(current_position, destination); }
#else
extern void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
extern void set_current_to_destination() { COPY(current_position, destination); }
extern void sync_plan_position_e();
extern void set_current_to_destination();
#endif
#if ENABLED(NEWPANEL)
void lcd_setstatusPGM(const char* const message, const int8_t level);

View File

@ -20,16 +20,18 @@
*
*/
#include "Marlin.h"
#include "math.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "ubl.h"
#include "hex_print_routines.h"
#include "temperature.h"
unified_bed_leveling ubl;
extern Planner planner;
#include "../../module/configuration_store.h"
#include "../../core/serial.h"
#include "../../module/planner.h"
#include "math.h"
/**
* These support functions allow the use of large bit arrays of flags that take very
@ -37,9 +39,9 @@
* to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed
* in the future.
*/
void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y) { CBI(bits[y], x); }
void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); }
bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); }
void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
uint8_t ubl_cnt = 0;

View File

@ -23,66 +23,61 @@
#ifndef UNIFIED_BED_LEVELING_H
#define UNIFIED_BED_LEVELING_H
#include "MarlinConfig.h"
#include "../../Marlin.h"
#include "../../core/serial.h"
#include "../../module/planner.h"
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "Marlin.h"
#include "planner.h"
#include "math.h"
#include "vector_3.h"
#include "configuration_store.h"
#define UBL_VERSION "1.01"
#define UBL_OK false
#define UBL_ERR true
#define UBL_VERSION "1.01"
#define UBL_OK false
#define UBL_ERR true
#define USE_NOZZLE_AS_REFERENCE 0
#define USE_PROBE_AS_REFERENCE 1
#define USE_NOZZLE_AS_REFERENCE 0
#define USE_PROBE_AS_REFERENCE 1
typedef struct {
typedef struct {
int8_t x_index, y_index;
float distance; // When populated, the distance from the search location
} mesh_index_pair;
} mesh_index_pair;
// ubl.cpp
// ubl.cpp
void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y);
void bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y);
void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y);
bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y);
// ubl_motion.cpp
// ubl_motion.cpp
void debug_current_and_destination(const char * const title);
void debug_current_and_destination(const char * const title);
// ubl_G29.cpp
// ubl_G29.cpp
enum MeshPointType { INVALID, REAL, SET_IN_BITMAP };
enum MeshPointType { INVALID, REAL, SET_IN_BITMAP };
// External references
// External references
char *ftostr43sign(const float&, char);
bool ubl_lcd_clicked();
void home_all_axes();
char *ftostr43sign(const float&, char);
bool ubl_lcd_clicked();
void home_all_axes();
extern uint8_t ubl_cnt;
extern uint8_t ubl_cnt;
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#if ENABLED(ULTRA_LCD)
#if ENABLED(ULTRA_LCD)
extern char lcd_status_message[];
void lcd_quick_feedback();
#endif
#endif
#define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
#define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
typedef struct {
typedef struct {
bool active = false;
float z_offset = 0.0;
int8_t storage_slot = -1;
} ubl_state;
} ubl_state;
class unified_bed_leveling {
class unified_bed_leveling {
private:
static float last_specified_z;
@ -395,15 +390,8 @@
static bool prepare_segmented_line_to(const float ltarget[XYZE], const float &feedrate);
static void line_to_destination_cartesian(const float &fr, uint8_t e);
}; // class unified_bed_leveling
}; // class unified_bed_leveling
extern unified_bed_leveling ubl;
extern unified_bed_leveling ubl;
#if ENABLED(UBL_G26_MESH_VALIDATION)
FORCE_INLINE void gcode_G26() { ubl.G26(); }
#endif
FORCE_INLINE void gcode_G29() { ubl.G29(); }
#endif // AUTO_BED_LEVELING_UBL
#endif // UNIFIED_BED_LEVELING_H

View File

@ -20,21 +20,22 @@
*
*/
#include "MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "ubl.h"
#include "Marlin.h"
#include "hex_print_routines.h"
#include "configuration_store.h"
#include "ultralcd.h"
#include "stepper.h"
#include "planner.h"
#include "gcode.h"
#include "../../Marlin.h"
#include "../../libs/hex_print_routines.h"
#include "../../module/configuration_store.h"
#include "../../lcd/ultralcd.h"
#include "../../module/stepper.h"
#include "../../module/planner.h"
#include "../../gcode/parser.h"
#include "../../libs/least_squares_fit.h"
#include <math.h>
#include "least_squares_fit.h"
#define UBL_G29_P31

View File

@ -19,14 +19,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "Marlin.h"
#include "ubl.h"
#include "planner.h"
#include "stepper.h"
#include "../../Marlin.h"
#include "../../module/planner.h"
#include "../../module/stepper.h"
#include <math.h>
extern float destination[XYZE];