Some refactoring

coil_winder
Marcin K 2017-02-19 19:15:53 +01:00
rodzic cbeec817b6
commit 62f2a4871b
6 zmienionych plików z 33 dodań i 27 usunięć

Wyświetl plik

@ -9,8 +9,8 @@
//#define RXD1 DIO7
//#define TXD1 DIO8
// ATmega32U4 doesn't have a serial port 0, maybe its a USB?
// do some munging of port 0 to port 1 the help serial.c
// do some munging of serial port
#define UCSR0A UCSRA
#define U2X0 U2X
#define UBRR0 UBRRL

Wyświetl plik

@ -154,7 +154,6 @@
#define ENCODER_PIN 17
#define PWR_OUT1_PIN 18
#define PWR_OUT2_PIN 19
#define ANALOG_IN_PIN 33
@ -180,12 +179,6 @@
#define F_CPU 16000000UL
#endif
/** \def MOTHERBOARD
This is the motherboard, as opposed to the extruder. See extruder/ directory
for GEN3 extruder firmware.
*/
#define MOTHERBOARD
/** \def DEBUG_LED_PIN
Enable flashing of a LED during motor stepping.
@ -197,6 +190,7 @@
http://reprap.org/wiki/Teacup_Firmware#Doing_precision_profiling
*/
#define DEBUG_LED_PIN PC1
////////////////DEBUG/////////////////////
#define SIMINFO
#define DEBUG

Wyświetl plik

@ -8,18 +8,26 @@
#define IS_ENDING(c) (c == '\n' || c == '\r')
#define ATOI(c) (c - '0')
#define STATE_ERROR 1
GCODE_PARAM params[8];
uint8_t current_parameter;
TARGET next_target;
// Parser is implemented as a finite state automata (DFA)
// This is pointer holds function with actions expected for current progress, each of these functions
// changes its value on state change
uint8_t (*current_state)(uint8_t c);
//a few state functions prototypes
uint8_t start_parsing_parameter(uint8_t );
uint8_t start_parse_number(uint8_t);
uint8_t start_parsing_number(uint8_t);
/// convert a floating point input value into an integer with appropriate scaling.
/// \param *df pointer to floating point structure that holds fp value to convert
/// \param mantissa the actual digits of our floating point number
/// \param exponent scale mantissa by \f$10^{-exponent}\f$
/// \param sign positive or negative?
/// \param multiplicand multiply by this amount during conversion to integer
///
/// Tested for up to 42'000 mm (accurate), 420'000 mm (precision 10 um) and
@ -65,7 +73,7 @@ void parser_init()
next_target.f_multiplier = 256;
parser_reset();
}
// this function executes command after is parsed
void process_command()
{
for(int i = 1; i <= current_parameter; ++i)
@ -100,11 +108,12 @@ void process_command()
}
}
uint8_t gcode_error(uint8_t c)
uint8_t gcode_syntax_error(uint8_t c)
{
if IS_ENDING(c)
parser_reset();
return 1;
return STATE_ERROR;
}
uint8_t start_parsing_parameter(uint8_t c)
@ -120,11 +129,11 @@ uint8_t start_parsing_parameter(uint8_t c)
if IS_LETTER(c)
{
params[current_parameter].name = c;
current_state = start_parse_number;
current_state = start_parsing_number;
return 0;
}
current_state = gcode_error;
return 1;
current_state = gcode_syntax_error;
return STATE_ERROR;
}
uint8_t parse_digit(uint8_t c)
@ -161,11 +170,11 @@ uint8_t parse_digit(uint8_t c)
return 0;
}
current_state = gcode_error;
return 1;
current_state = gcode_syntax_error;
return STATE_ERROR;
}
uint8_t start_parse_number(uint8_t c)
uint8_t start_parsing_number(uint8_t c)
{
current_state = parse_digit;
//negative number
@ -179,8 +188,8 @@ uint8_t start_parse_number(uint8_t c)
parse_digit(c);
return 0;
}
current_state = gcode_error;
return 1;
current_state = gcode_syntax_error;
return STATE_ERROR;
}
uint8_t gcode_parse_char(uint8_t c) {
@ -192,7 +201,7 @@ uint8_t gcode_parse_char(uint8_t c) {
if IS_ENDING(c)
{
if ( result == 1) //error
if ( result == STATE_ERROR) //error
return 2;
return 1;
}

Wyświetl plik

@ -18,6 +18,7 @@ extern const uint32_t powers[]; // defined in msg.c
/// accept the next character and process it
uint8_t gcode_parse_char(uint8_t c);
/// setup variables
void parser_init();
#endif /* _GCODE_PARSE_H */

Wyświetl plik

@ -4,7 +4,6 @@
#include "config.h"
#include <stdint.h>
#include "motor.h"

Wyświetl plik

@ -15,9 +15,12 @@
#include "config.h"
#include "pinio.h"
//#include "clock.h"
//#include "cpu.h"
//#include "memory_barrier.h"
/** \def MOTHERBOARD
This is the motherboard, as opposed to the extruder. See extruder/ directory
for GEN3 extruder firmware.
*/
#define MOTHERBOARD
#ifdef MOTHERBOARD
#include "queue.h"