Misc. improvements (#12747)

* Make ExtUI respect MAXTEMP limits
  - Temperatures are now clamped by MAXTEMP limits rather than arbitrary values.
* Speed up USB init, add status
  - Speed up USB initialization
  - Show status message if init failed
* Enable status messages for EXTENSIBLE_UI
* Adjust max limit to MAX_TEMP - 15
* Misc. tweaks to formatting, const, etc.
This commit is contained in:
Marcio Teixeira
2019-01-01 14:17:48 -07:00
committed by Scott Lahteine
parent 4f2473053c
commit 60cb36bef3
12 changed files with 188 additions and 209 deletions

View File

@ -31,6 +31,10 @@
#include "Sd2Card_FlashDrive.h"
#if ENABLED(ULTRA_LCD) || ENABLED(EXTENSIBLE_UI)
#include "../../lcd/ultralcd.h"
#endif
USB usb;
BulkOnly bulk(&usb);
@ -46,25 +50,27 @@ void Sd2Card::idle() {
switch (state) {
case USB_HOST_DELAY_INIT:
next_retry = millis() + 10000;
next_retry = millis() + 2000;
state = USB_HOST_WAITING;
break;
case USB_HOST_WAITING:
if (ELAPSED(millis(), next_retry)) {
next_retry = millis() + 10000;
next_retry = millis() + 2000;
state = USB_HOST_UNINITIALIZED;
}
break;
case USB_HOST_UNINITIALIZED:
SERIAL_ECHOLNPGM("Starting USB host");
SERIAL_ECHOPGM("Starting USB host...");
if (!usb.start()) {
SERIAL_ECHOLNPGM("USB host failed to start. Will retry in 10 seconds.");
SERIAL_ECHOPGM(" Failed. Retrying in 2s.");
#if ENABLED(ULTRA_LCD) || ENABLED(EXTENSIBLE_UI)
LCD_MESSAGEPGM("USB start failed");
#endif
state = USB_HOST_DELAY_INIT;
}
else {
SERIAL_ECHOLNPGM("USB host initialized");
else
state = USB_HOST_INITIALIZED;
}
SERIAL_EOL();
break;
case USB_HOST_INITIALIZED:
const uint8_t lastUsbTaskState = usb.getUsbTaskState();
@ -91,10 +97,10 @@ void Sd2Card::idle() {
// This is equivalent to polling the SD_DETECT when using SD cards.
bool Sd2Card::isInserted() {
return usb.getUsbTaskState() == USB_STATE_RUNNING;
};
}
// Marlin calls this to initialize an SD card once it is inserted.
bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
bool Sd2Card::init(const uint8_t sckRateID/*=0*/, const pin_t chipSelectPin/*=SD_CHIP_SELECT_PIN*/) {
if (!ready()) return false;
if (!bulk.LUNIsGood(0)) {
@ -121,7 +127,7 @@ uint32_t Sd2Card::cardSize() {
#ifndef USB_DEBUG
const uint32_t
#endif
lun0_capacity = bulk.GetCapacity(0);
lun0_capacity = bulk.GetCapacity(0);
return lun0_capacity;
}

View File

@ -32,7 +32,6 @@
*/
//#define USB_DEBUG 1
#include "../SdFatConfig.h"
#include "../SdInfo.h"
@ -61,11 +60,11 @@
class Sd2Card {
private:
typedef enum {
USB_HOST_DELAY_INIT,
USB_HOST_WAITING,
typedef enum : uint8_t {
USB_HOST_UNINITIALIZED,
USB_HOST_INITIALIZED
USB_HOST_INITIALIZED,
USB_HOST_DELAY_INIT,
USB_HOST_WAITING
} state_t;
static state_t state;
@ -75,21 +74,20 @@ class Sd2Card {
uint32_t lun0_capacity;
#endif
static inline bool ready() {return state == USB_HOST_INITIALIZED;}
static inline bool ready() { return state == USB_HOST_INITIALIZED; }
public:
bool init(uint8_t sckRateID = 0, uint8_t chipSelectPin = SD_CHIP_SELECT_PIN);
bool init(const uint8_t sckRateID=0, const pin_t chipSelectPin=SD_CHIP_SELECT_PIN);
static void idle();
bool readStart(uint32_t block) { pos = block; return ready(); }
bool readData(uint8_t* dst) { return readBlock(pos++, dst); }
bool readStop() { return true; }
bool writeStart(uint32_t block, uint32_t eraseCount) { pos = block; return ready(); }
bool writeData(uint8_t* src) { return writeBlock(pos++, src); }
bool writeStop() { return true; }
inline bool readStart(const uint32_t block) { pos = block; return ready(); }
inline bool readData(uint8_t* dst) { return readBlock(pos++, dst); }
inline bool readStop() const { return true; }
inline bool writeStart(const uint32_t block, const uint32_t eraseCount) { UNUSED(eraseCount); pos = block; return ready(); }
inline bool writeData(uint8_t* src) { return writeBlock(pos++, src); }
inline bool writeStop() const { return true; }
bool readBlock(uint32_t block, uint8_t* dst);
bool writeBlock(uint32_t blockNumber, const uint8_t* src);