/* * main.c * * Created: 29/09/2012 2:13:52 AM * Author: mdryden */ #include "main.h" //Internal global variables int16_t p1, p2, p3, p4; uint16_t u1, u2, u3, u4; uint8_t p5, o1, o2, o3; //uint16_t step_dac[50], step_seconds[50]; //Internal function declarations int8_t command_handler(char command); int8_t command_handler(char command){ /** * Deals with commands over USB * * Calls functions in * @param command Command character input. */ int16_t pcv1, pcv2; uint16_t pct1, pct2; switch (command){ case 'A': //ADS Buffer/rate/PGA values from ads1255.h scanf("%hhx%hhx%hhx",&o1,&o2,&o3); printf("#A: %x %x %x\r\n",o1,o2,o3); ads1255_setup(o1, o2, o3); break; case 'G': //Gain - start gain, autogain on/off, (min gain, max gain), low/high switch thresholds //scanf("%1u%1u%7li%7li",&g_gain,&autogain_enable,&overcurrent_threshold,&undercurrent_threshold); scanf("%u",&g_gain); printf("#G: %u\r\n", g_gain); pot_set_gain(); //uses global g_gain, so no params break; case 'L': //LSV - start, stop, slope scanf("%u%u%i%i%i%i%u",&pct1,&pct2,&pcv1,&pcv2,&p1,&p2,&u1); precond(pcv1,pct1,pcv2,pct2); lsv_experiment(p1,p2,u1,2); break; case 'C': //CV - v1, v2, start, scans, slope scanf("%u%u%i%i%i%i%i%hhu%u",&pct1,&pct2,&pcv1,&pcv2,&p1,&p2,&p3,&p5,&u1); precond(pcv1,pct1,pcv2,pct2); cv_experiment(p1,p2,p3,p5,u1); break; case 'S': //SWV - start, stop, step size, pulse_height, frequency, scans scanf("%u%u%i%i%i%i%u%u%u%u",&pct1,&pct2,&pcv1,&pcv2,&p1,&p2,&u1,&u2,&u3,&u4); precond(pcv1,pct1,pcv2,pct2); swv_experiment(p1,p2,u1,u2,u3,u4); break; case 'D': //DPV - start, stop, step size, pulse_height, period, width scanf("%u%u%i%i%i%i%u%u%u%u",&pct1,&pct2,&pcv1,&pcv2,&p1,&p2,&u1,&u2,&u3,&u4); precond(pcv1,pct1,pcv2,pct2); dpv_experiment(p1,p2,u1,u2,u3,u4); break; #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 case 'P': //potentiometry - time, OCP/poteniometry scanf("%u%hhu",&pct1, &o1); pot_experiment(pct1, o1); break; #endif case 'R': //CA - steps, step_dac[], step_seconds[] scanf("%hhu",&p5); //get number of steps printf("#Steps: %u\n\r", p5); //allocate arrays for steps uint16_t * step_dac = malloc(p5*sizeof(uint16_t)); uint16_t * step_seconds = malloc(p5*sizeof(uint16_t)); //check for successful allocation if (!step_dac || !step_seconds){ printf("#ERR: Could not allocate memory\n\r"); break; } uint8_t i; for (i=0; i