Subversion Repositories shark

Rev

Rev 1332 | Rev 1334 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed


/*
 * Project: S.Ha.R.K.
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
 * (see authors.txt for full list of hartik's authors)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/*
 * Copyright (C) 2000 Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "chimera.h"

/* Manual step increment */
#define INC_LEG         2

unsigned char   active_leg;

void pad(KEY_EVT *k)
{
        switch (k->scan) {
                case KEY_Z:
                        //sem_wait(&mx_status);
                        status.power ^= 1;
                        //sem_post(&mx_status);
                        break;
               
                case KEY_Q:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].pwm ^= 0x1;
                        //sem_post(&mx_status);
                        break;
                case KEY_W:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].pwm ^= 0x2;
                        //sem_post(&mx_status);
                        break;
                case KEY_E:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].pwm ^= 0x4;
                        //sem_post(&mx_status);
                        break;
               
                case KEY_U:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].x += INC_LEG;
                        if (status.leg[active_leg].x > POS_X_MAX) status.leg[active_leg].x = POS_X_MAX;
                        //sem_post(&mx_status);
                        break;
                case KEY_J:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].x -= INC_LEG;
                        if (status.leg[active_leg].x < POS_X_MIN) status.leg[active_leg].x = POS_X_MIN;
                        //sem_post(&mx_status);
                        break;
                case KEY_I:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].y += INC_LEG;
                        if (status.leg[active_leg].y > POS_Y_MAX) status.leg[active_leg].y = POS_Y_MAX;
                        //sem_post(&mx_status);
                        break;
                case KEY_K:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].y -= INC_LEG;
                        if (status.leg[active_leg].y < POS_Y_MIN) status.leg[active_leg].y = POS_Y_MIN;
                        //sem_post(&mx_status);
                        break;
                case KEY_O:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].z += INC_LEG;
                        if (status.leg[active_leg].z > POS_Z_MAX) status.leg[active_leg].z = POS_Z_MAX;
                        //sem_post(&mx_status);
                        break;
                case KEY_L:
                        //sem_wait(&mx_status);
                        status.leg[active_leg].z -= INC_LEG;
                        if (status.leg[active_leg].z < POS_Z_MIN) status.leg[active_leg].z = POS_Z_MIN;
                        //sem_post(&mx_status);
                        break;
                       
                case KEY_1:
                        active_leg = 0;
                        break;
                case KEY_2:
                        active_leg = 1;
                        break;
                case KEY_3:
                        active_leg = 2;
                        break;
                case KEY_4:
                        active_leg = 3;
                        break;
                case KEY_5:
                        active_leg = 4;
                        break;
                case KEY_6:
                        //active_leg = 5;
                        calibrate_step(100000);
                        break;
/*
                case KEY_C:
                        calibrate_init();
                        break;

                case KEY_A:
                        calibrate_step(-108000);
                        break;
                case KEY_S:
                        calibrate_step(-3600);
                        break;
                case KEY_D:
                        calibrate_step(-60);
                        break;
                case KEY_F:
                        calibrate_step(+60);
                        break;
                case KEY_G:
                        calibrate_step(+3600);
                        break;
                case KEY_H:
                        calibrate_step(+108000);
                        break;
*/

        }
}

void init_key()
{
        KEY_EVT k;

        /* Leg Selector */
        k.flag = 0;
        k.scan = KEY_1;
        k.ascii = '1';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_2;
        k.ascii = '2';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_3;
        k.ascii = '3';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_4;
        k.ascii = '4';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_5;
        k.ascii = '5';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_6;
        k.ascii = '6';
        keyb_hook(k,pad);

        /* Leg Position */
        k.flag = 0;
        k.scan = KEY_J;
        k.ascii = 'j';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_K;
        k.ascii = 'k';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_L;
        k.ascii = 'l';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_U;
        k.ascii = 'u';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_I;
        k.ascii = 'i';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_O;
        k.ascii = 'o';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_Q;
        k.ascii = 'q';
        keyb_hook(k,pad);
       
        k.flag = 0;
        k.scan = KEY_W;
        k.ascii = 'w';
        keyb_hook(k,pad);
       
        k.flag = 0;
        k.scan = KEY_E;
        k.ascii = 'e';
        keyb_hook(k,pad);
       
        k.flag = 0;
        k.scan = KEY_Z;
        k.ascii = 'z';
        keyb_hook(k,pad);


        k.flag = 0;
        k.scan = KEY_C;
        k.ascii = 'c';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_A;
        k.ascii = 'a';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_S;
        k.ascii = 's';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_D;
        k.ascii = 'd';
        keyb_hook(k,pad);
                                                                                                                             
        k.flag = 0;
        k.scan = KEY_F;
        k.ascii = 'f';
        keyb_hook(k,pad);

        k.flag = 0;
        k.scan = KEY_G;
        k.ascii = 'g';
        keyb_hook(k,pad);
                                                                                                                             
        k.flag = 0;
        k.scan = KEY_H;
        k.ascii = 'h';
        keyb_hook(k,pad);

}