Compare commits
1 commit
develop
...
velocity_c
| Author | SHA1 | Date | |
|---|---|---|---|
| 1016cc3abc |
5 changed files with 52 additions and 2 deletions
|
|
@ -1 +1 @@
|
|||
358
|
||||
363
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ typedef enum
|
|||
HPGL_Parser_ReceivingX,
|
||||
HPGL_Parser_ReceivingY,
|
||||
|
||||
// Receiving velocity value
|
||||
HPGL_Parser_ReceivingVelocity,
|
||||
|
||||
HPGL_Parser_Error,
|
||||
} HPGL_ParserState_t;
|
||||
|
||||
|
|
@ -45,6 +48,8 @@ void HPGL_Poll(void)
|
|||
|
||||
static bool waiting_for_movement_queue = false;
|
||||
|
||||
static unsigned char current_velocity = OUTPUT_DEFAULT_VELOCITY;
|
||||
|
||||
if(waiting_for_movement_queue)
|
||||
{
|
||||
if(!HPGL_EnqueueMovement(waiting_movement))
|
||||
|
|
@ -100,6 +105,7 @@ void HPGL_Poll(void)
|
|||
// Initialise
|
||||
HPGL_ParseErrorCounter = 0;
|
||||
// No parameters expected for this one
|
||||
current_velocity = OUTPUT_DEFAULT_VELOCITY;
|
||||
state = HPGL_Parser_Idle;
|
||||
break;
|
||||
|
||||
|
|
@ -111,6 +117,7 @@ void HPGL_Poll(void)
|
|||
case INST('P', 'U'):
|
||||
// Movement with pen up
|
||||
current_movement.pen_down = false;
|
||||
current_movement.velocity = current_velocity;
|
||||
current_movement.x = 0;
|
||||
current_movement.y = 0;
|
||||
state = HPGL_Parser_ReceivingX;
|
||||
|
|
@ -119,11 +126,24 @@ void HPGL_Poll(void)
|
|||
case INST('P', 'D'):
|
||||
// Movement with pen down
|
||||
current_movement.pen_down = true;
|
||||
current_movement.velocity = current_velocity;
|
||||
current_movement.x = 0;
|
||||
current_movement.y = 0;
|
||||
state = HPGL_Parser_ReceivingX;
|
||||
break;
|
||||
|
||||
case INST('V', 'N'):
|
||||
// Reset velocity to default
|
||||
current_velocity = OUTPUT_DEFAULT_VELOCITY;
|
||||
state = HPGL_Parser_Idle;
|
||||
break;
|
||||
|
||||
case INST('V', 'S'):
|
||||
// Velocity set
|
||||
current_velocity = 0;
|
||||
state = HPGL_Parser_ReceivingVelocity;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unsupported instruction
|
||||
HPGL_ParseErrorCounter++;
|
||||
|
|
@ -213,6 +233,25 @@ void HPGL_Poll(void)
|
|||
}
|
||||
break;
|
||||
|
||||
case HPGL_Parser_ReceivingVelocity:
|
||||
if(character == ';' || character == '\n')
|
||||
{
|
||||
// Command finished
|
||||
state = HPGL_Parser_Idle;
|
||||
}
|
||||
else if(character >= '0' && character <= '9')
|
||||
{
|
||||
unsigned int digit = character - '0';
|
||||
current_velocity = current_velocity * 10 + digit;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The VS command could come with a pen number after a comma.
|
||||
// This is currently unsupported.
|
||||
state = HPGL_Parser_Error;
|
||||
}
|
||||
break;
|
||||
|
||||
case HPGL_Parser_Error:
|
||||
// Exit error state only after end of command
|
||||
if(character == '\n' || character == ';')
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
typedef struct
|
||||
{
|
||||
bool pen_down;
|
||||
unsigned char velocity;
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
} HPGL_Movement_t;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ static Output_Coordinate_t Output_CurrentLineStart = {0, 0};
|
|||
static Output_Coordinate_t Output_CurrentLineEnd = {0, 0};
|
||||
static unsigned int Output_CurrentLineLength;
|
||||
static unsigned int Output_CurrentLinePosition;
|
||||
static unsigned int Output_CurrentVelocity = OUTPUT_LENGTH_SCALE / 3;
|
||||
static unsigned int Output_CurrentVelocity = OUTPUT_DEFAULT_VELOCITY;
|
||||
|
||||
bool Output_EnqueueMovement(HPGL_Movement_t movement)
|
||||
{
|
||||
|
|
@ -52,6 +52,10 @@ bool Output_EnqueueMovement(HPGL_Movement_t movement)
|
|||
{
|
||||
movement.y = OUTPUT_COORDINATE_LIMIT;
|
||||
}
|
||||
if(movement.velocity > OUTPUT_MAXIMUM_VELOCITY)
|
||||
{
|
||||
movement.velocity = OUTPUT_MAXIMUM_VELOCITY;
|
||||
}
|
||||
|
||||
memcpy(Output_BufferWrite, &movement, sizeof(HPGL_Movement_t));
|
||||
Output_BufferWrite++;
|
||||
|
|
@ -128,6 +132,7 @@ static bool Output_FetchNextPoint(void)
|
|||
Output_CurrentLineEnd.x - Output_CurrentLineStart.x,
|
||||
Output_CurrentLineEnd.y - Output_CurrentLineStart.y);
|
||||
Output_CurrentLinePosition = 0;
|
||||
Output_CurrentVelocity = movement->velocity;
|
||||
|
||||
Output_BufferRead++;
|
||||
if(Output_BufferRead >= Output_Buffer + CONFIG_BUFFER_MOVEMENTS)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@
|
|||
// overflows during coordinate calculations.
|
||||
#define OUTPUT_LENGTH_SCALE (1 << 3)
|
||||
|
||||
// If no velocity is sett via a ‘VS’ command or ‘VN’ is invoked, use this
|
||||
// velocity setting
|
||||
#define OUTPUT_DEFAULT_VELOCITY (OUTPUT_LENGTH_SCALE / 3)
|
||||
#define OUTPUT_MAXIMUM_VELOCITY (OUTPUT_LENGTH_SCALE) // TODO: Check value
|
||||
|
||||
// Delay after initiating pen-up/-down before continuing movements
|
||||
#define OUTPUT_PEN_UP_DELAY 200 // In movement timer ticks
|
||||
#define OUTPUT_PEN_DOWN_DELAY 20 // In movement timer ticks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue