// // On my system, this program can be compiled into a userspace HAL component // with the command: // gcc test.c -DULAPI -I/usr/src/emc2/include -L/usr/src/emc2/lib -lemchal // //#include #include #include #include #include #include struct data { hal_bit_t *b; } *data; int comp_id; static void siginthand(int sig); int main(void) { int result; signal(SIGINT,siginthand); comp_id = hal_init("pphid"); if(comp_id < 0) exit(1); data = hal_malloc(sizeof(struct data)); result = hal_pin_bit_new("pphid.bit",HAL_OUT,&data->b,comp_id); if(result < 0) { hal_exit(comp_id); exit(1); } hal_ready(comp_id); printf("Hello\nstarting...\n"); while(1) { printf("Getting pin data\n"); *data->b = !*data->b; system("echo -ne \"\\007\""); printf("Sleeping for 5 sec...\n"); sleep(1); //printf("Pin says: %d",*data->b); //getch(); } hal_exit(comp_id); } static void siginthand(int sig) { hal_exit(comp_id); exit(0); }