示例#1
0
文件: vbit.c 项目: gregmedd/vbit-pi
int main (/* TODO: add args */)
{
	
	int i;

	
	// Set up the eight magazine threads
	magInit();

	// TODO: Test that the threads started.
	
	// Sequence streams of packets into VBI fields
	i=piThreadCreate(Stream);
	if (i != 0)
	{
		// printf ("Stream thread! It didn't start\n");		
		return 1;
	}
	// Copy VBI to stdout
	i=piThreadCreate(OutputStream);
	if (i != 0)
	{
		// printf ("OutputStream thread! It didn't start\n");
		return 1;
	}
	while (1)
	{
	}
	puts("Finished\n"); // impossible to get here
	return 1;
}
示例#2
0
/* piThreadCreate
 *
 * Parameters:
 * - fn: void *(*)(void *)
 * - arg2: void *
 * Return Type: int
 */
mrb_value
mrb_Pi_piThreadCreate(mrb_state* mrb, mrb_value self) {
  mrb_value fn;
  mrb_value arg2;

  /* Fetch the args */
  mrb_get_args(mrb, "oo", &fn, &arg2);

  /* Type checking */
  TODO_type_check_void_PTR_LPAREN_PTR_RPAREN_LPAREN_void_PTR_RPAREN(fn);
  TODO_type_check_void_PTR(arg2);

  /* Unbox parameters */
  void *(*native_fn)(void *) = TODO_mruby_unbox_void_PTR_LPAREN_PTR_RPAREN_LPAREN_void_PTR_RPAREN(fn);

  void * native_arg2 = TODO_mruby_unbox_void_PTR(arg2);

  /* Invocation */
  int result = piThreadCreate(native_fn, native_arg2);

  /* Box the return value */
  mrb_value return_value = mrb_fixnum_value(result);

  return return_value;
}
示例#3
0
int main(int argc, char **argv)
{
	printf("hello\n");
	
	cfg_dt cfg=load_config(argc,argv);
	printf("config loaded==>loglevel=%d\t\nlogfile=%s\n",cfg.log_level,cfg.logfile);
	
	f(argc, argv);
	
	
	if(1!=f_sysinit(cfg.itype,cfg.use_exit_critical_function))
	{ 
		release_config(&cfg);
		return 1;
     }
     else if(cfg.itype!=3)
     {
	
	  mcp23017Setup (BASE_I2C, 0x20) ;
	  
	
	// For the push button to stop it...

  pinMode         (BASE_I2C + 15, INPUT) ;
  pullUpDnControl (BASE_I2C + 15, PUD_UP) ;
  
  while (digitalRead (BASE_I2C + 15) == 0)
        delay (1) ;
  }
  
    piThreadCreate (matrixUpdater) ;
     while(getchar()!=32);
	release_config(&cfg);
	return 0;
}
示例#4
0
int softServoSetup (int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7)
{
  int servo ;

  if (p0 != -1) { pinMode (p0, OUTPUT) ; digitalWrite (p0, LOW) ; }
  if (p1 != -1) { pinMode (p1, OUTPUT) ; digitalWrite (p1, LOW) ; }
  if (p2 != -1) { pinMode (p2, OUTPUT) ; digitalWrite (p2, LOW) ; }
  if (p3 != -1) { pinMode (p3, OUTPUT) ; digitalWrite (p3, LOW) ; }
  if (p4 != -1) { pinMode (p4, OUTPUT) ; digitalWrite (p4, LOW) ; }
  if (p5 != -1) { pinMode (p5, OUTPUT) ; digitalWrite (p5, LOW) ; }
  if (p6 != -1) { pinMode (p6, OUTPUT) ; digitalWrite (p6, LOW) ; }
  if (p7 != -1) { pinMode (p7, OUTPUT) ; digitalWrite (p7, LOW) ; }

  pinMap [0] = p0 ;
  pinMap [1] = p1 ;
  pinMap [2] = p2 ;
  pinMap [3] = p3 ;
  pinMap [4] = p4 ;
  pinMap [5] = p5 ;
  pinMap [6] = p6 ;
  pinMap [7] = p7 ;

  for (servo = 0 ; servo < MAX_SERVOS ; ++servo)
    pulseWidth [servo] = 1500 ;		// Mid point
  
  return piThreadCreate (softServoThread) ;
}
示例#5
0
/*
 * Setup
 */
