int main (void) { char keyPressed = 0; int keyPress = 0; int keyToggle = 0; int numberOfPresses = 0; unsigned char KeyPressed; wiringPiSetup (); pinMode (2, OUTPUT); // column 1 pinMode (3, OUTPUT); // column 2 pinMode (14, INPUT); // row 1 pinMode (5, INPUT); // row 2 pullUpDnControl (14, PUD_DOWN); // row 1 pullUpDnControl (5, PUD_DOWN); // row 2 for (;;) { //getkeypad(); keyPressed = getkeypad(); std::cout << "Button press = " << keyPressed << "\n"; delay(180); } return 0 ; }
int grabframe(char *buffer) { int x, ret=0; for(x=0;x<20;x++) { QC_grabdata(buffer+(x*(19200/20)),19200/20); if (checkkeypad()) if(getkeypad()==KP_DOORBELL) { ret=3; break; } if (checkring()) { ret=5; break; } } return ret; }
int state2 (void) { packet pkt; int errno, current=0, last=1, csz, x, y, *a, *b, *c,doorbell=0, ns; /* Set retransmit flag to 1 for first transmission */ int retransmitFlag=1, changeState=0; /* Init Camera */ QC_init (); while(changeState==0) { /* Check doorbell */ if (checkkeypad()) if (getkeypad()==KP_DOORBELL) { informdoorbell (); return 3; } /* Check Dallas Ring */ if (checkring()) return 5; /* Test for retransmit flag */ if(retransmitFlag==1) { /* Reset last frame so that when it is XORd a full picture is transmitted */ for(x=0;x<frameBufferSz;x++) { in[last][x]=0; } } /* Attempt to grab a frame */ if ((changeState = grabframe (in[current])) == 0) { /* Correction and smoothing */ for(x=0;x<frameBufferSz;x++) { if (in[current][x] != 0) in[current][x]=16-in[current][x]; } /* XOR frame with previous to obtain difference Here I exploit the fact that the 68040 is 32 bit so by treating the bytes as ints I can XOR 4 bytes at a time.... clever huh? */ a=(int *) in[current]; b=(int *) in[last]; c=(int *) diff; for (x = 0; x < (frameBufferSz / 4); x++) c[x] = a[x] ^ b[x]; /* Use RLE to compress the difference (We increment compressed by 1 to make room for a control byte) */ csz=RLEencode(diff,frameBufferSz,compressed+1); /* Tell the receiver whether this is the first frame in a sequence (compressed[0]=1) or not (compressed[0]=0) */ compressed[0]=retransmitFlag; retransmitFlag=0; /* Construct Packet */ pkt.datatype=VIDEO; pkt.length=csz/8+2; pkt.data=compressed; /* Place it in serial Queue and check for change of state instruction from client */ ns=senddata(&pkt); if(ns > 0) changeState=ns; /* Reverse what is current and what is previous */ current=1-current; last=1-last; } }; if (changeState == 3) informdoorbell (); return changeState; }
void main (void) { int i; unsigned char k; ringinfo ri; puts ("G7 hardware diagnostics\n\r"); puts ("\n\rInitialising board..."); boardinit (); puts (" done\n\r"); puts ("\n\r ** Timer test\n\r"); puts ("Waiting for 3 seconds..."); starttimer (1010000); while (gettimer () > 10000); puts (" done\n\r"); puts ("\n\r ** iButton reader test\n\r"); puts ("Place an iButton in the reader...\n\r"); i = 0; do { while (!checkring ()); ri = getringinfo (); i++; } while (ri.crc == 0xFF); puts ("iButton read ("); putn (i, 10, 2); puts (" times); product family "); putn (ri.product, 16, 2); puts ("; user ID "); for (i = 0; i < 6; i++) putn (ri.id [i], 16, 2); puts ("; CRC "); putn (ri.crc, 16, 2); puts ("\n\r"); puts ("\n\r ** Keypad test\n\r"); puts ("Press all the keys and the doorbell...\n\r"); for (i = 0; i < 13; i++) { k = getkeypad (); starttimer (40000); buzzerled (BUZZER); while (gettimer () > 10000); buzzerled (ALLOFF); stoptimer (); puts ("Key pressed: "); if (k < 10) putn (k, 10, 1); else switch (k) { case KP_STAR: puts ("*"); break; case KP_HASH: puts ("#"); break; case KP_DOORBELL: puts ("doorbell"); break; case KP_UNDEF: puts ("undefined ("); putn (k, 16, 2); puts (")"); break; } puts ("\n\r"); } puts ("\n\r ** Beeper test\n\r"); starttimer (10000000); buzzerled (BUZZER); while (gettimer () > 10000000 - 30000); buzzerled (ALLOFF); while (gettimer () > 10000000 - 40000); buzzerled (BUZZER); while (gettimer () > 10000000 - 70000); buzzerled (ALLOFF); stoptimer (); puts ("\n\r ** Door open test\n\r"); for (i = 0; i < 5; i++) { starttimer (210000); buzzerled (LEDGREEN); while (gettimer () > 110000); buzzerled (ALLOFF); while (gettimer () > 10000); stoptimer (); } puts ("\n\r ** Entry denied test\n\r"); for (i = 0; i < 5; i++) { starttimer (210000); buzzerled (LEDRED); while (gettimer () > 110000); buzzerled (ALLOFF); while (gettimer () > 10000); stoptimer (); } puts ("\n\r ** Door status test\n\r"); puts ("Close the door, then press a key\n\r"); mon_getc (); puts ("Door status is "); putn (getdoorstatus (), 10, 1); puts ("\n\r"); puts ("Open the door, then press a key\n\r"); mon_getc (); puts ("Door status is "); putn (getdoorstatus (), 10, 1); puts ("\n\r"); puts ("\n\r ** Testing done\n\r"); }