static void send_file_to_fpga(std::string &file_name, gpio &error, gpio &done) { std::ifstream bitstream; std::cout << "File name - " << file_name.c_str() << std::endl; bitstream.open(file_name.c_str(), std::ios::binary); if (!bitstream.is_open()) std::cout << "File " << file_name << " not opened succesfully." << std::endl; spidev spi("/dev/spidev1.0"); char buf[BUF_SIZE]; char rbuf[BUF_SIZE]; do { bitstream.read(buf, BUF_SIZE); spi.send(buf, rbuf, bitstream.gcount()); if (error.get_value()) std::cout << "INIT_B went high, error occured." << std::endl; if (!done.get_value()) std::cout << "Configuration complete." << std::endl; } while (bitstream.gcount() == BUF_SIZE); }
void PinTinDisplay::CallDisplayOkMessage(char* title) { bool isConfirmed = false; bool buttonHasBeenReleased = false; int currentRow = 0; this->oled.setCursor(0, 0); this->oled.clear(PAGE); oled.print(title); this->oled.setCursor(48, 40); this->oled.print("OK"); this->oled.setDrawMode(XOR); this->oled.rectFill(46, 38, 14, 12); this->oled.setDrawMode(NORM); this->oled.display(); while(!isConfirmed) { usleep(2000); if (BUTTON_UP.pinRead() == HIGH && BUTTON_DOWN.pinRead() == HIGH && BUTTON_SELECT.pinRead() == HIGH) buttonHasBeenReleased = true; if (BUTTON_SELECT.pinRead() == LOW && buttonHasBeenReleased){ buttonHasBeenReleased = false; isConfirmed = true; } } }
static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &done) { std::ifstream bitstream; bitstream.open(file_name.c_str(), std::ios::binary); if (!bitstream.is_open()) throw uhd::os_error( "Could not open the file: " + file_name ); spidev spi("/dev/spidev1.0"); char buf[BUF_SIZE]; char rbuf[BUF_SIZE]; do { bitstream.read(buf, BUF_SIZE); spi.send(buf, rbuf, bitstream.gcount()); if (error.get_value()) throw uhd::os_error("INIT_B went high, error occured."); if (!done.get_value()) UHD_MSG(status) << "Configuration complete." << std::endl; } while (bitstream.gcount() == BUF_SIZE); }
/*----------------------------------------------------------------------------*/ void button_testing_deinit(void) { HA_NOTIFY("\n*** Deinitializing hardware ***\n" "All IO pins will be reset to IN_FLOATING\n"); MB1_up.gpio_shutdown(); MB1_down.gpio_shutdown(); MB1_left.gpio_shutdown(); MB1_right.gpio_shutdown(); MB1_select.gpio_shutdown(); }
/*----------------------------------------------------------------------------*/ void led7seg_testing_init(void) { HA_NOTIFY("\n*** Initializing hardware for LED7SEG tests ***\n" "L1 pin: port: %u (port A = 0,...), pin: %u\n" "L2 pin: port: %u (port A = 0,...), pin: %u\n" "L3 pin: port: %u (port A = 0,...), pin: %u\n" "L4 pin: port: %u (port A = 0,...), pin: %u\n" "A pin: port: %u (port A = 0,...), pin: %u\n" "B pin: port: %u (port A = 0,...), pin: %u\n" "C pin: port: %u (port A = 0,...), pin: %u\n" "D pin: port: %u (port A = 0,...), pin: %u\n" "h pin: port: %u (port A = 0,...), pin: %u\n", l1_params.port, l1_params.pin, l2_params.port, l2_params.pin, l3_params.port, l3_params.pin, l4_params.port, l4_params.pin, a_params.port, a_params.pin, b_params.port, b_params.pin, c_params.port, c_params.pin, d_params.port, d_params.pin, h_params.port, h_params.pin); MB1_L1.gpio_init(&l1_params); MB1_L2.gpio_init(&l2_params); MB1_L3.gpio_init(&l3_params); MB1_L4.gpio_init(&l4_params); MB1_A.gpio_init(&a_params); MB1_B.gpio_init(&b_params); MB1_C.gpio_init(&c_params); MB1_D.gpio_init(&d_params); MB1_h.gpio_init(&h_params); }
/** \brief Initialization of edOLED Library. Setup IO pins for SPI port then send initialization commands to the SSD1306 controller inside the OLED. */ void edOLED::begin() { // default 5x7 font setFontType(0); setColor(WHITE); setDrawMode(NORM); setCursor(0,0); spiSetup(); RST_PIN.pinWrite(HIGH); //(digitalWrite(rstPin, HIGH); usleep(5000); // VDD (3.3V) goes high at start, lets just chill for 5 ms RST_PIN.pinWrite(LOW); // bring reset low usleep(10000); // wait 10ms RST_PIN.pinWrite(HIGH); //digitalWrite(rstPin, HIGH); // Init sequence for 64x48 OLED module command(DISPLAYOFF); // 0xAE command(SETDISPLAYCLOCKDIV); // 0xD5 command(0x80); // the suggested ratio 0x80 command(SETMULTIPLEX); // 0xA8 command(0x2F); command(SETDISPLAYOFFSET); // 0xD3 command(0x0); // no offset command(SETSTARTLINE | 0x0); // line #0 command(CHARGEPUMP); // enable charge pump command(0x14); command(NORMALDISPLAY); // 0xA6 command(DISPLAYALLONRESUME); // 0xA4 command(SEGREMAP | 0x1); command(COMSCANDEC); command(SETCOMPINS); // 0xDA command(0x12); command(SETCONTRAST); // 0x81 command(0x8F); command(SETPRECHARGE); // 0xd9 command(0xF1); command(SETVCOMDESELECT); // 0xDB command(0x40); command(DISPLAYON); //--turn on oled panel clear(ALL); // Erase hardware memory inside the OLED }
/*----------------------------------------------------------------------------*/ void button_testing(void) { start_waiting_esc_character(); HA_NOTIFY("\n*** BUTTON & MBOARD TEST ***\n" "(press ESC to quit).\n"); while(1) { if(is_press_button(MB1_up.gpio_read())) { testing_delay_us(10000); while(is_press_button(MB1_up.gpio_read())); HA_NOTIFY("Press button UP.\n"); } if(is_press_button(MB1_down.gpio_read())) { testing_delay_us(10000); while(is_press_button(MB1_down.gpio_read())); HA_NOTIFY("Press button DOWN.\n"); } if(is_press_button(MB1_left.gpio_read())) { testing_delay_us(10000); while(is_press_button(MB1_left.gpio_read())); HA_NOTIFY("Press button LEFT.\n"); } if(is_press_button(MB1_right.gpio_read())) { testing_delay_us(10000); while(is_press_button(MB1_right.gpio_read())); HA_NOTIFY("Press button RIGHT.\n"); } if(is_press_button(MB1_select.gpio_read())) { testing_delay_us(10000); while(is_press_button(MB1_select.gpio_read())); HA_NOTIFY("Press button SELECT.\n"); } /* poll the esc_pressed */ if (esc_pressed == true) { break; } }//End while(). stop_waiting_esc_character(); HA_NOTIFY("Test stopped.\n"); }
/*----------------------------------------------------------------------------*/ void led7seg_testing_deinit(void) { HA_NOTIFY("\n*** Deinitializing hardware ***\n" "All IO pins will be reset to IN_FLOATING\n"); /* Shutdown GPIOs */ MB1_L1.gpio_shutdown(); MB1_L2.gpio_shutdown(); MB1_L3.gpio_shutdown(); MB1_L4.gpio_shutdown(); MB1_A.gpio_shutdown(); MB1_B.gpio_shutdown(); MB1_C.gpio_shutdown(); MB1_D.gpio_shutdown(); MB1_h.gpio_shutdown(); }
/*----------------------------------------------------------------------------*/ void button_testing_init(void) { HA_NOTIFY("up pin: port: %u (port A = 0,...), pin: %u.\n" "down pin: port: %u (port A = 0,...), pin: %u.\n" "left pin: port: %u (port A = 0,...), pin: %u.\n" "right pin: port: %u (port A = 0,...), pin: %u.\n" "select pin: port: %u (port A = 0,...), pin: %u.\n", up_params.port, up_params.pin, down_params.port, down_params.pin, left_params.port, left_params.pin, right_params.port, right_params.pin, select_params.port, select_params.pin); MB1_up.gpio_init(&up_params); MB1_down.gpio_init(&down_params); MB1_left.gpio_init(&left_params); MB1_right.gpio_init(&right_params); MB1_select.gpio_init(&select_params); testing_delay_us(100000); }
/*----------------------------------------------------------------------------*/ static void sim900_testing_init(void) { HA_NOTIFY("\nInitializing hardware for sim900 tests\n" "USART: %u, Baudrate: %lu\n" "RI pin: port: %u (port A = 0,...), pin: %u\n", uart_num, baudrate, RI_params.port, RI_params.pin); /* Initialize UART */ MB1_usart.Restart(baudrate); MB1_usart.it_enable(0,1); MB1_usart.it_config(USART_IT_RXNE, ENABLE); MB1_int.subISR_assign(MB1_int_type, usart3_irq); /* Init RI pin */ RI_pin.gpio_init(&RI_params); HA_NOTIFY("\nRI: %d (should be 1)\n", RI_pin.gpio_read()); /* Create ring buffer */ rb_init(&rx_buffer, 128); }
static void prepare_fpga_for_configuration(gpio &prog, gpio &)//init) { prog.set_value(true); prog.set_value(false); prog.set_value(true); #if 0 bool ready_to_program(false); unsigned int count(0); do { ready_to_program = init.get_value(); count++; sleep(1); } while (count < 10 && !ready_to_program); if (count == 10) { throw uhd::os_error("FPGA not ready for programming."); } #endif }
static void prepare_fpga_for_configuration(gpio &prog, gpio &init) { prog.set_value(true); prog.set_value(false); prog.set_value(true); #if 0 bool ready_to_program(false); unsigned int count(0); do { ready_to_program = init.get_value(); count++; sleep(1); } while (count < 10 && !ready_to_program); if (count == 10) { std::cout << "FPGA not ready for programming." << std::endl; exit(-1); } #endif }
/*----------------------------------------------------------------------------*/ static void sim900_testing_deinit(void) { HA_NOTIFY("\n*** Deinitializing hardware ***\n" "USART: %u, will be shut down\n" "All IO pins will be reset to IN_FLOATING\n", uart_num); /*Deinit USART and INT*/ MB1_int.subISR_remove(ISRMgr_ns::ISRMgr_USART3, usart3_irq); MB1_usart.it_disable(); MB1_usart.Shutdown(); /* Deinit RI pin */ RI_pin.gpio_shutdown(); rb_clear(&rx_buffer); }
/* LED7SEG function */ void led_data(uint8_t number, bool h) { switch (number){ /* Number 0 */ case 0: MB1_A.gpio_assign_value(!data_set_value); MB1_B.gpio_assign_value(!data_set_value); MB1_C.gpio_assign_value(!data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 1 */ case 1: MB1_A.gpio_assign_value(data_set_value); MB1_B.gpio_assign_value(!data_set_value); MB1_C.gpio_assign_value(!data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 2 */ case 2: MB1_A.gpio_assign_value(!data_set_value); MB1_B.gpio_assign_value(data_set_value); MB1_C.gpio_assign_value(!data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 3 */ case 3: MB1_A.gpio_assign_value(data_set_value); MB1_B.gpio_assign_value(data_set_value); MB1_C.gpio_assign_value(!data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 4 */ case 4: MB1_A.gpio_assign_value(!data_set_value); MB1_B.gpio_assign_value(!data_set_value); MB1_C.gpio_assign_value(data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 5 */ case 5: MB1_A.gpio_assign_value(data_set_value); MB1_B.gpio_assign_value(!data_set_value); MB1_C.gpio_assign_value(data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 6 */ case 6: MB1_A.gpio_assign_value(!data_set_value); MB1_B.gpio_assign_value(data_set_value); MB1_C.gpio_assign_value(data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 7 */ case 7: MB1_A.gpio_assign_value(data_set_value); MB1_B.gpio_assign_value(data_set_value); MB1_C.gpio_assign_value(data_set_value); MB1_D.gpio_assign_value(!data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 8 */ case 8: MB1_A.gpio_assign_value(!data_set_value); MB1_B.gpio_assign_value(!data_set_value); MB1_C.gpio_assign_value(!data_set_value); MB1_D.gpio_assign_value(data_set_value); MB1_h.gpio_assign_value(h); break; /* Number 9 */ case 9: MB1_A.gpio_assign_value(data_set_value); MB1_B.gpio_assign_value(!data_set_value); MB1_C.gpio_assign_value(!data_set_value); MB1_D.gpio_assign_value(data_set_value); MB1_h.gpio_assign_value(h); break; default: HA_NOTIFY("Data must be 0 ~ 9.\n"); MB1_A.gpio_assign_value(data_set_value); MB1_B.gpio_assign_value(data_set_value); MB1_C.gpio_assign_value(data_set_value); MB1_D.gpio_assign_value(data_set_value); MB1_h.gpio_assign_value(h); break; } }
/** \brief SPI data. Setup DC and SS pins, then send data via SPI to SSD1306 controller. */ void edOLED::data(unsigned char c) { DC_PIN.pinWrite(HIGH); // DC HIGH spiTransfer(c); }
static void sim900_gsm_test(void) { uint8_t state = 0, data, ri = 0; start_waiting_esc_character(); HA_NOTIFY("\nTEST #2: GSM TEST\n" "This test calls *101# to check money account\n" "(Press ESC to continue)\n"); while (esc_pressed == false); stop_waiting_esc_character(); /* Clear buffer brfore testing */ rb_clear(&rx_buffer); HA_NOTIFY("\nCalling *101# ... \n"); /* Call *101# */ MB1_usart.Print("ATD*101#;\r"); start_waiting_esc_character(); while(1) { /* Receiving message */ if (rb_get_data(&rx_buffer,&data,1) > 0) { switch (state) { /* Print content between two " " */ case 0: if (data == '"') { state = 1; HA_NOTIFY("\nReceived Message: \n"); /*check RI pin*/ if (RI_pin.gpio_read() == 0) ri = 1; } break; case 1: if (data == '"') { state = 2; HA_NOTIFY("\n"); } else { HA_NOTIFY("%c", (char)data); } break; /* End of message */ case 2: if (data == '\r') { state = 3; HA_NOTIFY("\nSuccessful !\n"); } break; } } if (esc_pressed == true) { break; } } stop_waiting_esc_character(); /* Fail to receive message */ if (state != 3) { HA_NOTIFY("\nFail\n"); } else { if (ri == 1) { HA_NOTIFY("\nRI pin works\n"); } else { HA_NOTIFY("\nRI pin does not work\n"); } } }
/** \brief SPI command. Setup DC and SS pins, then send command via SPI to SSD1306 controller. */ void edOLED::command(unsigned char c) { DC_PIN.pinWrite(LOW); // DC pin LOW spiTransfer(c); }
int PinTinDisplay::menu(void) { bool isConfirmed = false; bool buttonHasBeenReleased = false; int currentRow = 0; while(!isConfirmed) { usleep(2000); if (BUTTON_UP.pinRead() == HIGH && BUTTON_DOWN.pinRead() == HIGH && BUTTON_SELECT.pinRead() == HIGH) buttonHasBeenReleased = true; oled.setCursor(0, 0); oled.clear(PAGE); if (currentRow == 0) oled.print("> LIST"); else oled.print(" List"); if (currentRow == 1) oled.print("> FIND"); else oled.print(" Find"); oled.print("----------"); if (currentRow == 2) oled.print("> NEW"); else oled.print(" New"); if (currentRow == 3) oled.print("> EDIT"); else oled.print(" Edit"); if (currentRow == 4) oled.print("> DELETE"); else oled.print(" Delete"); oled.display(); if (BUTTON_UP.pinRead() == LOW && buttonHasBeenReleased){ currentRow--; if (currentRow < 0){ currentRow = 4; } buttonHasBeenReleased = false; } if (BUTTON_DOWN.pinRead() == LOW && buttonHasBeenReleased){ currentRow++; if (currentRow > 4){ currentRow = 0; } buttonHasBeenReleased = false; } if (BUTTON_SELECT.pinRead() == LOW && buttonHasBeenReleased){ buttonHasBeenReleased = false; oled.clear(PAGE); oled.display(); return currentRow; } } }
int PinTinDisplay::DisplayEntry(char* uri, char* username, char* password, char* note) { int currentPage = 1; int totalPages = 4; bool isReturning = false; bool buttonHasBeenReleased = false; do{ usleep(2000); this->oled.setCursor(0, 0); this->oled.clear(PAGE); switch(currentPage){ case 1: this->oled.print("Uri:"); this->oled.setCursor(0, 8); this->oled.print(uri); break; case 2: this->oled.print("Username:"******"Password"); this->oled.setCursor(0, 8); this->oled.print(password); break; case 4: this->oled.print("Note:"); this->oled.setCursor(0, 8); this->oled.print(note); break; } this->oled.display(); //Draw the selection if (BUTTON_LEFT.pinRead() == LOW && buttonHasBeenReleased){ isReturning = true; buttonHasBeenReleased = false; } if (BUTTON_A.pinRead() == LOW && buttonHasBeenReleased){ currentPage--; if (currentPage < 1) currentPage = totalPages; buttonHasBeenReleased = false; } if (BUTTON_B.pinRead() == LOW && buttonHasBeenReleased){ currentPage++; if (currentPage > totalPages) { currentPage = 1; } buttonHasBeenReleased = false; } if (BUTTON_UP.pinRead() == HIGH && BUTTON_DOWN.pinRead() == HIGH && BUTTON_RIGHT.pinRead() == HIGH && BUTTON_LEFT.pinRead() == HIGH && BUTTON_SELECT.pinRead() == HIGH && BUTTON_A.pinRead() == HIGH && BUTTON_B.pinRead() == HIGH) buttonHasBeenReleased = true; } while (!isReturning); return -1; }
int PinTinDisplay::DisplayEntries(char** entries, int count) { int selectedEntry = 0; int currentPage = 1; int totalPages = 1; int currentEntry = 0; int currentPageEntry = 0; int entriesPerPage = 5; bool entrySelected = false; bool buttonHasBeenReleased = false; totalPages = (count / entriesPerPage) + 1; do{ usleep(2000); this->oled.setCursor(0, 0); this->oled.clear(PAGE); int upperBound = (currentPage * entriesPerPage); if (upperBound >= count) upperBound = count; int n = 0; for(int i = ((currentPage * entriesPerPage) - entriesPerPage); i < upperBound; i++) { if(i == currentEntry) { this->oled.setCursor(0, n * 9 - n); this->oled.print(">"); this->oled.setCursor(6, n * 9 - n); this->oled.print(entries[i]); } else { this->oled.setCursor(0, n * 9 - n); this->oled.print(" "); this->oled.setCursor(6, n * 9 - n); this->oled.print(entries[i]); } n++; } this->oled.setCursor(0, 40); this->oled.print("Page: "); this->oled.print(currentPage); this->oled.print("/"); this->oled.print(totalPages); this->oled.display(); //Draw the selection if (BUTTON_LEFT.pinRead() == LOW && buttonHasBeenReleased){ return -1; buttonHasBeenReleased = false; } if (BUTTON_UP.pinRead() == LOW && buttonHasBeenReleased){ currentEntry--; currentPageEntry--; if (currentPageEntry < 0){ currentPageEntry = entriesPerPage - 1; currentEntry = upperBound - 1; } buttonHasBeenReleased = false; } if (BUTTON_DOWN.pinRead() == LOW && buttonHasBeenReleased){ currentEntry++; currentPageEntry++; if (currentPageEntry > entriesPerPage - 1){ currentPageEntry = 0; currentEntry = ((currentPage * entriesPerPage) - entriesPerPage); } buttonHasBeenReleased = false; } if (BUTTON_A.pinRead() == LOW && buttonHasBeenReleased){ currentPage--; currentPageEntry = 0; if (currentPage < 1) currentPage = totalPages; currentEntry = ((currentPage * entriesPerPage) - entriesPerPage); buttonHasBeenReleased = false; } if (BUTTON_B.pinRead() == LOW && buttonHasBeenReleased){ currentPage++; currentPageEntry = 0; if (currentPage > totalPages) currentPage = 1; currentEntry = ((currentPage * entriesPerPage) - entriesPerPage); buttonHasBeenReleased = false; } if ((BUTTON_SELECT.pinRead() == LOW && buttonHasBeenReleased) || (BUTTON_RIGHT.pinRead() == LOW && buttonHasBeenReleased)){ return currentEntry; buttonHasBeenReleased = false; } if (BUTTON_UP.pinRead() == HIGH && BUTTON_DOWN.pinRead() == HIGH && BUTTON_RIGHT.pinRead() == HIGH && BUTTON_LEFT.pinRead() == HIGH && BUTTON_SELECT.pinRead() == HIGH && BUTTON_A.pinRead() == HIGH && BUTTON_B.pinRead() == HIGH) buttonHasBeenReleased = true; } while (!entrySelected); return currentEntry * (currentPage + 1); }
void led_number(uint8_t lednumber) { switch (lednumber){ case all: MB1_L1.gpio_assign_value(l_enable_value); MB1_L2.gpio_assign_value(l_enable_value); MB1_L3.gpio_assign_value(l_enable_value); MB1_L4.gpio_assign_value(l_enable_value); break; case 1: MB1_L1.gpio_assign_value(l_enable_value); MB1_L2.gpio_assign_value(!l_enable_value); MB1_L3.gpio_assign_value(!l_enable_value); MB1_L4.gpio_assign_value(!l_enable_value); break; case 2: MB1_L1.gpio_assign_value(!l_enable_value); MB1_L2.gpio_assign_value(l_enable_value); MB1_L3.gpio_assign_value(!l_enable_value); MB1_L4.gpio_assign_value(!l_enable_value); break; case 3: MB1_L1.gpio_assign_value(!l_enable_value); MB1_L2.gpio_assign_value(!l_enable_value); MB1_L3.gpio_assign_value(l_enable_value); MB1_L4.gpio_assign_value(!l_enable_value); break; case 4: MB1_L1.gpio_assign_value(!l_enable_value); MB1_L2.gpio_assign_value(!l_enable_value); MB1_L3.gpio_assign_value(!l_enable_value); MB1_L4.gpio_assign_value(l_enable_value); break; default: HA_NOTIFY("You can choose led_number 1 ~ 4.\n"); MB1_L1.gpio_assign_value(!l_enable_value); MB1_L2.gpio_assign_value(!l_enable_value); MB1_L3.gpio_assign_value(!l_enable_value); MB1_L4.gpio_assign_value(!l_enable_value); break; }//End switch case }
char* PinTinDisplay::CallGetUserTextInput(char* title) { string test = ""; const int verticalOffset = 24; int currentRow = 0; int currentCol = 0; bool isConfirmed = false; bool buttonHasBeenReleased = false; int currentCharSet = 0; const char smallAlphabet[3][10] = {{'a','b','c','d','e','f','g','h','i','j'}, {'k','l','m','n','o','p','q','r','s','t'}, {'u','v','w','x','y','z',' ',' ','<','y'}}; const char largeAlphabet[3][10] = {{'A','B','C','D','E','F','G','H','I','J'}, {'K','L','M','N','O','P','Q','R','S','T'}, {'U','V','W','X','Y','Z',' ',' ','<','y'}}; const char specialNumeric[3][10] = {{'1','2','3','4','5','6','7','8','9','0'}, {'+','-','/','*','{','}','(',')','%','$'}, {':','!','?','.',',','_','#',' ','<','y'}}; while(!isConfirmed) { this->oled.setCursor(0, 0); this->oled.clear(PAGE); oled.print(title); this->oled.setCursor(0, 8); oled.print(test.c_str()); this->oled.setCursor(0, verticalOffset); for(int row = 0; row < 3; row++) for(int col = 0; col < 10; col++) if ((currentRow == row) && (currentCol == col)) { this->oled.rectFill((currentCol * 6), (verticalOffset + currentRow * 8), 5, 8); this->oled.setCursor((currentCol * 6), (verticalOffset + currentRow * 8)); this->oled.setDrawMode(XOR); if (currentCharSet == 0) this->oled.write(smallAlphabet[row][col]); if (currentCharSet == 1) this->oled.write(largeAlphabet[row][col]); if (currentCharSet == 2) this->oled.write(specialNumeric[row][col]); this->oled.setDrawMode(NORM); } else { if (currentCharSet == 0) this->oled.write(smallAlphabet[row][col]); if (currentCharSet == 1) this->oled.write(largeAlphabet[row][col]); if (currentCharSet == 2) this->oled.write(specialNumeric[row][col]); } this->oled.display(); //Draw the selection if (BUTTON_RIGHT.pinRead() == LOW && buttonHasBeenReleased){ currentCol++; if (currentCol > 9){ currentRow++; currentCol = 0; } buttonHasBeenReleased = false; } if (BUTTON_LEFT.pinRead() == LOW && buttonHasBeenReleased){ currentCol--; if (currentCol < 0){ currentRow--; currentCol = 9; } buttonHasBeenReleased = false; } if (BUTTON_UP.pinRead() == LOW && buttonHasBeenReleased){ currentRow--; if (currentRow < 0){ currentRow = 2; } buttonHasBeenReleased = false; } if (BUTTON_DOWN.pinRead() == LOW && buttonHasBeenReleased){ currentRow++; if (currentRow > 2){ currentRow = 0; } buttonHasBeenReleased = false; } if (BUTTON_A.pinRead() == LOW && buttonHasBeenReleased){ currentCharSet--; if (currentCharSet < 0) currentCharSet = 2; buttonHasBeenReleased = false; } if (BUTTON_B.pinRead() == LOW && buttonHasBeenReleased){ currentCharSet++; if (currentCharSet > 2) currentCharSet = 0; buttonHasBeenReleased = false; } if (BUTTON_SELECT.pinRead() == LOW && buttonHasBeenReleased){ //test = test + smallAlphabet[currentRow][currentCol]; if (currentRow == 2 && currentCol == 9){ //return vector<char> chars(test.c_str(), test.c_str() + test.size() + 1u);; char *s = (char*)malloc(strlen(test.c_str())+1); // if you write char s[strlen(q)], it is defined locally, and thus on return gives an undefined behaviour int i; for(i = 0; i < strlen(test.c_str())+1; i++) s[i] = test[i]; //return s; //char *s = strdup(test); oled.clear(PAGE); oled.display(); return s; } if (currentCharSet == 0) test.push_back(smallAlphabet[currentRow][currentCol]); if (currentCharSet == 1) test.push_back(largeAlphabet[currentRow][currentCol]); if (currentCharSet == 2) test.push_back(specialNumeric[currentRow][currentCol]); buttonHasBeenReleased = false; } if (BUTTON_UP.pinRead() == HIGH && BUTTON_DOWN.pinRead() == HIGH && BUTTON_RIGHT.pinRead() == HIGH && BUTTON_LEFT.pinRead() == HIGH && BUTTON_SELECT.pinRead() == HIGH && BUTTON_A.pinRead() == HIGH && BUTTON_B.pinRead() == HIGH) buttonHasBeenReleased = true; } }