Skip to content

Commit

Permalink
followups
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 23, 2021
1 parent 2411f0b commit 3d81594
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/usb_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ uint8_t BulkStorage::Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t bl
}

uint8_t BulkStorage::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t * buf) {
return USBH_MSC_Write(&hUsbHost, lun, addr, const_cast <uint8_t*>(buf), blocks) != USBH_OK;
return USBH_MSC_Write(&hUsbHost, lun, addr, const_cast<uint8_t*>(buf), blocks) != USBH_OK;
}

#endif // USE_OTG_USB_HOST && USBHOST
Expand Down
19 changes: 9 additions & 10 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,17 @@ typedef float celsius_float_t;
typedef const float const_float_t;
#endif
typedef const_float_t const_feedRate_t;
typedef const_celsius_float_t const_float_t;

// Conversion macros
#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f)
#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f)
#define MMM_TO_MMS(MM_M) feedRate_t(static_cast<float>(MM_M) / 60.0f)
#define MMS_TO_MMM(MM_S) (static_cast<float>(MM_S) * 60.0f)

//
// Coordinates structures for XY, XYZ, XYZE...
//

// Helpers
#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f)
#define _RECIP(N) ((N) ? 1.0f / static_cast<float>(N) : 0.0f)
#define _ABS(N) ((N) < 0 ? -(N) : (N))
#define _LS(N) (N = (T)(uint32_t(N) << v))
#define _RS(N) (N = (T)(uint32_t(N) >> v))
Expand Down Expand Up @@ -216,8 +215,8 @@ struct XYval {
FI XYval<int32_t> asLong() const { return { int32_t(x), int32_t(y) }; }
FI XYval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
FI XYval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
FI XYval<float> asFloat() { return { float(x), float(y) }; }
FI XYval<float> asFloat() const { return { float(x), float(y) }; }
FI XYval<float> asFloat() { return { static_cast<float>(x), static_cast<float>(y) }; }
FI XYval<float> asFloat() const { return { static_cast<float>(x), static_cast<float>(y) }; }
FI XYval<float> reciprocal() const { return { _RECIP(x), _RECIP(y) }; }
FI XYval<float> asLogical() const { XYval<float> o = asFloat(); toLogical(o); return o; }
FI XYval<float> asNative() const { XYval<float> o = asFloat(); toNative(o); return o; }
Expand Down Expand Up @@ -327,8 +326,8 @@ struct XYZval {
FI XYZval<int32_t> asLong() const { return { int32_t(x), int32_t(y), int32_t(z) }; }
FI XYZval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
FI XYZval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
FI XYZval<float> asFloat() { return { float(x), float(y), float(z) }; }
FI XYZval<float> asFloat() const { return { float(x), float(y), float(z) }; }
FI XYZval<float> asFloat() { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) }; }
FI XYZval<float> asFloat() const { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) }; }
FI XYZval<float> reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z) }; }
FI XYZval<float> asLogical() const { XYZval<float> o = asFloat(); toLogical(o); return o; }
FI XYZval<float> asNative() const { XYZval<float> o = asFloat(); toNative(o); return o; }
Expand Down Expand Up @@ -438,8 +437,8 @@ struct XYZEval {
FI XYZEval<int32_t> asLong() const { return { int32_t(x), int32_t(y), int32_t(z), int32_t(e) }; }
FI XYZEval<int32_t> ROUNDL() { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
FI XYZEval<int32_t> ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
FI XYZEval<float> asFloat() { return { float(x), float(y), float(z), float(e) }; }
FI XYZEval<float> asFloat() const { return { float(x), float(y), float(z), float(e) }; }
FI XYZEval<float> asFloat() { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(e) }; }
FI XYZEval<float> asFloat() const { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(e) }; }
FI XYZEval<float> reciprocal() const { return { _RECIP(x), _RECIP(y), _RECIP(z), _RECIP(e) }; }
FI XYZEval<float> asLogical() const { XYZEval<float> o = asFloat(); toLogical(o); return o; }
FI XYZEval<float> asNative() const { XYZEval<float> o = asFloat(); toNative(o); return o; }
Expand Down
17 changes: 9 additions & 8 deletions Marlin/src/feature/probe_temp_comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,22 @@ void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const celsius
float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const celsius_t temp) {
const uint8_t measurements = cali_info[tsi].measurements;
const celsius_float_t start_temp = cali_info[tsi].start_temp,
res_temp = cali_info[tsi].temp_res;
res_temp = cali_info[tsi].temp_res
tempf = static_cast<celsius_float_t>(temp);
const int16_t * const data = sensor_z_offsets[tsi];

auto point = [&](uint8_t i) {
return xy_float_t({start_temp + i*res_temp, static_cast<float>(data[i])});
return xy_float_t({ start_temp + i * res_temp, static_cast<float>(data[i]) });
};

auto linear_interp = [](float x, xy_float_t p1, xy_float_t p2) {
auto linear_interp = [](const_float_t x, xy_float_t p1, xy_float_t p2) {
return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
};

// Linear interpolation
uint8_t idx = static_cast<uint8_t>((temp - start_temp) / res_temp);
uint8_t idx = static_cast<uint8_t>((tempf - start_temp) / res_temp);

// offset in um
// offset in µm
float offset = 0.0f;

#if !defined(PTC_LINEAR_EXTRAPOLATION) || PTC_LINEAR_EXTRAPOLATION <= 0
Expand All @@ -191,12 +192,12 @@ float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const ce
offset = static_cast<float>(data[measurements - 1]);
#else
if (idx < 0)
offset = linear_interp(temp, point(0), point(PTC_LINEAR_EXTRAPOLATION));
offset = linear_interp(tempf, point(0), point(PTC_LINEAR_EXTRAPOLATION));
else if (idx > measurements - 2)
offset = linear_interp(temp, point(measurements - PTC_LINEAR_EXTRAPOLATION - 1), point(measurements - 1));
offset = linear_interp(tempf, point(measurements - PTC_LINEAR_EXTRAPOLATION - 1), point(measurements - 1));
#endif
else
offset = linear_interp(temp, point(idx), point(idx + 1));
offset = linear_interp(tempf, point(idx), point(idx + 1));

// return offset in mm
return offset / 1000.0f;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/probe_temp_comp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ProbeTempComp {
*/
static float init_measurement;

static float get_offset_for_temperature(const TempSensorID tsi, const_celsius_float_t temp);
static float get_offset_for_temperature(const TempSensorID tsi, const celsius_t temp);

/**
* Fit a linear function in measured temperature offsets
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ enum ADCSensorState : char {
typedef struct TempInfo {
uint16_t acc;
int16_t raw;
celsius_float_t celsius;
celsius_t celsius;
inline void reset() { acc = 0; }
inline void sample(const uint16_t s) { acc += s; }
inline void update() { raw = acc; }
Expand Down Expand Up @@ -737,8 +737,8 @@ class Temperature {
FORCE_INLINE static int16_t rawProbeTemp() { return temp_probe.raw; }
#endif
FORCE_INLINE static celsius_t degProbe() { return temp_probe.celsius; }
FORCE_INLINE static bool isProbeBelowTemp(const_celsius_t target_temp) { return temp_probe.celsius < target_temp; }
FORCE_INLINE static bool isProbeAboveTemp(const_celsius_t target_temp) { return temp_probe.celsius > target_temp; }
FORCE_INLINE static bool isProbeBelowTemp(const celsius_t target_temp) { return temp_probe.celsius < target_temp; }
FORCE_INLINE static bool isProbeAboveTemp(const celsius_t target_temp) { return temp_probe.celsius > target_temp; }
static bool wait_for_probe(const celsius_t target_temp, bool no_wait_for_cooling=true);
#endif

Expand Down

0 comments on commit 3d81594

Please sign in to comment.