/* Write a u16 to the device, and return one u16 read back */ int max3110_out(struct uart_max3110 *max, const u16 out) { u16 tmp; int ret; ret = max3110_write_then_read(max, (u8 *)&out, (u8 *)&tmp, 2, 1); if (ret) return ret; /* If some valid data is read back */ if (tmp & MAX3110_READ_DATA_AVAILABLE) receive_char(max, (tmp & 0xff)); return ret; }
void read_and_execute() { char tempChar; while(HasChars()) { receive_char(&tempChar); data[current_pos] = tempChar; if(tempChar == '\r') { parse(); } current_pos++; } }
static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) { struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; const unsigned char *p; char *f, flags = 0; int i; for (i = count, p = cp, f = fp; i; i--, p++) { if (f) flags = *f++; if (flags == TTY_NORMAL) { receive_char(pInfo, *p); } else { receive_error(pInfo, flags); } } }
void receive_GRB_value(){ unsigned char IO_char = 'A'; //default value, some random letter int numberOfLED = 0; unsigned char theColors[(NUMBER_OF_LEDS*3)]; for(;;){ if(numberOfLED < (NUMBER_OF_LEDS*3)){ //receive 177 bytes, for 59 leds one byte per color receive_char(&IO_char); theColors[numberOfLED] = IO_char; numberOfLED++; } else{ break; } } //uart_put_int_decimal(theColors[0][0]); numberOfLED = 0; convert_full_ledstrip(theColors); delay(50); //led reset time //uart_put_string("\nSUCCESS"); }
void play_hangman(int socket_id, userpw_t* User) { word_t* hangmanWord = getRandomWord(); send_number(socket_id, strlen(hangmanWord->object)); send_number(socket_id, strlen(hangmanWord->objectType)); char* objGuessing = obfuscate_string(hangmanWord->object); char* objTypeGuessing = obfuscate_string(hangmanWord->objectType); send_word(socket_id, objGuessing); send_word(socket_id, objTypeGuessing); int guessesAllowedServer = determineWordLength(hangmanWord); int correct = 2; do { char received = receive_char(socket_id); reveal_string(hangmanWord->object, objGuessing, received); reveal_string(hangmanWord->objectType, objTypeGuessing, received); send_word(socket_id, objGuessing); send_word(socket_id, objTypeGuessing); guessesAllowedServer--; if(wordGuessed(objGuessing) == 1 && wordGuessed(objTypeGuessing) == 1) { correct = 1; pthread_mutex_lock(&leaderboardLock); int* gamesWon = User->gamesWon; (*gamesWon)++; pthread_mutex_unlock(&leaderboardLock); } } while (guessesAllowedServer > 0 && correct == 2); int* gamesPlayed = User->gamesPlayed; (*gamesPlayed)++; }
int main(void) { uint32_t i; char c; char s1[64], s2[64]; uint8_t bufb[512]; init_serial(); lcd_init(); lcd_printf("Hello World! \n n: %d", 152); // init card send_str("\ninit mmc card: "); c = mmc_init(); if (c) { send_str("failed ("); send_int(c); send_str(")\n"); } else { send_str("success\n"); init_partition(0); c = 'h'; while (1) { switch (c) { case 'l' : ls(); break; case 'c' : send_str("dir: "); receive_str(s1); cd(s1); break; case 'r' : send_str("rename file: "); receive_str(s1); send_str("new name: "); receive_str(s2); rn(s1, s2); break; case 'd' : send_str("delete file: "); receive_str(s1); del(s1); break; case 'p' : send_str("file: "); receive_str(s1); cat(s1); break; case 't' : send_str("name: "); receive_str(s1); touch(s1); break; case 's' : send_str("sector: 0x"); i = receive_hex(); if (mmc_readsector(i, bufb)) { send_str("error reading sector\n"); } else { dump_sector(bufb); send_char('\n'); } break; case 'h' : default : send_str("h - help\nl - dir listing\nc - change dir\nd - delete file\np - print file contents\nt - create empty file\ns - dump sector\n"); break; } // prompt send_str("> "); c = receive_char(); send_char('\n'); } } while (1) ; return 0; }
{ print1602(":",1,4); print1602(":",1,7); } } } } void interrupt_serial1(void) interrupt 4 { unsigned char k; k =receive_char(); printchar1602(k , 1, 15); if(k=='A') { temp_set++; if(temp_set>70) temp_set = 70; } if(k=='B') { temp_set--; if(temp_set<10) temp_set = 10; } if(k=='T') {
// Take input from a computer and load it onto the cube buffer void rs232() { char tempval; int x = 0; int y = 0; int escape = 0; while (current_mode == MODE_BINARY) { // Switch state on red LED for debugging // Should switch state every time the code // is waiting for a byte to be received. debug_blink(LED_RED); // Wait until a byte has been received while(!HasChars()); // Load the received byte from rs232 into a buffer. receive_char(&tempval); // Uncommet this to echo data back to the computer // for debugging purposes. //SendChar(tempval); // Every time the cube receives a 0xff byte, // it goes into sync escape mode. // if a 0x00 byte is then received, the x and y counters // are reset to 0. This way the x and y counters are // always the same on the computer and in the cube. // To send an 0xff byte, you have to send it twice! // Go into sync escape mode if (tempval == 0xff) { // Wait for the next byte while(!HasChars()); // Get the next byte receive_char(&tempval); // Sync signal is received. // Reset x and y counters to 0. if (tempval == 0x00) { x = 0; y = 0; escape = 1; } // if no 0x00 byte is received, proceed with // the byte we just received. } if (escape == 0) { // Load data into the current position in the buffer fb[x][y] = tempval; // Check if we have reached the limits of the buffer array. if (y == 7) { if (x == 7) { // All data is loaded. Reset both counters y = 0; x = 0; // Copy the data onto the cube. tmp2cube(); } else { // A layer is loaded, reset y and increment x. x++; y = 0; } } else { // We are in the middle of loading a layer. increment y. y++; } } else { escape = 0; } } }