int main(int argc, char **argv) { int relay = 0; int onoff = 0; // GPIO 初始化 if(!bcm2835_init()) return 1; // 設定接腳狀態 bcm2835_gpio_fsel(RELAY_INP1, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(RELAY_INP2, BCM2835_GPIO_FSEL_OUTP); // 初始輸出狀態 bcm2835_gpio_write(RELAY_INP1, HIGH); bcm2835_gpio_write(RELAY_INP2, HIGH); while(1) { printf("\nUsage: relay(1 or 2) on/off(1 or 0), ex. 1 0 (relay 1 off) \n"); printf("3 0 all off, 3 1 all on, 0 0 to exit\n"); printf("relay turn on/off: (%d %d): ", relay, onoff); scanf("%d %d", &relay, &onoff); printf("relay turn on/off: (%d %d): ", relay, onoff); fflush(stdin); if(onoff == 0) onoff = HIGH; else if(onoff == 1) onoff = LOW; else { printf("keyin the worng relay status!\n"); if(!prog_exit) return 3; } if(relay == 0) { return prog_exit(); } else if(relay == 1) bcm2835_gpio_write(RELAY_INP1, onoff); else if(relay == 2) bcm2835_gpio_write(RELAY_INP2, onoff); else if(relay == 3) { bcm2835_gpio_write(RELAY_INP1, onoff); bcm2835_gpio_write(RELAY_INP2, onoff); } else { printf("Keyin the wrong relay number!\n"); if(!prog_exit()) return 3; } } return 0; }
int main(int argc, char *argv[]) { printf("iRecovery - Version: %s - For LIBUSB: %s\n", VERSION, LIBUSB_VERSION); printf("by westbaer. Thanks to pod2g, tom3q, planetbeing, geohot and posixninja.\r\nRewrite by GreySyntax.\n\n"); if(argc < 2) { prog_usage(); exit(1); } prog_init(); (void) signal(SIGTERM, prog_exit); (void) signal(SIGQUIT, prog_exit); (void) signal(SIGINT, prog_exit); if (device == NULL) { printf("[Device] Failed to connect, check the device is in DFU or WTF (Recovery) Mode.\r\n"); return -1; } printf("[Device] Connected.\n"); prog_handle(argc, argv); //Handle arguments prog_exit(); exit(0); }