1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:16:27 +02:00

cngt/cngt.c: added small steps (default) and long steps (with shift)

This commit is contained in:
Werner Almesberger 2011-08-31 17:21:59 -03:00
parent eb8964da6f
commit 639d9a21df

View File

@ -13,14 +13,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include "serial.h" #include "serial.h"
#include "getkey.h" #include "getkey.h"
#define MAX_POS 10 #define MAX_POS 10
#define STEP 5 /* xy movement step, 5 mm */ #define STEP_XY 5 /* xy movement step, 5 mm */
#define STEP_Z 1 /* z movement step, 1 mm */ #define STEP_FINE_XY 0.5 /* xy movement fine step, 0.5 mm */
#define STEP_Z 1 /* z movement step, 1 mm */
#define STEP_FINE_Z 0.1 /* z movement step, 0.1 mm */
static double pos_x[MAX_POS]; static double pos_x[MAX_POS];
@ -56,20 +59,30 @@ static void down(void)
static int do_key(char c) static int do_key(char c)
{ {
double step_xy = STEP_FINE_XY;
double step_z = STEP_FINE_Z;
if (isupper(c)) {
step_xy = STEP_XY;
step_z = STEP_Z;
}
/* Anything but x/y positioning */ /* Anything but x/y positioning */
switch (c) { switch (c) {
case 'U':
case 'u': case 'u':
if (positioning) { if (positioning) {
cz += STEP_Z; cz += step_z;
move(); move();
} else { } else {
up(); up();
} }
return 0; return 0;
case 'D':
case 'd': case 'd':
if (positioning) { if (positioning) {
cz -= STEP_Z; cz -= step_z;
move(); move();
} else { } else {
down(); down();
@ -87,17 +100,21 @@ static int do_key(char c)
up(); up();
switch (c) { switch (c) {
case 'H':
case 'h': case 'h':
cx -= STEP; cx -= step_xy;
break; break;
case 'J':
case 'j': case 'j':
cy -= STEP; cy -= step_xy;
break; break;
case 'K':
case 'k': case 'k':
cy += STEP; cy += step_xy;
break; break;
case 'L':
case 'l': case 'l':
cx += STEP; cx += step_xy;
break; break;
default: default:
if (positioning) if (positioning)
@ -212,7 +229,10 @@ int main(int argc, char **argv)
if (positioning) if (positioning)
printf("%f %f %f\r\n", cx, cy, cz); printf("%f %f %f\r\n", cx, cy, cz);
} }
up();
if (!positioning)
up();
serial_close(); serial_close();
return 0; return 0;
} }