Exemple #1
0
int main (void)
{
  int speed, times, size ;
  unsigned int start, end ;
  int spiFail ;
  unsigned char *myData ;
  double timePerTransaction, perfectTimePerTransaction, dataSpeed ;

  if ((myData = malloc (MAX_SIZE)) == NULL)
  {
    fprintf (stderr, "Unable to allocate buffer: %s\n", strerror (errno)) ;
    exit (EXIT_FAILURE) ;
  }

  wiringPiSetup () ;

  for (speed = 1 ; speed <= 32 ; speed *= 2)
  {
    printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
    printf ("|   MHz |   Size | mS/Trans |      TpS |    Mb/Sec | Latency mS |\n") ;
    printf ("+-------+--------+----------+----------+-----------+------------+\n") ;

    spiFail = FALSE ;
    spiSetup (speed * 1000000) ;
    for (size = 1 ; size <= MAX_SIZE ; size *= 2)
    {
      printf ("| %5d | %6d ", speed, size) ;

      start = millis () ;
      for (times = 0 ; times < NUM_TIMES ; ++times)
	if (wiringPiSPIDataRW (SPI_CHAN, myData, size) == -1)
	{
	  printf ("SPI failure: %s\n", strerror (errno)) ;
	  spiFail = TRUE ;
	  break ;
	}
      end = millis () ;

      if (spiFail)
	break ;

      timePerTransaction        = ((double)(end - start) / (double)NUM_TIMES) / 1000.0 ;
      dataSpeed                 =  (double)(size * 8)    / (1024.0 * 1024.0) / timePerTransaction  ;
      perfectTimePerTransaction = ((double)(size * 8))   / ((double)(speed * 1000000)) ;

      printf ("| %8.3f ", timePerTransaction * 1000.0) ;
      printf ("| %8.1f ", 1.0 / timePerTransaction) ;
      printf ("| %9.5f ", dataSpeed) ;
      printf ("|   %8.5f ", (timePerTransaction - perfectTimePerTransaction) * 1000.0) ;
      printf ("|\n") ;

    }

    close (myFd) ;
    printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
    printf ("\n") ;
  }
  return 0 ;
}
/** \brief Initialization of edOLED Library.

    Setup IO pins for SPI port then send initialization commands to the
    SSD1306 controller inside the OLED.
*/
void edOLED::begin()
{
	// default 5x7 font
	setFontType(0);
	setColor(WHITE);
	setDrawMode(NORM);
	setCursor(0,0);
	
	spiSetup();
	
	RST_PIN.pinWrite(HIGH); //(digitalWrite(rstPin, HIGH);
	usleep(5000); // VDD (3.3V) goes high at start, lets just chill for 5 ms
	RST_PIN.pinWrite(LOW); // bring reset low
	usleep(10000); // wait 10ms
	RST_PIN.pinWrite(HIGH);	//digitalWrite(rstPin, HIGH);

	// Init sequence for 64x48 OLED module
	command(DISPLAYOFF);			// 0xAE

	command(SETDISPLAYCLOCKDIV);	// 0xD5
	command(0x80);					// the suggested ratio 0x80

	command(SETMULTIPLEX);			// 0xA8
	command(0x2F);

	command(SETDISPLAYOFFSET);		// 0xD3
	command(0x0);					// no offset

	command(SETSTARTLINE | 0x0);	// line #0

	command(CHARGEPUMP);			// enable charge pump
	command(0x14);

	command(NORMALDISPLAY);			// 0xA6
	command(DISPLAYALLONRESUME);	// 0xA4

	command(SEGREMAP | 0x1);
	command(COMSCANDEC);

	command(SETCOMPINS);			// 0xDA
	command(0x12);

	command(SETCONTRAST);			// 0x81
	command(0x8F);

	command(SETPRECHARGE);			// 0xd9
	command(0xF1);
	
	command(SETVCOMDESELECT);			// 0xDB
	command(0x40);

	command(DISPLAYON);				//--turn on oled panel
	clear(ALL);						// Erase hardware memory inside the OLED
}
Exemple #3
0
void* entryDistanciaFrontal(void*)
{
   

    int spiChannel=0;
    int channelConfig=CHAN_CONFIG_SINGLE;
       
    printf("Cargando modulo \n"); 
    spiSetup(spiChannel);
    pinMode(PIN_CNI70_SIGUELINEAS,INPUT);
	
    while (1) {  
	int distChan0 = myAnalogRead(spiChannel,channelConfig,0);
	int distChan1 = myAnalogRead(spiChannel,channelConfig,1);
	int sigueL = digitalRead(PIN_CNI70_SIGUELINEAS);
	printf(" Canal 0: %d Canal 1: %d SigueL: %d\n",distChan0,distChan1,sigueL);
	delay(500);
	
    }	    


    close (myFd) ;
    return 0;
}
/** \brief Initialisation of MicroOLED Library.

    Setup IO pins for SPI port then send initialisation commands to the SSD1306 controller inside the OLED.
*/
void MicroOLED::begin()
{
	// default 5x7 font
	setFontType(0);
	setColor(WHITE);
	setDrawMode(NORM);
	setCursor(0,0);

	pinMode(dcPin, OUTPUT);
	pinMode(rstPin, OUTPUT);

	// Set up the selected interface:
	if (interface == MODE_SPI)
		spiSetup();
	else if (interface == MODE_I2C)
		i2cSetup();
	else if (interface == MODE_PARALLEL)
		parallelSetup();

	// Display reset routine
	pinMode(rstPin, OUTPUT);	// Set RST pin as OUTPUT
	digitalWrite(rstPin, HIGH);	// Initially set RST HIGH
	delay(5);	// VDD (3.3V) goes high at start, lets just chill for 5 ms
	digitalWrite(rstPin, LOW);	// Bring RST low, reset the display
	delay(10);	// wait 10ms
	digitalWrite(rstPin, HIGH);	// Set RST HIGH, bring out of reset

	// Display Init sequence for 64x48 OLED module
	command(DISPLAYOFF);			// 0xAE

	command(SETDISPLAYCLOCKDIV);	// 0xD5
	command(0x80);					// the suggested ratio 0x80

	command(SETMULTIPLEX);			// 0xA8
	command(0x2F);

	command(SETDISPLAYOFFSET);		// 0xD3
	command(0x0);					// no offset

	command(SETSTARTLINE | 0x0);	// line #0

	command(CHARGEPUMP);			// enable charge pump
	command(0x14);

	command(NORMALDISPLAY);			// 0xA6
	command(DISPLAYALLONRESUME);	// 0xA4

	command(SEGREMAP | 0x1);
	command(COMSCANDEC);

	command(SETCOMPINS);			// 0xDA
	command(0x12);

	command(SETCONTRAST);			// 0x81
	command(0x8F);

	command(SETPRECHARGE);			// 0xd9
	command(0xF1);

	command(SETVCOMDESELECT);			// 0xDB
	command(0x40);

	command(DISPLAYON);				//--turn on oled panel
	clear(ALL);						// Erase hardware memory inside the OLED controller to avoid random data in memory.
}
Exemple #5
0
int main (int argc, char *argv [])
{
    int loadSpi=FALSE;
    int analogChannel=0;
    int spiChannel=0;
    int channelConfig=CHAN_CONFIG_SINGLE;
    int print_once;
    int modus_operandi = 1;
    int mode_flag=1;
    int rows = 2;
    int cols = 16;
    int bits = 4; //4 bit mode
    char buf [32];
    char tempbuf [32];
    char weatherBuff;
    char *tempmsg;
    int lcd;
    struct tm *t ;
    time_t tim ;
    int i;
    int max_distance;
    int curr_distance;
  /*
    if (argc < 2)
    {
        fprintf (stderr, "%s\n", usage) ;
        return 1 ;
    }
    if((strcasecmp (argv [1], "all") == 0) )
        argv[1] = "0";
    if ( (sscanf (argv[1], "%i", &analogChannel)!=1) || analogChannel < 0 || analogChannel > 8 )
    {
        printf ("%s\n",  usage) ;
        return 1 ;
    }
    int i;
    for(i=2; i<argc; i++)
    {
        if (strcasecmp (argv [i], "-l") == 0 || strcasecmp (argv [i], "-load") == 0)
            loadSpi=TRUE;
        else if (strcasecmp (argv [i], "-ce1") == 0)
            spiChannel=1;
        else if (strcasecmp (argv [i], "-d") == 0 || strcasecmp (argv [i], "-diff") == 0)
            channelConfig=CHAN_CONFIG_DIFF;
    }
  */
    //
    if(loadSpi==TRUE)
        loadSpiDriver();
    wiringPiSetup () ;
    //set button input
   // pinMode(BUTTON, INPUT);	
    spiSetup(spiChannel);
    i = 0;
    print_once = 0;
    
    if (bits == 4)
	lcdHandle = lcdInit (rows, cols, 4, 11,15, 4,5,6,7,0,0,0,0) ;
    else
	lcdHandle = lcdInit (rows, cols, 8, 11,15, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }
//-------------Begin Infinite Loop
pinMode(27, OUTPUT);
//digitalWrite(27, HIGH);
pinMode(23, OUTPUT);
digitalWrite(27,LOW);
digitalWrite(23,LOW);
//sendEmail();
printf("grabbing weather data\n");
getWeather();
printf("weather is: %s\n", filestring);
delay(20);

/*set initial distance for ultrasonic sensor*/

	ZonicSetup();
	max_distance = getZonicCM();

while(1){

//ZonicSetup();
curr_distance = getZonicCM();
if (digitalRead(MODUS_OPERANDI_PIN) == LOW)
	{mode_flag = (mode_flag+1)%2;
	delay(500);}
/*else if (digitalRead(MODUS_OPERANDI_PIN) == HIGH)
	{mode_flag = 0;}
*/
/*MODE_FLAG = 0.....HOME MODE
MODE_FLAG = 1......AWAY MODE */
/*MAYBE ADD SET APPLIANCE MODE*/
printf("How fast is this while?\n");

/*HOME MODE
*
*Display Temperature and Date on LCD
*
*/
	if (mode_flag == 1){
		digitalWrite(27,LOW);
		digitalWrite(23,HIGH);


		tim = time (NULL) ;
		 t = localtime (&tim) ;

		 sprintf (buf, "%02d:%02d:%02d   %02d/%02d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mon, t->tm_mday) ;

		 //lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
		 lcdPosition (lcdHandle, 0, 1);
		 lcdPuts     (lcdHandle, buf) ;

//printf("got here1\n");
 //pingPong (lcd, cols) ;

		temp = steinhartAndHart(myAnalogRead(0,8,0));
		sprintf (tempbuf,"        TEMP:%.0fC   WEATHER: %s  MODE:HOME              ", temp,filestring); 
		tempmsg = tempbuf;
		lcdPosition (lcdHandle, 0, 1);
		scrollMessage(tempmsg,0, 16);
		//scrollMessage(weatherBuff, 0, 16);
		//lcdPuts (lcdHandle, tempbuf);
//		lcdPuts (lcdHandle, chr(223));
 
//	printf("mode_flag = %d\n", mode_flag);
/*		if (digitalRead(BUTTON) == LOW){
			printf("\n------HOME MODE--------\n");
			printf("Thermistor Output (Channel 1):\n");
			printf("-----------------\n");
			temp = steinhartAndHart(myAnalogRead(0,8,0));
			sprintf (tempbuf, "Temp: %.02d C", temp); 
			lcdPosition (lcdHandle, 0, 0);
			lcdPuts (lcdHandle, tempbuf);
			printf("Celsius: %.02f\n", temp);		//print out temperature in Celsius
			temp = (temp * 9.0)/5.0 + 32.0;
			printf("Fahrenheit: %.02f\n", temp);		//print out temperature in Fahrenheit
			//delay(170);
			}
*/
		}


/*AWAY MODE
*
*TAKE IN LDR AND SONIC SENSOR DATA
*
*/
	else {
		 digitalWrite(23,LOW);
		 digitalWrite(27,HIGH);
		
		//printf("mode_flag = %d\n", mode_flag);
		//delay(500);
		//mode_flag = 0; //do something
		/*
		if (curr_distance < max_distance){
			printf("Intruder at %d!\n",getZonicCM());
			}*/
		 printf("%d cm\n", getZonicCM());
		 tim = time (NULL) ;
		 t = localtime (&tim) ;

		 sprintf (buf, "%02d:%02d:%02d   %02d/%02d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mon, t->tm_mday) ;

		 //lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
		 lcdPosition (lcdHandle, 0, 1);
		 lcdPuts     (lcdHandle, buf) ;


		temp = steinhartAndHart(myAnalogRead(0,8,0));
		sprintf (tempbuf, "                Temp:%.0fC   MODE:AWAY                 ", temp); 
		lcdPosition (lcdHandle, 0, 0);
		//lcdPuts (lcdHandle, tempbuf);
		scrollMessage(tempbuf,0,16);
//		printf("got here1\n");
/*ULTRASONIC SENSOR*/			
	//	printf("Distance: %dcm\n",getZonicCM());
	//	delay(2000);
		/*
		if (digitalRead(BUTTON) == LOW){
			printf("\n------AWAY MODE------\n");
			printf("LDR Output (Channel 2):\n");
			printf("LDR Output: %d\n", myAnalogRead(0,8,1));
			printf("-----------------\n");
			//delay(200);
		}
		*/
	}
}
return 0;
}