int main(void) { // packets[0] = UPC-A Barcode // packets[1] = Item Name // packets[2] = Number of Servings // packets[3] = Scan Date (MM/DD/YYYY); char** packets; char return_key; char package[] = "<keypad><x>*/"; TRISGbits.TRISG7 = 1; //in breakout pin RF2 (row 1) TRISGbits.TRISG2 = 1; //in breakout pin RA2 (row 2) TRISCbits.TRISC0 = 1; //in breakout pin RB8 (row 3) TRISCbits.TRISC1 = 1;//in breakout pin RB9 (row 4) TRISEbits.TRISE12 = 0; //in breakout pin RB12 (col 1) TRISCbits.TRISC2 = 0; //in breakout pin RB10 (col 2) TRISEbits.TRISE14 = 0; //in breakout pin RB14 (col 3) ANSELGbits.ANSG7 = 0; //Row 1-4 //configuring all pins as digital ANSELGbits.ANSG2 = 0; ANSELCbits.ANSC0 = 0; ANSELCbits.ANSC1 = 0; ANSELEbits.ANSE12 = 0; //Col 1-3 ANSELCbits.ANSC2 = 0; ANSELEbits.ANSE14 = 0; InitClock(); InitUART2(); /* Infinite Loop */ while ( TRUE ) { if (rx_complete) { break; } return_key = 'X'; //initialize return key to default return variable from readKeyboard() while(return_key == 'X'){ //while nothing is pressed, keep on making calls return_key = readKeyboard(); } if(return_key != 'X'){ //if return_key is not default key, send to RPi package[9] = return_key; U1MODEbits.UARTEN = 1; // Re-enable UART if not already done printf("%s", package); } while(readKeyboard() != 'X'){ //no operation till next key is pressed. } } packets = get_barcode(); read_sd_card(packets); }
void int_80(size_t call, size_t fd, char *buffer, size_t count) { switch (call) { case WRITE: if (fd == STDOUT) { writeScreen(buffer, count); }/*else{ write(fd, buffer, count); }*/ break; case ERASE: if (fd == STDOUT) { eraseScreen(buffer, count); } break; case READ: if (fd == STDIN) { readKeyboard(buffer, count); } break; default: break; } return; }
// ***************************************************************************** // ***************************************************************************** // Section: Main Entry Point // ***************************************************************************** // ***************************************************************************** int main ( void ) { /* Call the System Intialize routine*/ SYS_Initialize ( ) ; /*Initialize Timer*/ TIMER_SetConfiguration ( TIMER_CONFIGURATION_RTCC ) ; TRISGbits.TRISG7 = 1; //in breakout pin RF2 (row 1) TRISGbits.TRISG2 = 1; //in breakout pin RA2 (row 2) TRISCbits.TRISC0 = 1; //in breakout pin RB8 (row 3) TRISCbits.TRISC1 = 1;//in breakout pin RB9 (row 4) TRISEbits.TRISE12 = 0; //in breakout pin RB12 (col 1) TRISCbits.TRISC2 = 0; //in breakout pin RB10 (col 2) TRISEbits.TRISE14 = 0; //in breakout pin RB14 (col 3) ANSELGbits.ANSG7 = 0; //Row 1-4 //configuring all pins as digital ANSELGbits.ANSG2 = 0; ANSELCbits.ANSC0 = 0; ANSELCbits.ANSC1 = 0; ANSELEbits.ANSE12 = 0; //Col 1-3 ANSELCbits.ANSC2 = 0; ANSELEbits.ANSE14 = 0; char return_key; /* Infinite Loop */ while ( 1 ) { return_key = 'X'; //initialize return key to default return variable from readKeyboard() while(return_key == 'X'){ //while nothing is pressed, keep on making calls return_key = readKeyboard(); } if(return_key != 'X'){ //if return_key is not default key, print to LCD //should transmit to UART at this point LCD_PutChar(return_key); } while(readKeyboard() != 'X'){ //no operation till next key is pressed. } } }
void sig_handler(int signo) { char buf[1]; if (signo == SIGIO) //ASSERTION That the correct signal is received. { readKeyboard(); } }
void task2() { uint8_t val = keyboardToInt(readKeyboard()); if (val) { binToDecDigits(val, disp, 4); UDR = 'a' + val; } }
/*---------------------------------------------------------------------- Parameters: map - the map to write fname - the name of the file to write to. Description: write a map out to a file in hips format ----------------------------------------------------------------------*/ void MapIShowImage(IMAP *map, char *name) { IMAGE image ; #if USE_XWIN xwindow_type *xwin ; #endif ImageInitHeader(&image, map->cols, map->rows, PFINT, 1) ; image.image = (unsigned char *)map->image ; #if USE_XWIN xwin = DebugShowImage(&image, NULL, 1, name, 1) ; readKeyboard(&image, xwin, 1) ; DebugEnd(xwin) ; #endif }
void main() { volatile uchar nPulse = 0; // numero dell'impulso da controllare. if==0 allora vai CONTINUO. volatile uchar loopCounter = 0; volatile uchar delayKeyb = 250; rom char *BLANK16 = " "; // nPSA = Tmr0Value; nPSA = 0; mSecScale = 0; TMRO_TabEntry = 0; irqType = 0; KeybValue = 0; // valore del HC148 uchar j; // uchar Tmr0Value = eeprom_read(_EEPROM); Init_Registers(); initPorts(); LCD_initialize(); LCD_Clear(); // intcon_RBIE = 1; // Change of state (COS) on RB4 to RB7 // stTMR0.tmr0Value = TMR0_vals[mSecScale]; // stTMR0.delayVal = TMR0_cntr[mSecScale]; // stTMR0.psaValue = TMR0_psa[mSecScale]; // stTMR0.scale = mSecSCALE[mSecScale]; stTMR0.tmr0Value = TMR0_vals[mSecScale]; stTMR0.delayVal = TMR0_delay[mSecScale]; stTMR0.psaValue = TMR0_psa[mSecScale]; stTMR0.scale = mSecSCALE[mSecScale]; stTMR0.extraCounter = TMR0_cntr[mSecScale]; delayNum = 0; while (1) { clear_wdt(); displayCfgValues(); loopCounter++; if (loopCounter > 3) delayKeyb = 200; // Next wait più basso if (loopCounter >10) delayKeyb = 10; // Next wait più basso readKeyboard(delayKeyb); // LCD_printf(0,0, "KEYB: %02X", KeybValue); switch (KeybValue) { // Value of PSA 0x00 to 0x07 case KEY_PSA_UP: case KEY_PSA_DN: stTMR0.psaValue++; if (stTMR0.psaValue > 0x08) stTMR0.psaValue = 0x00; continue; // increments the TMR0 value by 4096 units case TMR0_UP_0x1000: stTMR0.extraCounter++; continue; // increments the TMR0 value by 256 units case TMR0_UP_0x0100: stTMR0.tmr0Value += 0x0100; continue; // increments the TMR0 value by 16 units case TMR0_UP_0x0010: stTMR0.tmr0Value += 0x0010; continue; // decrements the TMR0 value by 1 units case TMR0_UP_0x0001: stTMR0.tmr0Value++; continue; // value of time to select (1mSec, 10mSec, 100mSec, 1Sec) case KEY_mSecSCALE: case KEY_mSecSCALE_DN: TMR0_psa[mSecScale] = stTMR0.psaValue ; TMR0_cntr[mSecScale] = stTMR0.extraCounter; TMR0_vals[mSecScale] = stTMR0.tmr0Value ; mSecSCALE[mSecScale] = stTMR0.scale ; mSecScale++; if (mSecScale > 4) mSecScale = 0; stTMR0.psaValue = TMR0_psa[mSecScale]; stTMR0.extraCounter = TMR0_cntr[mSecScale]; stTMR0.tmr0Value = TMR0_vals[mSecScale]; stTMR0.scale = mSecSCALE[mSecScale]; continue; case TMR0_DN_0x1000: stTMR0.extraCounter--; continue; // decrements the TMR0 value by 256 units case TMR0_DN_0x0100: stTMR0.tmr0Value -= 0x0100; continue; // decrements the TMR0 value by 16 units case TMR0_DN_0x0010: stTMR0.tmr0Value -= 0x0010; continue; // decrements the TMR0 value by 1 units case TMR0_DN_0x0001: stTMR0.tmr0Value--; continue; case KEY_START2: case KEY_START: openGate(); continue; // decrements the TMR0 value by 4096 units default: break; } toggle_pin( MyLED ); // attento al ';' finale se metterlo nella MACRO o meno TMR0_GATE_LINE = 0; //Turn OFF Gate line intcon_RBIE = 1; //Enable PortB4-7 IRQ sleep(); intcon_RBIE = 0; //Disable PortB4-7 IRQ delayKeyb = 250; // valore di default } }
size_t _read(int fd, void* buf, size_t length) { return readKeyboard(buf, length); }
/* Keyboard Thread Checks the keys on the keyboard. Waits for an OSsignal from the Keyboard pins interrupts before checking what key has been pressed. It has three main states Idle, Record Sequence, or PRT Idle = simply waits for a valid key press Record Sequence = begins recording the boards movements and saves to a buffer PRT = Pitch, Roll, Time waits for User input to send the desired angles to receiver. */ void keyboard_thread(void const *argument) { struct Values *values = (struct Values*)argument; uint8_t keyboard_mode=0; float currentRoll=0; float currentPitch=0; float previousRoll=0; float previousPitch=0; float mstime=0; uint8_t keyCurrent = 0xFF; while(1){ // Wait for keypad Interrupt osSignalWait(0x08, osWaitForever); // Read the current key keyCurrent = readKeyboard(); transmit_locked = 1; // Lock transmitter //printf("Keyboard Value 0x%x\n", keyCurrent); //Record Angle Sequence State if((keyCurrent == D) && (keyboard_mode == KEYBOARD_STATE_IDLE)){ //printf("Recording sequence!!! \n"); float pitchBuffer[256]; float rollBuffer[256]; uint32_t time_ms = 100; // Record sequence int index = 0; //Record 256 samples or 25 seconds of movemement while (index < 256) { pitchBuffer[index] = measurements.pitch; rollBuffer[index] = measurements.roll; //printf("Index = %i Pitch = %f Roll = %f \n",index,pitchBuffer[index],rollBuffer[index]); index++; osDelay(time_ms); //Delay of 100ms } //printf("Sending sequence!!! \n"); //Send the sequence transmit_record_sequence(256, pitchBuffer, rollBuffer, (float) time_ms); //printf("Done transmitting sequence!!! \n"); osDelay(10000); transmit_locked = 0; //Enable Broadcast Mode } //PRT STATE, sends Desired Pitch,Roll and Time else if((keyCurrent==A) || (keyboard_mode== KEYBOARD_STATE_PRT)){ keyboard_mode = KEYBOARD_STATE_PRT; if(keyCurrent == A){ //Reset Variables osMutexWait(measureUpdate, osWaitForever); values->follow=0; previousRoll= values->roll; previousPitch = values->pitch; measurements.rollIncrement = 0; measurements.pitchIncrement = 0; measurements.time = 0; osMutexRelease(measureUpdate); currentRoll=0; //Begin Keypad Transmission Command for (int i = 0; i < 1; i++) transmit_keypad_begin(); //read Roll readValue(¤tRoll, &tid_keyboard); } //Read Pitch on B press if(keyCurrent == B){ currentPitch=0; readValue(¤tPitch, &tid_keyboard); } //Read Time on C press if(keyCurrent == C){ mstime=0; readValue(&mstime, &tid_keyboard); //Convert time to count value and pitch and roll to increment values osMutexWait(measureUpdate, osWaitForever); values->time= (float)(mstime/100); values->rollIncrement = (currentRoll-previousRoll)/(mstime/100); values->pitchIncrement = (currentPitch-previousPitch)/(mstime/100); //printf("Roll %f Pitch %f Time %f ms\n", currentRoll, currentPitch, mstime); // Transmit Data //printf("SENDING pitchIncrement = %f \n",values->pitchIncrement); transmit_keypad_pitch(values->pitchIncrement); osDelay(100); //printf("SENDING rollIncrement = %f \n",values->rollIncrement); transmit_keypad_roll(values->rollIncrement); osDelay(100); //printf("SENDING time = %f \n",values->time); transmit_keypad_time(values->time); osDelay(100); //printf("SENDING END \n"); transmit_keypad_end(); osDelay(100); osMutexRelease(measureUpdate); //osTimerStart(timerid_motor,100); //printf("Time %f\n", values->time); // Start transmitting again after delay osDelay(6000); transmit_locked = 0; // unlock transmit keyboard_mode = KEYBOARD_STATE_IDLE; } } else { transmit_locked = 0; } //Add delay before allowing next keyboard read to avoid debouncing. osDelay(200); osSignalClear(tid_keyboard, 0x08); } }
void UinputEvPoll::doPoll() { int epfd; int ret; int i; struct epoll_event ev; struct epoll_event evs[16]; epfd = epoll_create1(0); if (epfd < 0) { printf("triambience: failed to create epoll instance\n"); emit finished(); return; } memset(&ev, 0, sizeof(ev)); ev.events = EPOLLIN; ev.data.fd = _uinputfd; ret = epoll_ctl(epfd, EPOLL_CTL_ADD, _uinputfd, &ev); if (ret) { printf("triambience: Couldn't add to epoll\n"); close(epfd); emit finished(); return; } printf("triambience: Starting tristate key polling.\n"); for (;;) { // Checks if the process should be aborted mutex.lock(); bool abort = _abort; mutex.unlock(); if (abort) { break; } ret = epoll_wait(epfd, evs, 16, -1); if (ret < 0) { if (errno == EINTR) continue; else break; } for (i = 0 ; i<ret ; i++) { readKeyboard(evs[i].data.fd); } } close(epfd); emit finished(); }