Exemplo n.º 1
0
static int
scrollGesture(Gesture g)
{ Name msg;
  Int amount;
  Graphical gr;
  Name dir = NAME_forwards;

  if ( !scrollMessage(g, g->drag_scroll_event, &gr, &msg, &amount) )
    fail;

  if ( valInt(amount) < 0 )
  { dir = NAME_backwards;
    amount = toInt(-valInt(amount));
  }

  if ( hasSendMethodObject(gr, msg) &&
       send(gr, msg, dir, NAME_line, amount, EAV) )
  { EventObj ev = getCloneObject(g->drag_scroll_event); /* TBD: optimise? */

    DEBUG(NAME_dragScroll,
	  Cprintf("Drag event = %s, receiver %s\n",
		  pp(ev->id), pp(ev->receiver)));

    ComputeGraphical(gr);
    restrictAreaEvent(ev, gr);		/* Normalise to area of rec */
    send(g, NAME_drag, ev, EAV);
    synchroniseGraphical(gr, ON);
    doneObject(ev);
  }

  succeed;
}
Exemplo n.º 2
0
static int
tryDragScrollGesture(Gesture g, EventObj ev)
{ status doscroll = scrollMessage(g, ev, NULL, NULL, NULL);

  if ( doscroll )
  { if ( isNil(g->drag_scroll_event) )
    { assign(g, drag_scroll_timer,
	     newObject(ClassTimer, CtoReal(0.06), /* TBD */
		       newObject(ClassMessage, g,
				 NAME_scroll, EAV), EAV));
      startTimer(g->drag_scroll_timer, NAME_repeat);
      assign(g, drag_scroll_event, getCloneObject(ev));
    }
  } else
  { cancelDragScrollGesture(g);
  }

  return doscroll;
}
Exemplo n.º 3
0
int main (int argc, char *argv[])
{
  int i ;
  int lcd ;
  int bits, rows, cols ;

  struct tm *t ;
  time_t tim ;

  char buf [32] ;

  if (argc != 4)
    return usage (argv [0]) ;

  printf ("Raspberry Pi LCD test\n") ;
  printf ("=====================\n") ;

  bits = atoi (argv [1]) ;
  cols = atoi (argv [2]) ;
  rows = atoi (argv [3]) ;

  if (!((rows == 1) || (rows == 2) || (rows == 4)))
  {
    fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  if (!((cols == 16) || (cols == 20)))
  {
    fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  wiringPiSetup () ;

  if (bits == 4)
    lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
  else
    lcdHandle = lcdInit (rows, cols, 8, 11, 10, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }

  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

  waitForEnter () ;

  if (rows > 1)
  {
    lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

    if (rows == 4)
    {
      lcdPosition (lcdHandle, 0, 2) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "=-") ;
      lcdPuts (lcdHandle, "=3") ;

      lcdPosition (lcdHandle, 0, 3) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "-=") ;
      lcdPuts (lcdHandle, "-4") ;
    }
  }

  waitForEnter () ;

  lcdCharDef  (lcdHandle, 2, newChar) ;

  lcdClear    (lcdHandle) ;
  lcdPosition (lcdHandle, 0, 0) ;
  lcdPuts     (lcdHandle, "User Char: ") ;
  lcdPutchar  (lcdHandle, 2) ;

  lcdCursor      (lcdHandle, TRUE) ;
  lcdCursorBlink (lcdHandle, TRUE) ;

  waitForEnter () ;

  lcdCursor      (lcdHandle, FALSE) ;
  lcdCursorBlink (lcdHandle, FALSE) ;
  lcdClear       (lcdHandle) ;

  for (;;)
  {
    scrollMessage (0, cols) ;
    
    if (rows == 1)
      continue ;

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

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

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

    if (rows == 2)
      continue ;

    sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;

    lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
    lcdPuts     (lcdHandle, buf) ;

    pingPong (lcd, cols) ;
  }

  return 0 ;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) {
  struct tm *t;
  time_t tim;
  char buf[32];

  const char* programName = argv[0];
  const char* displayMessage = argv[1];

  if(argc < 2) {
    fprintf(stderr, "Usage: %s display_message\n", programName);
    return -1;
  }

  /* initialize WiringPi */
  wiringPiSetupSys();

  /* initalize LCD */
  lcdHandle = lcdInit(ROWS, COLUMNS, 4, AF_RS, AF_E, AF_D1, AF_D2, AF_D3, AF_D4, 0, 0, 0, 0);
  if(lcdHandle < 0) {
    fprintf(stderr, "lcdInit failed\n");
    return -1;
  }

  /* initalize PCF8574 module, NOTE that the device address must be right & can be acquired by "i2cdetect -y 1" command */
  pcf8574Setup(AF_BASE, 0x3f);

  /* turn on LCD backlight */
  pinMode(AF_BL, OUTPUT);
  digitalWrite(AF_BL, 1);

  /* set LCD into write mode */
  pinMode(AF_RW, OUTPUT);
  digitalWrite(AF_RW, 0);

  /* then we start to display various messages on the LCD screen */
  lcdClear(lcdHandle);             // clear the screen
  lcdPosition(lcdHandle, 3, 0);    // set the cursor on the the 4th column & 1st row
  lcdPuts(lcdHandle, "RPi");       // print the text on the LCD at current cursor postion
  lcdPosition(lcdHandle, 4, 1);    // set the cursor on the the 5th column & 2nd row
  lcdPuts(lcdHandle, "codelast");

  waitForEnter();

  lcdClear(lcdHandle);             // clear the screen
  lcdPosition(lcdHandle, 0, 0);    // set the cursor on the 1st column & 1st row
  lcdCursor(lcdHandle, true);      // turn the cursor on
  lcdCursorBlink(lcdHandle, true); // turn the cursor blink on

  waitForEnter();

  lcdCursor(lcdHandle, false);       // turn the cursor off
  lcdCursorBlink(lcdHandle, false);  // turn the cursor blink off
  lcdClear(lcdHandle);               // clear the screen
  lcdPuts(lcdHandle, "Will scroll...");

  waitForEnter();

  while(true) {
    scrollMessage(0, COLUMNS, displayMessage);  // scroll the specified message on the 1st row

    /* display current time on LCD */
    tim = time(NULL);
    t = localtime(&tim);
    sprintf(buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);

    lcdPosition(lcdHandle, (COLUMNS - 8) / 2, 1);
    lcdPuts(lcdHandle, buf);
  }
  
  return 0;
}