Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <unistd.h>
- #include <syslog.h>
- #include <string.h>
- #include <wiringPi.h>
- #define sync_pin 7 // => 3
- #define data_pin 9 // => 5
- #define clock_pin 8 // => 7
- unsigned char led_cmd[10] = {0,0,1,0,0,0,0,1,0,0}; //Activates/initialises the LEDs, leaving the center LED lit.
- unsigned char anim_cmd[10] = {0,0,1,0,0,0,0,1,0,1}; //Makes the startup animation on the ring of light.
- unsigned char sync_cmd[10] = {0,0,0,0,0,0,0,1,0,0}; //Initiates the sync process.
- void wait_for(int pin, int v) {
- int pin_value;
- do {
- pin_value = digitalRead(pin);
- } while( pin_value != v );
- }
- void send_cmd(unsigned char * cmd) {
- int i = 0;
- /* Send start bit (wakeup the clock) */
- digitalWrite(data_pin, LOW);
- for(i = 0; i < 10; i++){
- wait_for(clock_pin, 0);
- digitalWrite(data_pin, cmd[i]);
- wait_for(clock_pin, 1);
- }
- wait_for(clock_pin, 0);
- /* Send end bit (stop the clock) */
- digitalWrite(data_pin, HIGH);
- wait_for(clock_pin, 1);
- }
- int main (void)
- {
- pid_t pid, sid;
- printf ("Rasberry Pi 360 Board Daemon\n") ;
- /* Init Wiring Pi */
- if (wiringPiSetup () == -1)
- return 1 ;
- /* Fork off the parent process */
- pid = fork();
- if (pid < 0) {
- exit(EXIT_FAILURE);
- }
- /* If we got a good PID, then
- we can exit the parent process. */
- if (pid > 0) {
- exit(EXIT_SUCCESS);
- }
- /* Create a new SID for the child process */
- sid = setsid();
- if (sid < 0) {
- /* Log the failure */
- exit(EXIT_FAILURE);
- }
- /* Setup gpio */
- pinMode(sync_pin, INPUT);
- pinMode(data_pin, OUTPUT);
- pinMode(clock_pin, OUTPUT);
- digitalWrite(clock_pin, HIGH);
- pinMode(clock_pin, INPUT);
- /* Stop RF Board Clock */
- digitalWrite(data_pin, HIGH);
- delay(2000);
- send_cmd(led_cmd);
- send_cmd(anim_cmd);
- while(1) {
- // Wait For Event in sync btn
- wait_for(sync_pin, 0);
- send_cmd(sync_cmd);
- }
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment