void set_Current(int current){ clear_Line(4); //delay_ms(200); char number[5]; sprintf(number,"%04d",current); dip204_set_cursor_position(1,4); dip204_write_string(number); }
void init_LCD(void){ static const gpio_map_t DIP204_SPI_GPIO_MAP = { {DIP204_SPI_SCK_PIN, DIP204_SPI_SCK_FUNCTION }, // SPI Clock. {DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION}, // MISO. {DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION}, // MOSI. {DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION} // Chip Select NPCS. }; spi_options_t spiOptions = { .reg = DIP204_SPI_NPCS, .baudrate = 1000000, .bits = 8, .spck_delay = 0, .trans_delay = 0, .stay_act = 1, .spi_mode = 0, .modfdis = 1 }; gpio_enable_module(DIP204_SPI_GPIO_MAP, sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0])); spi_initMaster(DIP204_SPI, &spiOptions); spi_selectionMode(DIP204_SPI, 0, 0, 0); spi_enable(DIP204_SPI); spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0); dip204_init(backlight_PWM, true); clear_Display(); dip204_hide_cursor(); } void init_Potentiometer(void){ const gpio_map_t ADC_GPIO_MAP = { {EXAMPLE_ADC_POTENTIOMETER_PIN, EXAMPLE_ADC_POTENTIOMETER_FUNCTION} }; gpio_enable_module(ADC_GPIO_MAP, sizeof(ADC_GPIO_MAP) / sizeof(ADC_GPIO_MAP[0])); AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET; adc_configure(&AVR32_ADC); adc_enable(&AVR32_ADC, EXAMPLE_ADC_POTENTIOMETER_CHANNEL); adc_start(&AVR32_ADC); } void init_CurrentSensor(void){ #define AVR32_ADC_AD_1_PIN 22 const gpio_map_t ADC_GPIO_MAP = { {AVR32_ADC_AD_3_PIN, AVR32_ADC_AD_3_FUNCTION} }; gpio_enable_module(ADC_GPIO_MAP, sizeof(ADC_GPIO_MAP) / sizeof(ADC_GPIO_MAP[0])); AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET; adc_configure(&AVR32_ADC); adc_enable(&AVR32_ADC, 3); adc_start(&AVR32_ADC); } void clear_Line(int line){ for(int i = 0; i<21;i++){ dip204_set_cursor_position(i,line); dip204_write_string(" "); } } void set_Direccion(int direccion){ if(direccion == 1){ clear_Line(2); dip204_set_cursor_position(1,2); dip204_write_string("Direccion:"); dip204_set_cursor_position(12,2); dip204_write_string("Forward"); } if(direccion == 0){ clear_Line(2); dip204_set_cursor_position(1,2); dip204_write_string("Direccion:"); dip204_set_cursor_position(12,2); dip204_write_string("Reverse"); } } void set_Velocidad(int velocidad){ clear_Line(3); dip204_set_cursor_position(1,3); dip204_write_string("Velocidad:"); dip204_set_cursor_position(12,3); switch (velocidad){ case 1: dip204_write_string("1"); break; case 2: dip204_write_string("2"); break; case 3: dip204_write_string("3"); break; case 4: dip204_write_string("4"); break; case 5: dip204_write_string("5"); break; case 6: dip204_write_string("6"); break; case 7: dip204_write_string("7"); break; case 8: dip204_write_string("8"); break; case 9: dip204_write_string("9"); break; case 10: dip204_write_string("10"); break; }//SWITCH }
void commandMode(char* author, char* title, char* filename, int row, int col, char** array){ //initialise the ncurses (void) initscr(); (void) nonl(); (void) cbreak(); // display curses at the bottom screen for command mode int h = 0; int w = 0; getmaxyx(stdscr, h, w); //move curses to the bottom of the screen move(h-1, 0); clrtoeol(); char buffer[20]; char *keySearch = " "; char* token1 = NULL; char* token2 = NULL; char* token3 = "0"; char* token4 = "0"; //reset string buffer for (int i =0; i<20;i++){ buffer[i] = ' '; } addch(':');//add : as default for(;;){ int ch = getch(); if(ch == ERR){ }else if(ch == 13){ if(buffer != NULL){ char *cstr = strdup(buffer); //clone the buffer token1 = strtok(cstr, keySearch); //cut it token2 = strtok(NULL, keySearch); token3 = strtok(NULL, keySearch); token4 = strtok(NULL, keySearch); if(strcmp(token1, "q") == 0){ //exit for (int i = 0; i < 20;i++){ buffer[i] = ' '; } //free(cstr); clear(); refresh(); endwin(); exit(EXIT_SUCCESS); //system("clear"); break; } else if ((strcmp(token1, "w") == 0) && ((strcmp(token2, "q") == 0) || (strcmp(token2, "P") == 0))){ //write level to current file writeToFile(author, title, filename, row, col, array); move(h - 1, 0); clrtoeol(); printw("Saved"); move(0,0); break; } else if ((strcmp(token1, "w") == 0) && (token2 != NULL)){ //write level to current file with specific name writeToFile(author, title, token2, row, col, array); move(h - 1, 0); clrtoeol(); printw("Saved to %s.pac", token2); move(0,0); break; } else if(strcmp(token1, "wq") == 0 && ((strcmp(token2, "q") == 0) || (strcmp(token2, "P") == 0))){ //write then quit writeToFile(author, title, filename, row, col, array); //free(cstr); clear(); refresh(); endwin(); exit(EXIT_SUCCESS); } else if(strcmp(token1, "wq") == 0 && token2 != NULL){ //write to specific file then quit; writeToFile(author, title, token2, row, col, array); //free(cstr); clear(); refresh(); endwin(); exit(EXIT_SUCCESS); } else if(strcmp(token1, "r") == 0 && token2 != NULL){ //read file name filename = token2; array = readFromFile(author, title, filename, &row, &col, array); clear(); refresh(); drawMap(author, title, filename, row, col, array); } else if(strcmp(token1, "n") == 0 && token2 != NULL && token3 != NULL && token4 != NULL && isdigit(*token3) && isdigit(*token4)){ //create new map with specific row and collumn int inputRow = atoi(token3); //int *inputRowPt = &inputRow; int inputCol = atoi(token4); //int *inputColPt = &inputCol; //initialize new array for writing char** newArray; newArray = malloc(inputCol*sizeof(char*)); for (int i = 0; i < inputRow; i++) { newArray[i] = malloc(inputRow*sizeof(char)); } for (int i = 0; i < inputRow; i++) { for (int j = 0; j < inputCol; j++) { newArray[i][j] = 's'; } } writeToFile(author, title, token2, inputRow, inputCol, newArray); //free(cstr); clear(); refresh(); endwin(); exit(EXIT_SUCCESS); } else if ((strcmp(token1, "m") == 0) && (token2 != NULL) && (token3 != NULL)){ //modify author and title writeToFile(token2, token3, filename, row, col, array); move(h - 1, 0); clrtoeol(); printw("%s.pac modified", filename); move(0,0); break; } else { clear_Line(h-1,0); move(h-1,0); printw("Error input"); break; } } else { for (int i =0; i<20;i++){ buffer[i] = ' '; //free(buffer); } move(h - 1, 0); clrtoeol(); move(0,0); break; } }else if (ch == 27){ //exit command mode with escape for (int i =0; i<20;i++){ buffer[i] = ' '; } move(h - 1, 0); clrtoeol(); move(0,0); break; } else if(ch == KEY_BACKSPACE){ int x = getcurx(stdscr); if(x != 1){ //erase character move(h-1, getcurx(stdscr)-1); delch(); buffer[getcurx(stdscr)-1] = '\0'; } } else { //read the character user input in command mode buffer[getcurx(stdscr)-1] = ch; addch(ch); } } }