int main(int argc, char **argv) { OptionsStruct opts; // struct for options int optStatus = 0; // // Get the parameters: optStatus = parseOptions(argc, argv, &opts); // if errors reading options then exit with non 0 status if (optStatus != 0) { return 1; } //open the Raspberry Pi's onboard serial port, baud rate is 115200 //make sure that the display module has the same baud rate genieSetup("/dev/ttyAMA0", 115200); // If a value is provided send that to the display and exit if (strlen(opts.value) > 0) { pushToDisplay(opts, opts.value); // If no value provided on command line the use stdin // Need to fix this for non string objects } else { int continueLoop = 1; while (continueLoop) { char *line = NULL; size_t size; size_t chars; chars = getline(&line, &size, stdin); if (chars == -1) { continueLoop = 0; // get out of the loop } else { // remove the newline character if (line[chars - 1] == '\n') { line[chars - 1] = '\0'; --chars; } // push the line to the display pushToDisplay(opts, line); } } } if (opts.cleanClose == 1) { genieClose(); } return 0; }
int main (int argc, char *argv[]) { if (argc > 1){ if(strcmp(argv[1], "-L") ==0 ){ display_LCO() ; exit (1); } else if(strcmp(argv[1], "-c") ==0) { int c = atoi(argv[2]); set_cap(c); exit (1); } else if(strcmp(argv[1], "-r") ==0){ int i = atoi(argv[2]); int reg; reg = read_reg(i); printf("Value for Register %d is %#x \n", i, reg); fflush(stdout); exit (1); } else if(strcmp(argv[1], "-n") == 0 ){ //Create the thread pthread_t bmp085 ; //Start the Calibration AS3935_Calibration(); //Open file descriptor for dev/i2c only once fd = bmp085_i2c_Begin(); if (wiringPiSetupGpio () < 0) { fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ; return 1 ; } // Start the interrupt reading (this creates a thread) wiringPiISR (BUTTON_PIN, INT_EDGE_RISING, &getdistance); //Using the Raspberry Pi's on-board serial port. if (genieSetup ("/dev/ttyAMA0", 115200) < 0) { fprintf (stderr, "rgb: Can't initialise Genie Display: %s\n", strerror (errno)) ; return 1 ; } genieWriteObj (GENIE_OBJ_FORM, 0, 0) ; // Start the temperature and pressure sensor reading threads (void)pthread_create (&bmp085, NULL, handleTemperaturePressure, NULL) ; (void)pthread_join (bmp085, NULL); return 0 ; } else { usage(); } } else { usage(); } return 0; }
int main () { pthread_t myThread ; struct genieReplyStruct reply ; printf ("\n\n\n\n") ; printf ("Visi-Genie Weather Station Demo\n") ; printf ("===============================\n") ; // Genie display setup // Using the Raspberry Pi's on-board serial port. if (genieSetup ("/dev/ttyAMA0", 115200) < 0) { fprintf (stderr, "rgb: Can't initialise Genie Display: %s\n", strerror (errno)) ; return 1 ; } // Select form 0 (the temperature) genieWriteObj (GENIE_OBJ_FORM, 0, 0) ; // Start the temperature and pressure sensor reading threads (void)pthread_create (&myThread, NULL, handleTemperature, NULL) ; (void)pthread_create (&myThread, NULL, handlePressure, NULL) ; // Big loop - just wait for events from the display now for (;;) { while (genieReplyAvail ()) { genieGetReply (&reply) ; handleGenieEvent (&reply) ; } usleep (10000) ; // 10mS - Don't hog the CPU in-case anything else is happening... } return 0 ; }