int main(int argc, const char *argv[]) { char str[] = "abdcdfjienga"; put_ch(str); return 0; }
int WRTnode2r_spi_start(void) { int fd; unsigned char len = 0; unsigned char i = 0; const char data[] = RT2880_SPI_START_STR; fd = open("/dev/spiS0", O_RDWR); if (fd <= 0) { fprintf(stderr, "Please insmod module spi_drv.o!\n"); return -1; } len = strlen(data); if(0 == len) { fprintf(stderr, "write length is 0.\n"); close(fd); return -1; } put_len(fd, len); for(i=0; i<len; i++) { put_ch(fd, data[i]); DEBUG_PRINT("write data[%d] = 0x%x %c\n", i, data[i] , data[i]); } close(fd); return 0; }
size_t WRTnode2r_spi_write(char* data, int len, int is_force) { int chk_match, size, fd; unsigned char buf; unsigned char status = 0; unsigned char i = 0; fd = open("/dev/spiS0", O_RDWR); if (fd <= 0) { fprintf(stderr, "Please insmod module spi_drv.o!\n"); return -1; } if (is_force) { status = read_status(fd); DEBUG_PRINT("write status = 0x%x\n", status); if(status & SPI_STATUS_OK) { if(status & SPI_STATUS_7688_WRITE_TO_STM32_F) { fprintf(stderr, "stm32 write buf full.\n"); goto err; } } else { fprintf(stderr, "stm32 spi read error.\n"); } } else { do{ status = read_status(fd); DEBUG_PRINT("write status = 0x%x\n", status); if((status & SPI_STATUS_OK) && (!(status & SPI_STATUS_7688_WRITE_TO_STM32_F))) { break; } //usleep(SPI_MCU_CHECK_STATUS_DELAY_US); } while(1); } if(0 == len) { fprintf(stderr, "write length is 0.\n"); goto err; } put_len(fd, len); for(i=0; i<len; i++) { put_ch(fd, data[i]); DEBUG_PRINT("write data[%d] = 0x%x %c\n", i, data[i] , data[i]); } close(fd); return 0; err: close(fd); return -1; }
int main(int argc, const char *argv[]) { Console console; console.begin = 0; init_buf(&console); printf("init buf:\n"); print_buf(&console); int y = 0; char ch = '0'; int warp = 0; for (y=0 ; y < 20; ++y) { for (int x=0 ; x < BUF_W; ++x) { put_ch(&console, x, y, ch); printf("(%d, %d)\t\t", x, y); printf("input: %c\t\t", ch); printf("begin: %d\t\t", console.begin); if (y >= PAGE*BUF_H) { //printf("warp!!\n"); warp = 1; } printf("scroll: "); #if 1 if (warp == 1) { int index_y = (console.begin + BUF_H) % (PAGE*BUF_H); //for (int i = 0 ; i < (PAGE-1)*BUF_H ; ++i) // begin 往下加上 BUF_H, 再往下加 (PAGE-1)*BUF_H 個 (一次加一) // ex: begin = 5, (5+3) % 9 = 8 // 8, 9%9 = 0, 10%9 = 1, 11%9 = 2 , 12%9 = 3 , 13%9 = 4 for (int i = 0 ; i < (PAGE-1)*BUF_H ; ++i) { printf("%d ", (index_y+ (PAGE-1)*BUF_H - 1- i)%(PAGE*BUF_H) ); } } else #endif { for (int i = console.begin-1 ; i >= 0 ; --i) printf("%d ", i); } printf("\n"); } ++ch; if (ch==':') ch = '0'; printf("print buf:\n"); print_buf(&console); printf("print screen (%dX%d):\n", BUF_W, BUF_H); print_screen(&console); printf("scroll screen\n"); scroll(&console, -1); print_screen(&console); } return 0; }
/* * playit: * Play a given game, handling all the curses commands from * the driver. */ void playit() { int ch; int y, x; u_int32_t version; if (read(Socket, (char *) &version, LONGLEN) != LONGLEN) { bad_con(); /* NOTREACHED */ } if (ntohl(version) != (unsigned long)HUNT_VERSION) { bad_ver(); /* NOTREACHED */ } errno = 0; # ifdef OTTO Otto_count = 0; # endif nchar_send = MAX_SEND; while ((ch = GETCHR()) != EOF) { # ifdef DEBUG fputc(ch, stderr); # endif switch (ch & 0377) { case MOVE: y = GETCHR(); x = GETCHR(); # ifdef USE_CURSES move(y, x); # else mvcur(cur_row, cur_col, y, x); cur_row = y; cur_col = x; # endif break; case ADDCH: ch = GETCHR(); # ifdef OTTO switch (ch) { case '<': case '>': case '^': case 'v': otto_face = ch; # ifdef USE_CURSES getyx(stdscr, otto_y, otto_x); # else otto_y = cur_row; otto_x = cur_col; # endif break; } # endif put_ch(ch); break; case CLRTOEOL: clear_eol(); break; case CLEAR: clear_the_screen(); break; case REFRESH: refresh(); break; case REDRAW: redraw_screen(); refresh(); break; case ENDWIN: refresh(); if ((ch = GETCHR()) == LAST_PLAYER) Last_player = TRUE; ch = EOF; goto out; case BELL: beep(); break; case READY: refresh(); if (nchar_send < 0) # if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) tcflush(STDIN, TCIFLUSH); # else # ifndef TCFLSH (void) ioctl(STDIN, TIOCFLUSH, &in); # else (void) ioctl(STDIN, TCFLSH, 0); # endif # endif nchar_send = MAX_SEND; # ifndef OTTO (void) GETCHR(); # else Otto_count -= (GETCHR() & 0xff); if (!Am_monitor) { # ifdef DEBUG fputc('0' + Otto_count, stderr); # endif if (Otto_count == 0 && Otto_mode) otto(otto_y, otto_x, otto_face); } # endif break; default: # ifdef OTTO switch (ch) { case '<': case '>': case '^': case 'v': otto_face = ch; # ifdef USE_CURSES getyx(stdscr, otto_y, otto_x); # else otto_y = cur_row; otto_x = cur_col; # endif break; } # endif put_ch(ch); break; } } out: (void) close(Socket); }