Code tidying.
This commit is contained in:
parent
9ec28592e5
commit
fb2bbc0504
8 changed files with 202 additions and 166 deletions
|
@ -23,12 +23,10 @@ Licence: GPL
|
|||
#ifndef CONFIGURATION_H
|
||||
#define CONFIGURATION_H
|
||||
|
||||
class RepRap;
|
||||
class Platform;
|
||||
class Move;
|
||||
class Heat;
|
||||
class GCodes;
|
||||
class Webserver;
|
||||
#define NAME "RepRapFirmware"
|
||||
#define VERSION "0.1"
|
||||
#define DATE "2012-11-18"
|
||||
#define LAST_AUTHOR "reprappro.com"
|
||||
|
||||
#define ABS_ZERO -273.15
|
||||
|
||||
|
@ -49,7 +47,6 @@ class Webserver;
|
|||
|
||||
#define CLIENT_CLOSE_DELAY 1000 // Microseconds to wait after serving a page
|
||||
|
||||
|
||||
#define INDEX_PAGE "reprap.htm"
|
||||
#define PRINT_PAGE "print.php"
|
||||
#define MESSAGE_FILE "messages.txt"
|
||||
|
@ -60,4 +57,8 @@ class Webserver;
|
|||
#define POST_LENGTH 200
|
||||
#define START_FEED_RATE 200
|
||||
|
||||
// The axes etc in a GCode
|
||||
|
||||
#define GCODE_LETTERS {'X', 'Y', 'Z', 'E', 'F' }
|
||||
|
||||
#endif
|
||||
|
|
4
GCodes.h
4
GCodes.h
|
@ -22,6 +22,8 @@ Licence: GPL
|
|||
#ifndef GCODES_H
|
||||
#define GCODES_H
|
||||
|
||||
// Small class to hold an individual GCode
|
||||
|
||||
class GCodeBuffer
|
||||
{
|
||||
public:
|
||||
|
@ -40,6 +42,8 @@ class GCodeBuffer
|
|||
int readPointer;
|
||||
};
|
||||
|
||||
// The GCode interpreter
|
||||
|
||||
class GCodes
|
||||
{
|
||||
public:
|
||||
|
|
11
Move.ino
11
Move.ino
|
@ -55,24 +55,25 @@ void Move::Spin()
|
|||
|
||||
void Move::Qmove()
|
||||
{
|
||||
char scratchString[STRING_LENGTH];
|
||||
//char scratchString[STRING_LENGTH];
|
||||
if(!gCodes->ReadMove(nextMove))
|
||||
return;
|
||||
platform->Message(HOST_MESSAGE, "Move - got a move:");
|
||||
/* platform->Message(HOST_MESSAGE, "Move - got a move:");
|
||||
for(char i = 0; i <= DRIVES; i++)
|
||||
{
|
||||
ftoa(scratchString, nextMove[i], 3);
|
||||
platform->Message(HOST_MESSAGE, scratchString);
|
||||
platform->Message(HOST_MESSAGE, ", ");
|
||||
}
|
||||
platform->Message(HOST_MESSAGE, "\n");
|
||||
platform->Message(HOST_MESSAGE, "\n");*/
|
||||
|
||||
dda->Init(currentPosition, nextMove);
|
||||
boolean work = dda->Init(currentPosition, nextMove);
|
||||
|
||||
for(char i = 0; i <= AXES; i++)
|
||||
currentPosition[i] = nextMove[i];
|
||||
|
||||
dda->Start();
|
||||
if(work)
|
||||
dda->Start();
|
||||
}
|
||||
|
||||
void Move::GetCurrentState(float m[])
|
||||
|
|
113
Platform.h
113
Platform.h
|
@ -73,8 +73,6 @@ Licence: GPL
|
|||
#define DRIVE_STEPS_PER_UNIT {91.4286, 91.4286, 4000, 929}
|
||||
#define JERKS {15.0, 15.0, 0.4, 15.0} // (mm/sec)
|
||||
|
||||
#define GCODE_LETTERS {'X', 'Y', 'Z', 'E', 'F' }
|
||||
|
||||
// AXES
|
||||
|
||||
|
||||
|
@ -158,18 +156,16 @@ Licence: GPL
|
|||
|
||||
/****************************************************************************************************/
|
||||
|
||||
class RepRap;
|
||||
//class RepRap;
|
||||
|
||||
void TC3_Handler();
|
||||
|
||||
class Platform
|
||||
{
|
||||
public:
|
||||
|
||||
friend class Move;
|
||||
|
||||
Platform(RepRap* r);
|
||||
|
||||
RepRap* GetRepRap();
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// These are the functions that form the interface between Platform and the rest of the firmware.
|
||||
|
@ -191,7 +187,7 @@ class Platform
|
|||
|
||||
// Communications and data storage; opening something unsupported returns -1.
|
||||
|
||||
char* FileList(char* directory); // Returns a ;-separated list of all the files in the named directory (for example on an SD card).
|
||||
char* FileList(char* directory); // Returns a ,-separated list of all the files in the named directory (for example on an SD card).
|
||||
int OpenFile(char* fileName, boolean write); // Open a local file (for example on an SD card).
|
||||
void GoToEnd(int file); // Position the file at the end (so you can write on the end).
|
||||
boolean Read(int file, unsigned char& b); // Read a single byte from a file into b,
|
||||
|
@ -199,7 +195,7 @@ class Platform
|
|||
void WriteString(int file, char* s); // Write the string to a file.
|
||||
void Write(int file, char b); // Write the byte b to a file.
|
||||
unsigned long Length(int file); // File size in bytes
|
||||
char* GetWebDir(); // Where the php/htm etc files are
|
||||
char* GetWebDir(); // Where the htm etc files are
|
||||
char* GetGcodeDir(); // Where the gcodes are
|
||||
char* GetSysDir(); // Where the system files are
|
||||
char* GetTempDir(); // Where temporary files are
|
||||
|
@ -318,11 +314,6 @@ inline void Platform::Exit()
|
|||
active = false;
|
||||
}
|
||||
|
||||
inline RepRap* Platform::GetRepRap()
|
||||
{
|
||||
return reprap;
|
||||
}
|
||||
|
||||
// Where the htm etc files are
|
||||
|
||||
inline char* Platform::GetWebDir()
|
||||
|
@ -372,4 +363,98 @@ inline int Platform::GetRawTemperature(byte heater)
|
|||
return analogRead(tempSensePins[heater]);
|
||||
}
|
||||
|
||||
//*********************************************************************************************************
|
||||
|
||||
// Interrupts
|
||||
|
||||
|
||||
void Platform::InitialiseInterrupts()
|
||||
{
|
||||
pmc_set_writeprotect(false);
|
||||
pmc_enable_periph_clk((uint32_t)TC3_IRQn);
|
||||
TC_Configure(TC1, 0, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
|
||||
TC1->TC_CHANNEL[0].TC_IER=TC_IER_CPCS;
|
||||
TC1->TC_CHANNEL[0].TC_IDR=~TC_IER_CPCS;
|
||||
NVIC_DisableIRQ(TC3_IRQn);
|
||||
}
|
||||
|
||||
inline void Platform::SetInterrupt(long t)
|
||||
{
|
||||
if(t <= 0)
|
||||
{
|
||||
NVIC_DisableIRQ(TC3_IRQn);
|
||||
return;
|
||||
}
|
||||
uint32_t rc = (uint32_t)(t*84)/128;
|
||||
TC_SetRA(TC1, 0, rc/2); //50% high, 50% low
|
||||
TC_SetRC(TC1, 0, rc);
|
||||
TC_Start(TC1, 0);
|
||||
NVIC_EnableIRQ(TC3_IRQn);
|
||||
}
|
||||
|
||||
//***************************************************************************************
|
||||
|
||||
// Network connection
|
||||
|
||||
inline int Platform::ClientStatus()
|
||||
{
|
||||
return clientStatus;
|
||||
}
|
||||
|
||||
inline void Platform::SendToClient(unsigned char b)
|
||||
{
|
||||
if(client)
|
||||
{
|
||||
client.write(b);
|
||||
} else
|
||||
Message(HOST_MESSAGE, "Attempt to send byte to disconnected client.");
|
||||
}
|
||||
|
||||
inline unsigned char Platform::ClientRead()
|
||||
{
|
||||
if(client)
|
||||
return client.read();
|
||||
|
||||
Message(HOST_MESSAGE, "Attempt to read from disconnected client.");
|
||||
return '\n'; // good idea??
|
||||
}
|
||||
|
||||
inline void Platform::ClientMonitor()
|
||||
{
|
||||
clientStatus = 0;
|
||||
|
||||
if(!client)
|
||||
{
|
||||
client = server->available();
|
||||
if(!client)
|
||||
return;
|
||||
//else
|
||||
//Serial.println("new client");
|
||||
}
|
||||
|
||||
clientStatus |= CLIENT;
|
||||
|
||||
if(!client.connected())
|
||||
return;
|
||||
|
||||
clientStatus |= CONNECTED;
|
||||
|
||||
if (!client.available())
|
||||
return;
|
||||
|
||||
clientStatus |= AVAILABLE;
|
||||
}
|
||||
|
||||
inline void Platform::DisconnectClient()
|
||||
{
|
||||
if (client)
|
||||
{
|
||||
client.stop();
|
||||
//Serial.println("client disconnected");
|
||||
} else
|
||||
Message(HOST_MESSAGE, "Attempt to disconnect non-existent client.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
96
Platform.ino
96
Platform.ino
|
@ -52,6 +52,12 @@ void TC3_Handler()
|
|||
reprap.GetPlatform()->Interrupt();
|
||||
}
|
||||
|
||||
inline void Platform::Interrupt()
|
||||
{
|
||||
reprap->Interrupt(); // Put nothing else in this function
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency)
|
||||
{
|
||||
|
@ -69,97 +75,7 @@ void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency)
|
|||
}
|
||||
*/
|
||||
|
||||
void Platform::InitialiseInterrupts()
|
||||
{
|
||||
pmc_set_writeprotect(false);
|
||||
pmc_enable_periph_clk((uint32_t)TC3_IRQn);
|
||||
TC_Configure(TC1, 0, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
|
||||
TC1->TC_CHANNEL[0].TC_IER=TC_IER_CPCS;
|
||||
TC1->TC_CHANNEL[0].TC_IDR=~TC_IER_CPCS;
|
||||
NVIC_DisableIRQ(TC3_IRQn);
|
||||
}
|
||||
|
||||
inline void Platform::SetInterrupt(long t)
|
||||
{
|
||||
if(t <= 0)
|
||||
{
|
||||
NVIC_DisableIRQ(TC3_IRQn);
|
||||
return;
|
||||
}
|
||||
uint32_t rc = (uint32_t)(t*84)/128;
|
||||
TC_SetRA(TC1, 0, rc/2); //50% high, 50% low
|
||||
TC_SetRC(TC1, 0, rc);
|
||||
TC_Start(TC1, 0);
|
||||
NVIC_EnableIRQ(TC3_IRQn);
|
||||
}
|
||||
|
||||
inline void Platform::Interrupt()
|
||||
{
|
||||
reprap->Interrupt(); // Put nothing else in this function
|
||||
}
|
||||
|
||||
//***************************************************************************************
|
||||
|
||||
// Network connection
|
||||
|
||||
inline int Platform::ClientStatus()
|
||||
{
|
||||
return clientStatus;
|
||||
}
|
||||
|
||||
inline void Platform::SendToClient(unsigned char b)
|
||||
{
|
||||
if(client)
|
||||
{
|
||||
client.write(b);
|
||||
} else
|
||||
Message(HOST_MESSAGE, "Attempt to send byte to disconnected client.");
|
||||
}
|
||||
|
||||
inline unsigned char Platform::ClientRead()
|
||||
{
|
||||
if(client)
|
||||
return client.read();
|
||||
|
||||
Message(HOST_MESSAGE, "Attempt to read from disconnected client.");
|
||||
return '\n'; // good idea??
|
||||
}
|
||||
|
||||
inline void Platform::ClientMonitor()
|
||||
{
|
||||
clientStatus = 0;
|
||||
|
||||
if(!client)
|
||||
{
|
||||
client = server->available();
|
||||
if(!client)
|
||||
return;
|
||||
//else
|
||||
//Serial.println("new client");
|
||||
}
|
||||
|
||||
clientStatus |= CLIENT;
|
||||
|
||||
if(!client.connected())
|
||||
return;
|
||||
|
||||
clientStatus |= CONNECTED;
|
||||
|
||||
if (!client.available())
|
||||
return;
|
||||
|
||||
clientStatus |= AVAILABLE;
|
||||
}
|
||||
|
||||
inline void Platform::DisconnectClient()
|
||||
{
|
||||
if (client)
|
||||
{
|
||||
client.stop();
|
||||
//Serial.println("client disconnected");
|
||||
} else
|
||||
Message(HOST_MESSAGE, "Attempt to disconnect non-existent client.");
|
||||
}
|
||||
|
||||
|
||||
//*******************************************************************************************************************
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
RepRapFirmware - Main Include
|
||||
|
||||
This defines versions etc, includes all the other include files in the right order and defines the
|
||||
master RepRap class. No other definitions or information should be in here.
|
||||
This includes all the other include files in the right order and defines some globals.
|
||||
No other definitions or information should be in here.
|
||||
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -22,50 +22,16 @@ Licence: GPL
|
|||
#ifndef REPRAPFIRMWARE_H
|
||||
#define REPRAPFIRMWARE_H
|
||||
|
||||
// Warn of what's to come, so we can use pointers to classes...
|
||||
|
||||
#define NAME "RepRapFirmware"
|
||||
#define VERSION "0.1"
|
||||
#define DATE "2012-11-18"
|
||||
#define LAST_AUTHOR "reprappro.com"
|
||||
class Platform;
|
||||
class Webserver;
|
||||
class GCodes;
|
||||
class Move;
|
||||
class Heat;
|
||||
class RepRap;
|
||||
|
||||
#include "Configuration.h"
|
||||
#include "Platform.h"
|
||||
|
||||
class RepRap
|
||||
{
|
||||
public:
|
||||
|
||||
RepRap();
|
||||
void Init();
|
||||
void Spin();
|
||||
void Exit();
|
||||
void Interrupt();
|
||||
boolean debug();
|
||||
void debug(boolean d);
|
||||
Platform* GetPlatform();
|
||||
Move* GetMove();
|
||||
Heat* GetHeat();
|
||||
GCodes* GetGCodes();
|
||||
Webserver* GetWebserver();
|
||||
|
||||
private:
|
||||
|
||||
Platform* platform;
|
||||
boolean active;
|
||||
Move* move;
|
||||
Heat* heat;
|
||||
GCodes* gCodes;
|
||||
Webserver* webserver;
|
||||
boolean dbg;
|
||||
};
|
||||
|
||||
inline Platform* RepRap::GetPlatform() { return platform; }
|
||||
inline Move* RepRap::GetMove() { return move; }
|
||||
inline Heat* RepRap::GetHeat() { return heat; }
|
||||
inline GCodes* RepRap::GetGCodes() { return gCodes; }
|
||||
inline Webserver* RepRap::GetWebserver() { return webserver; }
|
||||
inline boolean RepRap::debug() { return dbg; }
|
||||
inline void RepRap::debug(boolean d) { dbg = d; }
|
||||
extern RepRap reprap;
|
||||
|
||||
// Functions and globals not part of any class
|
||||
|
||||
|
@ -75,12 +41,15 @@ boolean StringStartsWith(char* string, char* starting);
|
|||
boolean StringEquals(char* s1, char* s2);
|
||||
int StringContains(char* string, char* match);
|
||||
|
||||
#include "Configuration.h"
|
||||
#include "Platform.h"
|
||||
#include "Webserver.h"
|
||||
#include "GCodes.h"
|
||||
#include "Move.h"
|
||||
#include "Heat.h"
|
||||
#include "Reprap.h"
|
||||
|
||||
|
||||
extern RepRap reprap;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ RepRap reprap;
|
|||
|
||||
//*************************************************************************************************
|
||||
|
||||
// RepRap member functions.
|
||||
|
||||
// Do nothing more in the constructor; put what you want in RepRap:Init()
|
||||
|
||||
RepRap::RepRap()
|
||||
|
@ -99,11 +101,6 @@ void RepRap::Spin()
|
|||
}
|
||||
|
||||
|
||||
void RepRap::Interrupt()
|
||||
{
|
||||
move->Interrupt();
|
||||
}
|
||||
|
||||
//*************************************************************************************************
|
||||
|
||||
// Utilities and storage not part of any class
|
||||
|
|
63
Reprap.h
Normal file
63
Reprap.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/****************************************************************************************************
|
||||
|
||||
RepRapFirmware - Reprap
|
||||
|
||||
RepRap is a simple class that acts as a container for an instance of all the others.
|
||||
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
|
||||
Version 0.1
|
||||
|
||||
21 May 2013
|
||||
|
||||
Adrian Bowyer
|
||||
RepRap Professional Ltd
|
||||
http://reprappro.com
|
||||
|
||||
Licence: GPL
|
||||
|
||||
****************************************************************************************************/
|
||||
|
||||
#ifndef REPRAP_H
|
||||
#define REPRAP_H
|
||||
|
||||
class RepRap
|
||||
{
|
||||
public:
|
||||
|
||||
RepRap();
|
||||
void Init();
|
||||
void Spin();
|
||||
void Exit();
|
||||
void Interrupt();
|
||||
boolean debug();
|
||||
void debug(boolean d);
|
||||
Platform* GetPlatform();
|
||||
Move* GetMove();
|
||||
Heat* GetHeat();
|
||||
GCodes* GetGCodes();
|
||||
Webserver* GetWebserver();
|
||||
|
||||
private:
|
||||
|
||||
Platform* platform;
|
||||
boolean active;
|
||||
Move* move;
|
||||
Heat* heat;
|
||||
GCodes* gCodes;
|
||||
Webserver* webserver;
|
||||
boolean dbg;
|
||||
};
|
||||
|
||||
inline Platform* RepRap::GetPlatform() { return platform; }
|
||||
inline Move* RepRap::GetMove() { return move; }
|
||||
inline Heat* RepRap::GetHeat() { return heat; }
|
||||
inline GCodes* RepRap::GetGCodes() { return gCodes; }
|
||||
inline Webserver* RepRap::GetWebserver() { return webserver; }
|
||||
inline boolean RepRap::debug() { return dbg; }
|
||||
inline void RepRap::debug(boolean d) { dbg = d; }
|
||||
inline void RepRap::Interrupt() { move->Interrupt(); }
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in a new issue