Skip to content

Commit

Permalink
Add cancel option to SD card build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Mets committed Mar 29, 2011
1 parent 6924da4 commit ef81899
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 152 deletions.
97 changes: 87 additions & 10 deletions v2/src/Motherboard/Host.cc
Expand Up @@ -27,7 +27,9 @@
#include <avr/eeprom.h>
#include "Main.hh"
#include "Errors.hh"
#include "SDCard.hh"
#include "EepromMap.hh"

namespace host {

/// Identify a command packet, and process it. If the packet is a command
/// packet, return true, indicating that the packet has been queued and no
Expand All @@ -45,7 +47,15 @@ Timeout packet_in_timeout;
#define HOST_TOOL_RESPONSE_TIMEOUT_MS 50
#define HOST_TOOL_RESPONSE_TIMEOUT_MICROS (1000L*HOST_TOOL_RESPONSE_TIMEOUT_MS)

bool do_host_reset = false;
char machineName[MAX_MACHINE_NAME_LEN];

char buildName[MAX_FILE_LEN];

uint32_t buildSteps;

HostState currentState;

bool do_host_reset = true;

void runHostSlice() {
InPacket& in = Motherboard::getBoard().getHostUART().in;
Expand All @@ -60,7 +70,10 @@ void runHostSlice() {
reset(false);
packet_in_timeout.abort();

// TODO: Reset the extruder board.
// Clear the machine and build names
machineName[0] = 0;
buildName[0] = 0;
currentState = HOST_STATE_READY;

return;
}
Expand Down Expand Up @@ -146,8 +159,8 @@ inline void handleVersion(const InPacket& from_host, OutPacket& to_host) {
inline void handleGetBuildName(const InPacket& from_host, OutPacket& to_host) {
to_host.append8(RC_OK);
for (uint8_t idx = 0; idx < 31; idx++) {
to_host.append8(build_name[idx]);
if (build_name[idx] == '\0') { break; }
to_host.append8(buildName[idx]);
if (buildName[idx] == '\0') { break; }
}
}

Expand Down Expand Up @@ -215,14 +228,14 @@ inline void handleEndCapture(const InPacket& from_host, OutPacket& to_host) {
}

inline void handlePlayback(const InPacket& from_host, OutPacket& to_host) {
const int MAX_FILE_LEN = MAX_PACKET_PAYLOAD-1;
to_host.append8(RC_OK);
char fnbuf[MAX_FILE_LEN];
for (int idx = 1; idx < from_host.getLength(); idx++) {
fnbuf[idx-1] = from_host.read8(idx);
buildName[idx-1] = from_host.read8(idx);
}
fnbuf[MAX_FILE_LEN-1] = '\0';
to_host.append8(sdcard::startPlayback(fnbuf));
buildName[MAX_FILE_LEN-1] = '\0';

uint8_t response = startBuildFromSD();
to_host.append8(response);
}

inline void handleNextFilename(const InPacket& from_host, OutPacket& to_host) {
Expand Down Expand Up @@ -381,6 +394,21 @@ inline void handleExtendedStop(const InPacket& from_host, OutPacket& to_host) {
to_host.append8(0);
}

inline void handleBuildStartNotification(const InPacket& from_host, OutPacket& to_host) {
uint8_t flags = from_host.read8(1);

buildSteps = from_host.read32(1);

for (int idx = 4; idx < from_host.getLength(); idx++) {
buildName[idx-4] = from_host.read8(idx);
}
buildName[MAX_FILE_LEN-1] = '\0';

currentState = HOST_STATE_BUILDING;

to_host.append8(RC_OK);
}

bool processQueryPacket(const InPacket& from_host, OutPacket& to_host) {
if (from_host.getLength() >= 1) {
uint8_t command = from_host.read8(0);
Expand Down Expand Up @@ -446,8 +474,57 @@ bool processQueryPacket(const InPacket& from_host, OutPacket& to_host) {
case HOST_CMD_EXTENDED_STOP:
handleExtendedStop(from_host,to_host);
return true;
case HOST_CMD_BUILD_START_NOTIFICATION:
handleBuildStartNotification(from_host,to_host);
return true;
}
}
}
return false;
}

char* getMachineName() {
if (machineName[0] == 0) {
for(uint8_t i = 0; i < MAX_MACHINE_NAME_LEN; i++) {
machineName[i] = eeprom::getEeprom8(eeprom::MACHINE_NAME+i, 0);
}
}
return machineName;
}

char* getBuildName() {

// buildName[0] = 't';
// buildName[1] = 'e';
// buildName[2] = 's';
// buildName[3] = 't';
// buildName[4] = 0;
return buildName;
}

HostState getHostState() {
return currentState;
}

// Start a build from SD, if possible.
sdcard::SdErrorCode startBuildFromSD() {
sdcard::SdErrorCode e;

// Attempt to start build
e = sdcard::startPlayback(buildName);
if (e != sdcard::SD_SUCCESS) {
// TODO: report error
return e;
}

currentState = HOST_STATE_BUILDING_FROM_SD;

return e;
}

// Stop the current build, if any
void stopBuild() {
do_host_reset = true; // indicate reset after response has been sent
}

}
31 changes: 31 additions & 0 deletions v2/src/Motherboard/Host.hh
Expand Up @@ -19,7 +19,38 @@
#define HOST_HH_

#include "Packet.hh"
#include "SDCard.hh"

namespace host {

const int MAX_MACHINE_NAME_LEN = 32;
const int MAX_FILE_LEN = MAX_PACKET_PAYLOAD-1;

void runHostSlice();

enum HostState {
HOST_STATE_READY = 0,
HOST_STATE_BUILDING = 1,
HOST_STATE_BUILDING_FROM_SD = 2,
HOST_STATE_ERROR = 3,
};

// Returns the name of the current machine
char* getMachineName();

//Returns the name of the current build, if any.
char* getBuildName();

// Returns the current host state
HostState getHostState();

// Start a build from SD, if possible.
// Returns true if build started successfully, false otherwise
sdcard::SdErrorCode startBuildFromSD();

// Stop the current build, if any
void stopBuild();

}

#endif // HOST_HH_
2 changes: 1 addition & 1 deletion v2/src/Motherboard/Main.cc
Expand Up @@ -60,7 +60,7 @@ int main() {
// Toolhead interaction thread.
tool::runToolSlice();
// Host interaction thread.
runHostSlice();
host::runHostSlice();
// Command handling thread.
command::runCommandSlice();
// Motherboard slice
Expand Down
10 changes: 10 additions & 0 deletions v2/src/Motherboard/boards/mb24/InterfaceBoard.cc
Expand Up @@ -70,6 +70,8 @@ class InterfaceBoard {

void popScreen();

micros_t getUpdateRate();

void doUpdate();
};

Expand Down Expand Up @@ -169,6 +171,10 @@ void InterfaceBoard::doInterrupt() {
buttons.scanButtons();
}

micros_t InterfaceBoard::getUpdateRate() {
return screenStack[screenIndex]->getUpdateRate();
}

void InterfaceBoard::doUpdate() {
InterfaceBoardDefinitions::ButtonName button;

Expand Down Expand Up @@ -214,6 +220,10 @@ void doInterrupt() {
board.doInterrupt();
}

micros_t getUpdateRate() {
return board.getUpdateRate();
}

void doUpdate() {
board.doUpdate();
}
Expand Down
2 changes: 2 additions & 0 deletions v2/src/Motherboard/boards/mb24/InterfaceBoard.hh
Expand Up @@ -23,6 +23,8 @@ void doInterrupt();

void doUpdate();

micros_t getUpdateRate();

}

#endif
32 changes: 30 additions & 2 deletions v2/src/Motherboard/boards/mb24/LiquidCrystal.cc
Expand Up @@ -260,9 +260,37 @@ inline void LiquidCrystal::write(uint8_t value) {
}


void LiquidCrystal::write_from_pgmspace(const prog_uchar message[]) {
void LiquidCrystal::writeInt(uint16_t value, uint8_t digits) {

uint16_t currentDigit;
uint16_t nextDigit;

switch (digits) {
case 1: currentDigit = 10; break;
case 2: currentDigit = 100; break;
case 3: currentDigit = 1000; break;
case 4: currentDigit = 10000; break;
default: return;
}

for (uint8_t i = 0; i < digits; i++) {
nextDigit = currentDigit/10;
write((value%currentDigit)/nextDigit+'0');
currentDigit = nextDigit;
}
}


void LiquidCrystal::writeString(char message[]) {
char* letter = message;
while (*letter != 0) {
write(*letter);
letter++;
}
}

void LiquidCrystal::writeFromPgmspace(const prog_uchar message[]) {
char letter;
if(!message) return;
while (letter = pgm_read_byte(message++)) {
write(letter);
}
Expand Down
7 changes: 6 additions & 1 deletion v2/src/Motherboard/boards/mb24/LiquidCrystal.hh
Expand Up @@ -85,9 +85,14 @@ public:
virtual void write(uint8_t);

/** Added by MakerBot Industries to support storing strings in flash **/
void write_from_pgmspace(const prog_uchar message[]);
void writeInt(uint16_t value, uint8_t digits);

void writeString(char message[]);

void writeFromPgmspace(const prog_uchar message[]);

void command(uint8_t);

private:
void send(uint8_t, bool);
void write4bits(uint8_t);
Expand Down

0 comments on commit ef81899

Please sign in to comment.