void t7(int pi) { int c, oc, id; printf("Watchdog tests.\n"); /* type of edge shouldn't matter for watchdogs */ id = callback(pi, GPIO, FALLING_EDGE, t7cbf); set_watchdog(pi, GPIO, 50); /* 50 ms, 20 per second */ time_sleep(0.5); oc = t7_count; time_sleep(2); c = t7_count - oc; CHECK(7, 1, c, 39, 5, "set watchdog on count"); set_watchdog(pi, GPIO, 0); /* 0 switches watchdog off */ time_sleep(0.5); oc = t7_count; time_sleep(2); c = t7_count - oc; CHECK(7, 2, c, 0, 1, "set watchdog off count"); callback_cancel(id); }
void t6(int pi) { int tp, t, p, id; printf("Trigger tests.\n"); gpio_write(pi, GPIO, PI_LOW); tp = 0; id = callback(pi, GPIO, EITHER_EDGE, t6cbf); time_sleep(0.2); for (t=0; t<5; t++) { time_sleep(0.1); p = 10 + (t*10); tp += p; gpio_trigger(pi, GPIO, p, 1); } time_sleep(0.5); CHECK(6, 1, t6_count, 5, 0, "gpio trigger count"); CHECK(6, 2, t6_on, tp, 25, "gpio trigger pulse length"); callback_cancel(id); }
void t3(int pi) { int pw[3]={500, 1500, 2500}; int dc[4]={20, 40, 60, 80}; int f, rr, v; float on, off; int t, id; printf("PWM/Servo pulse accuracy tests.\n"); id = callback(pi, GPIO, EITHER_EDGE, t3cbf); for (t=0; t<3; t++) { set_servo_pulsewidth(pi, GPIO, pw[t]); v = get_servo_pulsewidth(pi, GPIO); CHECK(3, t+t+1, v, pw[t], 0, "get servo pulsewidth"); time_sleep(1); t3_reset = 1; time_sleep(4); on = t3_on; off = t3_off; CHECK(3, t+t+2, (1000.0*(on+off))/on, 20000000.0/pw[t], 1, "set servo pulsewidth"); } set_servo_pulsewidth(pi, GPIO, 0); set_PWM_frequency(pi, GPIO, 1000); f = get_PWM_frequency(pi, GPIO); CHECK(3, 7, f, 1000, 0, "set/get PWM frequency"); rr = set_PWM_range(pi, GPIO, 100); CHECK(3, 8, rr, 200, 0, "set PWM range"); for (t=0; t<4; t++) { set_PWM_dutycycle(pi, GPIO, dc[t]); v = get_PWM_dutycycle(pi, GPIO); CHECK(3, t+t+9, v, dc[t], 0, "get PWM dutycycle"); time_sleep(1); t3_reset = 1; time_sleep(2); on = t3_on; off = t3_off; CHECK(3, t+t+10, (1000.0*on)/(on+off), 10.0*dc[t], 1, "set PWM dutycycle"); } set_PWM_dutycycle(pi, GPIO, 0); callback_cancel(id); }
static void servoInOnExit(void) { printf("Disconnecting Servos Input ...\n"); // cancel any registered callbacks for(uint32_t i = 0; i < gpioInputCount; i++) { callback_cancel(inputCallbackIds[i]); } if(isDaemonStarted) { // disconnect from the daemon if still running pigpio_stop(); isDaemonStarted = false; } }
int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout) { int triggered = 0; int id; double due; if (timeout <= 0.0) return 0; due = time_time() + timeout; id = callback_ex(user_gpio, edge, _wfe, &triggered); while (!triggered && (time_time() < due)) time_sleep(0.1); callback_cancel(id); return triggered; }
int wait_for_edge(int pi, unsigned user_gpio, unsigned edge, double timeout) { int triggered = 0; int id; double due; if ((pi < 0) || (pi >= MAX_PI) || !gPiInUse[pi]) return pigif_unconnected_pi; if (timeout <= 0.0) return 0; due = time_time() + timeout; id = callback_ex(pi, user_gpio, edge, _wfe, &triggered); while (!triggered && (time_time() < due)) time_sleep(0.05); callback_cancel(id); return triggered; }
void t2(int pi) { int dc, f, r, rr, oc, id; printf("PWM dutycycle/range/frequency tests.\n"); set_PWM_range(pi, GPIO, 255); set_PWM_frequency(pi, GPIO, 0); f = get_PWM_frequency(pi, GPIO); CHECK(2, 1, f, 10, 0, "set PWM range, set/get PWM frequency"); id = callback(pi, GPIO, EITHER_EDGE, t2cb); set_PWM_dutycycle(pi, GPIO, 0); dc = get_PWM_dutycycle(pi, GPIO); CHECK(2, 2, dc, 0, 0, "get PWM dutycycle"); time_sleep(0.5); /* allow old notifications to flush */ oc = t2_count; time_sleep(2); f = t2_count - oc; CHECK(2, 3, f, 0, 0, "set PWM dutycycle, callback"); set_PWM_dutycycle(pi, GPIO, 128); dc = get_PWM_dutycycle(pi, GPIO); CHECK(2, 4, dc, 128, 0, "get PWM dutycycle"); time_sleep(0.2); oc = t2_count; time_sleep(2); f = t2_count - oc; CHECK(2, 5, f, 40, 5, "set PWM dutycycle, callback"); set_PWM_frequency(pi, GPIO, 100); f = get_PWM_frequency(pi, GPIO); CHECK(2, 6, f, 100, 0, "set/get PWM frequency"); time_sleep(0.2); oc = t2_count; time_sleep(2); f = t2_count - oc; CHECK(2, 7, f, 400, 1, "callback"); set_PWM_frequency(pi, GPIO, 1000); f = get_PWM_frequency(pi, GPIO); CHECK(2, 8, f, 1000, 0, "set/get PWM frequency"); time_sleep(0.2); oc = t2_count; time_sleep(2); f = t2_count - oc; CHECK(2, 9, f, 4000, 1, "callback"); r = get_PWM_range(pi, GPIO); CHECK(2, 10, r, 255, 0, "get PWM range"); rr = get_PWM_real_range(pi, GPIO); CHECK(2, 11, rr, 200, 0, "get PWM real range"); set_PWM_range(pi, GPIO, 2000); r = get_PWM_range(pi, GPIO); CHECK(2, 12, r, 2000, 0, "set/get PWM range"); rr = get_PWM_real_range(pi, GPIO); CHECK(2, 13, rr, 200, 0, "get PWM real range"); set_PWM_dutycycle(pi, GPIO, 0); callback_cancel(id); }
void t9(int pi) { int s, oc, c, e, id; uint32_t p[10]; printf("Script store/run/status/stop/delete tests.\n"); gpio_write(pi, GPIO, 0); /* need known state */ /* 100 loops per second p0 number of loops p1 GPIO */ char *script="\ ld p9 p0\ tag 0\ w p1 1\ mils 5\ w p1 0\ mils 5\ dcr p9\ jp 0"; id = callback(pi, GPIO, RISING_EDGE, t9cbf); s = store_script(pi, script); /* Wait for script to finish initing. */ while (1) { time_sleep(0.1); e = script_status(pi, s, p); if (e != PI_SCRIPT_INITING) break; } oc = t9_count; p[0] = 99; p[1] = GPIO; run_script(pi, s, 2, p); time_sleep(2); c = t9_count - oc; CHECK(9, 1, c, 100, 0, "store/run script"); oc = t9_count; p[0] = 200; p[1] = GPIO; run_script(pi, s, 2, p); while (1) { time_sleep(0.1); e = script_status(pi, s, p); if (e != PI_SCRIPT_RUNNING) break; } c = t9_count - oc; time_sleep(0.1); CHECK(9, 2, c, 201, 0, "run script/script status"); oc = t9_count; p[0] = 2000; p[1] = GPIO; run_script(pi, s, 2, p); while (1) { time_sleep(0.1); e = script_status(pi, s, p); if (e != PI_SCRIPT_RUNNING) break; if (p[9] < 1600) stop_script(pi, s); } c = t9_count - oc; time_sleep(0.1); CHECK(9, 3, c, 410, 10, "run/stop script/script status"); e = delete_script(pi, s); CHECK(9, 4, e, 0, 0, "delete script"); callback_cancel(id); }
void t5(int pi) { int BAUD=4800; char *TEXT= "\n\ Now is the winter of our discontent\n\ Made glorious summer by this sun of York;\n\ And all the clouds that lour'd upon our house\n\ In the deep bosom of the ocean buried.\n\ Now are our brows bound with victorious wreaths;\n\ Our bruised arms hung up for monuments;\n\ Our stern alarums changed to merry meetings,\n\ Our dreadful marches to delightful measures.\n\ Grim-visaged war hath smooth'd his wrinkled front;\n\ And now, instead of mounting barded steeds\n\ To fright the souls of fearful adversaries,\n\ He capers nimbly in a lady's chamber\n\ To the lascivious pleasing of a lute.\n\ "; gpioPulse_t wf[] = { {1<<GPIO, 0, 10000}, {0, 1<<GPIO, 30000}, {1<<GPIO, 0, 60000}, {0, 1<<GPIO, 100000}, }; int e, oc, c, wid, id; char text[2048]; printf("Waveforms & serial read/write tests.\n"); id = callback(pi, GPIO, FALLING_EDGE, t5cbf); set_mode(pi, GPIO, PI_OUTPUT); e = wave_clear(pi); CHECK(5, 1, e, 0, 0, "callback, set mode, wave clear"); e = wave_add_generic(pi, 4, wf); CHECK(5, 2, e, 4, 0, "pulse, wave add generic"); wid = wave_create(pi); e = wave_send_repeat(pi, wid); CHECK(5, 3, e, 9, 0, "wave tx repeat"); oc = t5_count; time_sleep(5.05); c = t5_count - oc; CHECK(5, 4, c, 50, 2, "callback"); e = wave_tx_stop(pi); CHECK(5, 5, e, 0, 0, "wave tx stop"); e = bb_serial_read_open(pi, GPIO, BAUD, 8); CHECK(5, 6, e, 0, 0, "serial read open"); wave_clear(pi); e = wave_add_serial(pi, GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT); CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial"); wid = wave_create(pi); e = wave_send_once(pi, wid); CHECK(5, 8, e, 6811, 0, "wave tx start"); oc = t5_count; time_sleep(3); c = t5_count - oc; CHECK(5, 9, c, 0, 0, "callback"); oc = t5_count; while (wave_tx_busy(pi)) time_sleep(0.1); time_sleep(0.1); c = t5_count - oc; CHECK(5, 10, c, 1702, 0, "wave tx busy, callback"); c = bb_serial_read(pi, GPIO, text, sizeof(text)-1); if (c > 0) text[c] = 0; /* null terminate string */ CHECK(5, 11, strcmp(TEXT, text), 0, 0, "wave tx busy, serial read"); e = bb_serial_read_close(pi, GPIO); CHECK(5, 12, e, 0, 0, "serial read close"); c = wave_get_micros(pi); CHECK(5, 13, c, 6158148, 0, "wave get micros"); c = wave_get_high_micros(pi); if (c > 6158148) c = 6158148; CHECK(5, 14, c, 6158148, 0, "wave get high micros"); c = wave_get_max_micros(pi); CHECK(5, 15, c, 1800000000, 0, "wave get max micros"); c = wave_get_pulses(pi); CHECK(5, 16, c, 3405, 0, "wave get pulses"); c = wave_get_high_pulses(pi); CHECK(5, 17, c, 3405, 0, "wave get high pulses"); c = wave_get_max_pulses(pi); CHECK(5, 18, c, 12000, 0, "wave get max pulses"); c = wave_get_cbs(pi); CHECK(5, 19, c, 6810, 0, "wave get cbs"); c = wave_get_high_cbs(pi); CHECK(5, 20, c, 6810, 0, "wave get high cbs"); c = wave_get_max_cbs(pi); CHECK(5, 21, c, 25016, 0, "wave get max cbs"); callback_cancel(id); }