static int control__close(struct hw_device_t *dev) { struct sensors_control_context_t* ctx = (struct sensors_control_context_t*)dev; if (ctx) { close_akm(ctx); close_cm(ctx); close_ls(ctx); free(ctx); } return 0; }
void* azelComm(void* arg) { int ser_attempts = 0; // number of attempts to open port int init_attempts = 0; // number of attempts to initialize motor nameThread("AzEl"); bprintf(startup, "Starting serial thread for motors."); /* initialize values in the motor info structs */ azinfo.fd = 0; azinfo.open = 0; azinfo.init = 0; azinfo.closing = 0; //azinfo.ref = az_enc; strncpy(azinfo.motorstr, "az", 3); elinfo.fd = 0; elinfo.open = 0; elinfo.init = 0; elinfo.closing = 0; //elinfo.ref = el_enc; strncpy(elinfo.motorstr, "el", 3); /* try to open the ports */ while (azinfo.open == 0) { open_cm(AZ_DEVICE, &azinfo); if (ser_attempts == 10) { bputs(err, "Unable to open az motor port after 10 attempts.\n"); } ser_attempts++; if (azinfo.open == 1) { bprintf(info, "Opened the az motor port on attempt %i", ser_attempts); } else sleep(1); } ser_attempts = 0; while (elinfo.open == 0) { open_cm(EL_DEVICE, &elinfo); if (ser_attempts == 10) { bputs(err, "Unable to open el motor port after 10 attempts.\n"); } ser_attempts++; if (elinfo.open == 1) { bprintf(info, "Opened the el motor port on attempt %i", ser_attempts); } else sleep(1); } /* initialize motor internal parameters */ bprintf(info, "Initializing az motor"); while (azinfo.init == 0) { init_cm(&azinfo); if (init_attempts == 10) { bputs(err, "Could not initalize the az motor after 10 attempts.\n"); } init_attempts++; if (azinfo.init == 1) { bprintf(info, "Initialized the az motor on attempt %i", init_attempts); } else sleep(1); } init_attempts = 0; bprintf(info, "Initializing el motor"); while (elinfo.init == 0) { init_cm(&elinfo); if (init_attempts == 10) { bputs(err, "Could not initalize the el motor after 10 attempts.\n"); } init_attempts++; if (elinfo.init == 1) { bprintf(info, "Initialized the el motor on attempt %i", init_attempts); } else sleep(1); } while (1) { /* TODO: NEED SOME KIND OF CHECKING OF ERROR STATES HERE */ if (azinfo.closing == 1) { close_cm(&azinfo); usleep(10000); } if (elinfo.closing == 1) { close_cm(&elinfo); usleep(10000); } else { AzElScan(); usleep(10000); /* TODO - sjb: probably want, "too many errors, reconnecting logic here */ } } return NULL; }