void SevenSeg::showNumber(uint8_t number) { if (!isNumberValid(number)) return; symbol_t symbol = static_cast<symbol_t>(number); showSymbol(symbol); }
void loseGame() { showSymbol(simbolo[10]); while(true) { digitalWrite(LED_PIN,HIGH); delay(500); digitalWrite(LED_PIN,LOW); delay(500); } }
void nextNumber() { counter++; if(counter>=MAX) { counter = 0; } second = !second; showSymbol(simbolo[sequence[counter]]); digitalWrite(ledPins[7],second); /* Aqui acende e apaga a bolinha do display, para saber se os segundos estao passando */ }
void MINIGAME_pressRightNumber() /* Minigame padrão */ { int n, i, c = randomNumber(0,2); /* Sorteia qual numero deve ser apertado */ for(i=0;i<MAX;i++) { n = randomNumber(0,2); /* Sorteia os numeros da sequencia */ sequence[i] = n; if(n==c) /* Se o numero for o que deve ser pressionado, iguale o pressArray a 1, mostrando que se deve pressionar nesse instante */ pressArray[i] = 1; else pressArray[i] = 0; } showSymbol(simbolo[sequence[0]]); /* Ja acende o primeiro numero da sequencia */ nextNumber(); getHelp(); }
void main(void) { /* Clock configuration -----------------------------------------*/ CLK_Config(); /* GPIO configuration ------------------------------------------*/ GPIO_Config_Init(); TIM3_Config(); TIM4_Config(); UART1_Config(); UART3_Config(); enableInterrupts(); DeviceStatus.workState = 16; Delay(200); //beep Set_Beep_OptionByte(); Beep_Init(BEEP_FREQUENCY_4KHZ); BEEP_LSICalibrationConfig(LSI_128kHz); showAll(); PowerOnBeep(); clear(); TIM2_Config(); showTemp(Temperature[DeviceStatus.workState], ON); showSymbol(SYMBOL_DEFAULT); FunctionReport(DeviceStatus.workState); while (1) { if(DeviceStatus.Time_100ms == 1) { if(UART1_GetFlagStatus(UART1_FLAG_IDLE) == SET) { if(DataSize != 0) { DataResolve(RxRecvBuffer, DataSize); DataSize = 0; } } DeviceStatus.Time_100ms = 0; } } }
void checkForNextLevel() { int i; if(rightRounds>6) /* Passa de nível se acertou 6 vezes seguidas */ { showSymbol(simbolo[10]); /* NULL */ for(i=0;i<5;i++) { digitalWrite(LED_PIN,HIGH); delay(200); digitalWrite(LED_PIN,LOW); delay(200); } delay(1000); MINIGAME_pressRightNumber(); /* Aqui deve ser feito o sorteio do minigame */ roundsPassed=0; roundHelp=true; rightRounds=0; counter=0; interval-=NEXT_LEVEL; } }
void receive_cmd(int sockfd) { Writen(sockfd, welcome, sizeof(welcome) - 1); ssize_t n = 0; char buf[MAX_BUFF]; int pipes[MAX_LINE][2]; int line = 0; memset(pipes, -1, sizeof(pipes)); setenv("PATH", "bin:.", TRUE); printf("%s\n" ,getenv("PATH")); int pos = 0; int unknown_command = 0; again: while ( (n = read(sockfd, &buf[pos], MAX_BUFF - pos)) > 0) { if (buf[pos + n - 1] != '\n') { printf("n-1 != newline...\n"); printf("n-1 is (%c), (%x)\n", buf[n-1], buf[n-1]); pos += n; goto again; } else { buf[pos + n] = '\0'; pos = 0; printf("I see newline!!\n"); } char *linv[MAX_LINE]; int linc = parse_line(buf, linv); for (int z = 0; z < linc; z++) { char *cmdv[MAX_CMDS]; int cmdc = parse_cmd(linv[z], cmdv); printf("line: %d\n unknwon: %d\n", line, unknown_command); int fd_in = pipes[line][0]; if (pipes[line][1] != -1 && !unknown_command) { Close(pipes[line][1]); pipes[line][1] = -1; } unknown_command = 0; for (int i = 0; i < cmdc; i++) { printf("cmdv[%d] = %s\n", i, cmdv[i]); char *argv[MAX_ARGS]; int argc = parse_argv(cmdv[i], argv); if (argc == 0) continue; for (int j = 0; j < argc; j++) printf("argv[%d] = %s\n", j, argv[j]); if (strcmp(argv[0], "exit") == 0) return; if (strcmp(argv[0], "printenv") == 0) { for (int j = 1; j < argc; j++) dprintf(sockfd, "%s=%s\n", argv[j], getenv(argv[j])); break; } if (strcmp(argv[0], "setenv") == 0) { if (argc == 3) setenv(argv[1], argv[2], TRUE); else dprintf(sockfd, "usage: setenv KEY VALIE\n"); break; } int fd_out; int fd_errout; int in_out_pipe[2]; int close_fd_out = 1; int close_fd_errout = 1; if (i + 1 < cmdc) { // If there's next command Pipe(in_out_pipe); fd_out = in_out_pipe[1]; fd_errout = in_out_pipe[1]; } else { // This is last one fd_out = sockfd; fd_errout = sockfd; int minus = 0; for (int q = 0; q < argc; q++) { if (strcmp(argv[q], ">") == 0) { fd_out = open(argv[q + 1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); argv[q] = '\0'; argc = q; break; } else if (argv[q][0] == '|' && argv[q][1] != '!') { int dest_pipe = parse_number(&argv[q][1]) + line; printf("dest_pipe std = %d\n", dest_pipe); if (pipes[dest_pipe][1] == -1) Pipe(pipes[dest_pipe]); fd_out = pipes[dest_pipe][1]; close_fd_out = 0; argv[q] = '\0'; minus++; } else if (argv[q][0] == '!' && argv[q][1] != '|') { int dest_pipe = parse_number(&argv[q][1]) + line; printf("dest_pipe err = %d\n", dest_pipe); if (pipes[dest_pipe][1] == -1) Pipe(pipes[dest_pipe]); fd_errout = pipes[dest_pipe][1]; close_fd_errout = 0; argv[q] = '\0'; minus++; } else if ( (argv[q][0] == '!' && argv[q][1] == '|') || (argv[q][0] == '|' && argv[q][1] == '!')) { int dest_pipe = atoi(&argv[q][2]) + line; printf("dest_pipe std+err = %d\n", dest_pipe); if (pipes[dest_pipe][1] == -1) Pipe(pipes[dest_pipe]); fd_out = pipes[dest_pipe][1]; fd_errout = pipes[dest_pipe][1]; argv[q] = '\0'; minus++; } } argc -= minus; } printf("pipe[0]=%d\n", in_out_pipe[0]); printf("pipe[1]=%d\n", in_out_pipe[1]); char exit_code = fork_process(argv, fd_in, fd_out, fd_errout, sockfd); if (close_fd_out && fd_out != sockfd && fd_out != -1) Close(fd_out); if (close_fd_errout && fd_errout != fd_out && fd_errout != sockfd && fd_errout != -1) Close(fd_errout); if (exit_code == ERR_CMD_NOT_FOUND) { dprintf(sockfd, "Unknown command: [%s].\n", argv[0]); unknown_command = 1; break; } else { if (fd_in != -1) Close(fd_in); fd_in = in_out_pipe[0]; } } showSymbol(sockfd); if (!unknown_command) line++; } } if (n < 0 && errno == EINTR) { pos += n; goto again; } else if (n < 0) { err_sys("str_echo: read error"); } }
void SevenSeg::clear(void) { showSymbol(SYMBOL_NOTHING); showDecimalPoint(false); }
void SevenSeg::showChar(char c) { symbol_t symbol; if (c == '0') symbol = SYMBOL_0; else if (c == '1') symbol = SYMBOL_1; else if (c == '2') symbol = SYMBOL_2; else if (c == '3') symbol = SYMBOL_3; else if (c == '4') symbol = SYMBOL_4; else if (c == '5') symbol = SYMBOL_5; else if (c == '6') symbol = SYMBOL_6; else if (c == '7') symbol = SYMBOL_7; else if (c == '8') symbol = SYMBOL_8; else if (c == '9') symbol = SYMBOL_9; else if (c == 'A') symbol = SYMBOL_A; else if (c == 'b') symbol = SYMBOL_b; else if (c == 'C') symbol = SYMBOL_C; else if (c == 'c') symbol = SYMBOL_c; else if (c == 'd') symbol = SYMBOL_d; else if (c == 'E') symbol = SYMBOL_E; else if (c == 'F') symbol = SYMBOL_F; else if (c == 'H') symbol = SYMBOL_H; else if (c == 'h') symbol = SYMBOL_h; else if (c == 'I') symbol = SYMBOL_I; else if (c == 'L') symbol = SYMBOL_L; else if (c == 'l') symbol = SYMBOL_l; else if (c == 'O') symbol = SYMBOL_O; else if (c == 'o') symbol = SYMBOL_o; else if (c == 'P') symbol = SYMBOL_P; else if (c == 'S') symbol = SYMBOL_S; else if (c == 'U') symbol = SYMBOL_U; else if (c == 'u') symbol = SYMBOL_u; else if (c == 'Y') symbol = SYMBOL_Y; else if (c == '-') symbol = SYMBOL_MINUS; else if (c == ' ') symbol = SYMBOL_NOTHING; else symbol = SYMBOL_MINUS; showSymbol(symbol); }