void setup(void) {
	// initialise the hardware
	// initialize variables
	// Initialize the communications from the thermistor task

	wiringPiSetupSys(); // Setup wiringPi
	piThreadCreate(readTemperature); // Start Thermistor reading task
}
示例#6
0
void ThreadPowerOff(void)
{
  int x = piThreadCreate(ThreadPowerCheck);
  if(x != 0){
    printf("it didn't start\n");
  }
  if(verbose){
    printf("start succesfully\n");
  }
  while(true);
}
示例#7
0
void setup (void)
{

// Use the gpio program to initialise the hardware
//	(This is the crude, but effective bit)

  system ("gpio edge 24 falling") ;
  system ("gpio edge 10 falling") ;
  system ("gpio export 17 out") ;
  system ("gpio export 18 out") ;

// Setup wiringPi

  wiringPiSetupSys () ;

// Fire off our interrupt handler

  piThreadCreate   (waitForLeftEncoder) ;
  piThreadCreate   (waitForRightEncoder) ;
}
示例#8
0
int main(void)
{
unsigned int i;
if (wiringPiSetup() == -1)
exit(1);

if ( wiringPiISR (Din, INT_EDGE_FALLING, &myInterrupt) < 0 ) {
      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
      return 1;
}

int x = piThreadCreate (myThread) ;
if (x != 0)
printf("it didn¡¯t start\n");

pinMode(S0,OUTPUT);
pinMode(S1,OUTPUT);
pinMode(S2,OUTPUT);
pinMode(S3,OUTPUT);

digitalWrite(S0, LOW);// OUTPUT FREQUENCY SCALING 2%
digitalWrite(S1, HIGH); 
delay(5000);


   printf("R:%ld\n",g_array[0]);
   printf("G:%ld\n",g_array[1]);
   printf("B:%ld\n",g_array[2]);
   
   g_SF[0] = 255.0/ g_array[0];     //R Scale factor
   g_SF[1] = 255.0/ g_array[1] ;    //G Scale factor
   g_SF[2] = 255.0/ g_array[2] ;    //B Scale factor
   printf("R:%f\n",g_SF[0]);
   printf("G:%f\n",g_SF[1]);
   printf("B:%f\n",g_SF[2]); 
while(1)
{
	 g_flag = 0;

   printf("R:%ld\n",(int)(g_array[0]*g_SF[0]));
   printf("G:%ld\n",(int)(g_array[1]*g_SF[1]));
   printf("B:%ld\n",(int)(g_array[2]*g_SF[2]));
   
   delay(5000); 
}
return 0;
}
示例#9
0
文件: wfi.c 项目: LeMaker/WiringLMK
void setup (void)
{

    // Use the gpio program to initialise the hardware
    //	(This is the crude, but effective)

    system ("gpio edge 17 falling") ;

    // Setup wiringPi

    wiringPiSetupSys () ;

    // Fire off our interrupt handler

    piThreadCreate (waitForIt) ;

}
示例#10
0
int softToneCreate (int pin)
{
  int res ;

  pinMode      (pin, OUTPUT) ;
  digitalWrite (pin, LOW) ;

  freqs [pin] = 0 ;

  newPin = pin ;
  res = piThreadCreate (softToneThread) ;

  while (newPin != -1)
    delay (1) ;

  return res ;
}
示例#11
0
int softPwmCreate (int pin, int initialValue, int pwmRange)
{
  int res ;
    printf("func:%s line:%d\n",__func__,__LINE__);
  pinMode      (pin, OUTPUT) ;
  digitalWrite (pin, LOW) ;

  marks [pin] = initialValue ;
  range [pin] = pwmRange ;

  newPin = pin ;
  res = piThreadCreate (softPwmThread) ;

  while (newPin != -1)
    delay (1) ;

  return res ;
}
示例#12
0
void setup (void)
{

// Use the gpio program to initialise the hardware
//	(This is the crude, but effective bit)

  system ("gpio   edge  0 falling") ;
  system ("gpio export 17 out") ;
  system ("gpio export 18 out") ;

// Setup wiringPi

  wiringPiSetupSys () ;

// Fire off our interrupt handler

  piThreadCreate   (waitForIt) ;

  digitalWrite (17, 0) ;
}
示例#13
0
void init_servo()
{
   if ((fd = serialOpen ("/dev/ttyAMA0", 9600)) < 0)
	  {
	    fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
	    return 1 ;
	  }
	printf("init fd: %d",fd);
	//inital Thread
	int x = piThreadCreate(myThread);
	if(x!=0)
	{
		printf("No ko the bat dau\n");
	}
   if (wiringPiSetup () == -1)
   {
        fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
    	return 1 ;
   }
    // initial 0 & 1 pin PWM are output 
    pinMode (1, OUTPUT) ; // camera go up/down
    pinMode(0,OUTPUT); //camera turn lerf/right

    // pull 2 pin PWM to GND
    digitalWrite (1, LOW) ;
    digitalWrite(0, LOW);
    
    //setup 2 pin is PWM
    softPwmCreate(0,0,200);
    softPwmCreate(1,0,200);
    
    //setup the location defaults 
    i_count = 0;
    softPwmWrite(1,175+posHor);
    //delay(100);
    softPwmWrite(0,175+posVer);

    //delay(1000); 
}
示例#14
0
void setup(void)
{
	wiringPiSetupSys();
	piThreadCreate(waitForPin1);
}
int main(int argc, char* argv[])
{
    //Getting input from the file for subscribing
    char ADDRESS[50];
    char CLIENTID[23];
    char TOPIC[80];
    char PORT[5];
    FILE* fp = fopen("input_sub.config","r");
    fscanf(fp,"%s",ADDRESS);
    fscanf(fp,"%s",CLIENTID);
    fscanf(fp,"%s",TOPIC);
    fscanf(fp,"%s",PORT);
    sprintf(ADDRESS,"%s:%s",ADDRESS,PORT);
    fclose(fp);
    //WiringPi setup
    wiringPiSetupGpio ();
    pinMode (LED_1, OUTPUT);
    pinMode (LED_2, OUTPUT);
    pinMode (LED_3, OUTPUT);
    //pinMode (SWITCH_1, INPUT);
    //pinMode (SWITCH_2, INPUT);
    //pinMode (SWITCH_3, INPUT);
    //Pull up input pins
    pullUpDnControl (SWITCH_1, PUD_UP);
    pullUpDnControl (SWITCH_2, PUD_UP);
    pullUpDnControl (SWITCH_3, PUD_UP);
    //Set Interrupts
    wiringPiISR(SWITCH_1,INT_EDGE_BOTH,&interruptFunc_1);
    wiringPiISR(SWITCH_2,INT_EDGE_BOTH,&interruptFunc_2);
    wiringPiISR(SWITCH_3,INT_EDGE_BOTH,&interruptFunc_3);
    //Pull down the non ground pins
    pullUpDnControl (19, PUD_DOWN);
    pullUpDnControl (26, PUD_DOWN);
    //Lights Initialization
    digitalWrite(LED_1,HIGH);
    digitalWrite(LED_2,LOW);
    digitalWrite(LED_3,LOW);
    delay(100);
    digitalWrite(LED_1,LOW);
    digitalWrite(LED_2,HIGH);
    digitalWrite(LED_3,LOW);
    delay(100);
    digitalWrite(LED_1,LOW);
    digitalWrite(LED_2,LOW);
    digitalWrite(LED_3,HIGH);
    delay(100);
    digitalWrite(LED_1, LOW);
    digitalWrite(LED_2, LOW);
    digitalWrite(LED_3, LOW);

    //MQTT Setup for subscribing
    MQTTClient client;
    MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
    int rc;
    int ch;

    MQTTClient_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_USER, NULL);
    conn_opts.keepAliveInterval = 100;
    conn_opts.cleansession = 0;

    MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);

    if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
    {
        printf("Failed to connect, return code %d\n", rc);
        exit(-1);
    }
    printf("Subscribing to topic %s\nfor client %s using QoS %d\n\n"
           "Press Q<Enter> to quit\n\n", TOPIC, CLIENTID, QOS);
    MQTTClient_subscribe(client, TOPIC, QOS);

    //Start the new thread
    if(piThreadCreate(mqttStream) != 0)
    {
	printf("ERROR in creating MQTT streaming thread");
    }

    //Main loop
    int previousBoxStatus_1,previousBoxStatus_2,previousBoxStatus_3;

    previousBoxStatus_1 = boxStatus_1;
    previousBoxStatus_2 = boxStatus_2;
    previousBoxStatus_3 = boxStatus_3;

    do 
    {
    	//if the previous mode is not the status now publish else do nothing
	if(previousBoxStatus_1 != boxStatus_1){
		delay(debounceDelay);			//Time delay after an interrupt for the signal to be stable
		publishBoxStatus(10,boxStatus_1);
		previousBoxStatus_1 = boxStatus_1;	
	}
	if(previousBoxStatus_2 != boxStatus_2){
                delay(debounceDelay);                     //Time delay after an interrupt for the signal to be stable
                publishBoxStatus(20,boxStatus_2);
                previousBoxStatus_2 = boxStatus_2;
        }
	if(previousBoxStatus_3 != boxStatus_3){
                delay(debounceDelay);                     //Time delay after an interrupt for the signal to be stable
                publishBoxStatus(30,boxStatus_3);
                previousBoxStatus_3 = boxStatus_3;
        }
       // ch = getchar();
    } while(ch!='Q' && ch != 'q');

    MQTTClient_disconnect(client, 10000);
    MQTTClient_destroy(&client);
    return rc;
}
示例#16
0
int main (int argc, char** argv)
{
	
	int i;
	char filename[MAXPATH];
	
	if(argc > 2){
		if(!strcmp(argv[1],"--dir")){
			#ifdef _DEBUG_
			fprintf(stderr,"got directory %s from command line\n",argv[2]);
			#endif
			strncpy(pagesPath, argv[2], MAXPATH-1); /* copy directory string to global */
		}
	}
	
	// construct default config file filename from pages directory and default config file name
	// TODO: allow specifying any file from command line
	strncpy(filename,pagesPath,MAXPATH-1);
	i = filename[(strlen(filename)-1)];
	if (i != '/' && i != '\\' && strlen(filename) + 1 < MAXPATH)
		strcat(filename, "/"); // append missing trailing slash
	i = strlen(filename) + strlen(CONFIGFILE);
	if (i < MAXPATH){
		strncat(filename,CONFIGFILE, i);
	}
	#ifdef _DEBUG_
	fprintf(stderr,"using config file %s\n",filename);
	#endif
	
	i = readConfigFile(filename); // read in config from config file
	switch (i){
		case NOCONFIG:
			fprintf(stderr,"No config file found. Using default settings.\n");
			break;
		case BADCONFIG:
			fprintf(stderr,"Config file contains invalid setting: %s\n",configErrorString);
			return 1;
	}
	
	/* initialize the mutexes we're going to use! */
	init_mutex(0);
	init_mutex(1);
	
	InitNu4(); // Prepare the buffers used by Newfor subtitles
	
	// Start the network port (commands and subtitles)
	i=piThreadCreate(runClient);
	//while(1);
	
	// Set up the eight magazine threads
	magInit();

	// TODO: Test that the threads started.
	
	// Sequence streams of packets into VBI fields
	i=piThreadCreate(Stream);
	if (i != 0)
	{
		// printf ("Stream thread! It didn't start\n");		
		return 1;
	}
	// Copy VBI to stdout
	i=piThreadCreate(OutputStream);
	if (i != 0)
	{
		// printf ("OutputStream thread! It didn't start\n");
		return 1;
	}
	while (1)
	{
	}
	fputs("Finished\n",stderr); // impossible to get here
	return 1;
}