Last active
August 29, 2015 14:03
-
-
Save JohnPersano/ab38bffbbd1060f6b2f2 to your computer and use it in GitHub Desktop.
Jasper Fan Worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <wiringPi.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int PIN = 4; | |
void getStatus(){ | |
printf("%d\n", digitalRead(PIN)); | |
} | |
void turnOn(){ | |
pinMode(PIN, OUTPUT); | |
digitalWrite(PIN, LOW); | |
printf("%d\n", digitalRead(PIN)); | |
} | |
void turnOff(){ | |
pinMode(PIN, OUTPUT); | |
digitalWrite(PIN, HIGH); | |
printf("%d\n", digitalRead(PIN)); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if(argc != 3) { | |
printf("Invalid parameters: You must supply a GPIO pin and a function as a parameter. \n"); | |
exit(1); | |
} else { | |
if (wiringPiSetupGpio() == -1) { | |
exit(1); | |
} | |
sscanf(argv[1], "%d", &PIN); | |
if(PIN > 25) { | |
printf("%d is not a valid pin\n", PIN); | |
exit(1); | |
} | |
if(strcmp(argv[2], "-status") == 0){ | |
getStatus(); | |
} else if(strcmp(argv[2], "-on") == 0){ | |
turnOn(); | |
} else if(strcmp(argv[2], "-off") == 0){ | |
turnOff(); | |
} else { | |
printf("%s is not a valid parameter\n", argv[2]); | |
printf("The acceptable parameters are:\n"); | |
printf(" -status\n -on\n -off\n"); | |
exit(1); | |
} | |
} | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment