/** * Although this is undocumented, the ST7920 allows the character * data buffer (DDRAM) to be used in conjunction with the graphics * bitmap buffer (CGRAM). The contents of the graphics buffer is * XORed with the data from the character generator. This allows * us to make the progess bar out of graphical data (the bar) and * text data (the percentage). */ void ST7920_Lite_Status_Screen::draw_progress_bar(const uint8_t value) { #if HOTENDS == 1 // If we have only one extruder, draw a long progress bar on the third line constexpr uint8_t top = 1, // Top in pixels bottom = 13, // Bottom in pixels left = 12, // Left edge, in 16-bit words width = 4; // Width of progress bar, in 16-bit words #else constexpr uint8_t top = 16 + 1, bottom = 16 + 13, left = 5, width = 3; #endif const uint8_t char_pcnt = 100 / width; // How many percent does each 16-bit word represent? // Draw the progress bar as a bitmap in CGRAM for (uint8_t y = top; y <= bottom; y++) { set_gdram_address(left, y); begin_data(); for (uint8_t x = 0; x < width; x++) { uint16_t gfx_word = 0x0000; if ((x + 1) * char_pcnt <= value) gfx_word = 0xFFFF; // Draw completely filled bytes else if ((x * char_pcnt) < value) gfx_word = int(0x8000) >> (value % char_pcnt) * 16 / char_pcnt; // Draw partially filled bytes // Draw the frame around the progress bar if (y == top || y == bottom) gfx_word = 0xFFFF; // Draw top/bottom border else if (x == width - 1) gfx_word |= 0x0001; // Draw right border else if (x == 0) gfx_word |= 0x8000; // Draw left border write_word(gfx_word); } } // Draw the percentage as text in DDRAM #if HOTENDS == 1 set_ddram_address(DDRAM_LINE_3 + 4); begin_data(); write_byte(' '); #else set_ddram_address(DDRAM_LINE_2 + left); begin_data(); #endif // Draw centered if (value > 9) { write_number(value, 4); write_str_P(PSTR("% ")); } else { write_number(value, 3); write_str_P(PSTR("% ")); } }
int main(int argc, char * argv[]){ FILE * output = stdout; const char * bigram_filename = "bigram.db"; FacadePhraseIndex phrase_index; //gb_char binary file MemoryChunk * chunk = new MemoryChunk; chunk->load("gb_char.bin"); phrase_index.load(1, chunk); //gbk_char binary file chunk = new MemoryChunk; chunk->load("gbk_char.bin"); phrase_index.load(2, chunk); Bigram bigram; bigram.attach(bigram_filename, ATTACH_READONLY); begin_data(output); gen_unigram(output, &phrase_index); gen_bigram(output, &phrase_index, &bigram); end_data(output); return 0; }
void ST7920_Lite_Status_Screen::load_cgram_icon(const uint16_t addr, const void *data) { const uint16_t *p_word = (const uint16_t *)data; set_cgram_address(addr); begin_data(); for (uint8_t i = 16; i--;) write_word(pgm_read_word(p_word++)); }
/* This fills the entire graphics buffer with zeros */ void ST7920_Lite_Status_Screen::clear_gdram() { for (uint8_t y = 0; y < BUFFER_HEIGHT; y++) { set_gdram_address(0, y); begin_data(); for (uint8_t i = (BUFFER_WIDTH) / 16; i--;) write_word(0); } }
int main(int argc, char * argv[]){ FILE * output = stdout; const char * bigram_filename = SYSTEM_BIGRAM; SystemTableInfo system_table_info; bool retval = system_table_info.load(SYSTEM_TABLE_INFO); if (!retval) { fprintf(stderr, "load table.conf failed.\n"); exit(ENOENT); } FacadePhraseIndex phrase_index; const pinyin_table_info_t * phrase_files = system_table_info.get_table_info(); if (!load_phrase_index(phrase_files, &phrase_index)) exit(ENOENT); Bigram bigram; bigram.attach(bigram_filename, ATTACH_READONLY); begin_data(output); gen_unigram(output, &phrase_index); gen_bigram(output, &phrase_index, &bigram); end_data(output); return 0; }
void ST7920_Lite_Status_Screen::draw_status_message() { const char *str = ui.status_message; set_ddram_address(DDRAM_LINE_4); begin_data(); #if ENABLED(STATUS_MESSAGE_SCROLLING) uint8_t slen = utf8_strlen(str); if (slen <= LCD_WIDTH) { // String fits the LCD, so just print it write_str(str); for (; slen < LCD_WIDTH; ++slen) write_byte(' '); } else { // String is larger than the available space in screen. // Get a pointer to the next valid UTF8 character const char *stat = str + ui.status_scroll_offset; // Get the string remaining length const uint8_t rlen = utf8_strlen(stat); // If we have enough characters to display if (rlen >= LCD_WIDTH) { // The remaining string fills the screen - Print it write_str(stat, LCD_WIDTH); } else { // The remaining string does not completely fill the screen write_str(stat); // The string leaves space uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters write_byte('.'); // Always at 1+ spaces left, draw a dot if (--chars) { // Draw a second dot if there's space write_byte('.'); if (--chars) write_str(str, chars); // Print a second copy of the message } } // Adjust by complete UTF8 characters if (ui.status_scroll_offset < slen) { ui.status_scroll_offset++; while (!START_OF_UTF8_CHAR(str[ui.status_scroll_offset])) ui.status_scroll_offset++; } else ui.status_scroll_offset = 0; } #else uint8_t slen = utf8_strlen(str); write_str(str, LCD_WIDTH); for (; slen < LCD_WIDTH; ++slen) write_byte(' '); #endif }
/** * Draw an icon in GDRAM. Position specified in DDRAM * coordinates. i.e., X from 1 to 8, Y from 1 to 4. */ void ST7920_Lite_Status_Screen::draw_gdram_icon(uint8_t x, uint8_t y, const void *data) { const uint16_t *p_word = (const uint16_t *)data; // Handle display folding if (y > 1) y -= 2, x += 8; for (int i = 0; i < 16; i++) { set_gdram_address(x, i + y * 16); begin_data(); write_word(pgm_read_word(p_word++)); } }
void ST7920_Lite_Status_Screen::draw_feedrate_percentage(const uint16_t percentage) { // We only have enough room for the feedrate when // we have one extruder #if HOTENDS == 1 set_ddram_address(DDRAM_LINE_2 + 6); begin_data(); write_number(percentage, 3); write_byte('%'); #endif }
void ST7920_Lite_Status_Screen::draw_print_time(const duration_t &elapsed) { #if HOTENDS == 1 set_ddram_address(DDRAM_LINE_3); #else set_ddram_address(DDRAM_LINE_3 + 5); #endif char str[7]; str[elapsed.toDigital(str)] = ' '; begin_data(); write_str(str, 6); }
void ST7920_Lite_Status_Screen::draw_heat_icon(const bool whichIcon, const bool heating) { set_ddram_address( #if HOTENDS == 1 DDRAM_LINE_2 #else DDRAM_LINE_3 #endif ); begin_data(); if (heating) write_word(whichIcon ? CGRAM_ICON_1_WORD : CGRAM_ICON_2_WORD); else { write_byte(' '); write_byte(' '); } }
/** * The ST7920 has no degree character, so draw it to GDRAM. * This function takes character position xy * i.e., x is [0-15], while the y position is [0-3] */ void ST7920_Lite_Status_Screen::draw_degree_symbol(uint8_t x, uint8_t y, const bool draw) { const uint8_t *p_bytes = degree_symbol; // Handle display folding if (y > 1) y -= 2, x += 16; const bool oddChar = x & 1; const uint8_t x_word = x >> 1, y_top = degree_symbol_y_top, y_bot = y_top + COUNT(degree_symbol); for (uint8_t i = y_top; i < y_bot; i++) { uint8_t byte = pgm_read_byte(p_bytes++); set_gdram_address(x_word, i + y * 16); begin_data(); if (draw) { write_byte(oddChar ? 0x00 : byte); write_byte(oddChar ? byte : 0x00); } else write_word(0x0000); } }
void ST7920_Lite_Status_Screen::draw_position(const float x, const float y, const float z, bool position_known) { char str[7]; set_ddram_address(DDRAM_LINE_4); begin_data(); // If position is unknown, flash the labels. const unsigned char alt_label = position_known ? 0 : (ui.get_blink() ? ' ' : 0); dtostrf(x, -4, 0, str); write_byte(alt_label ? alt_label : 'X'); write_str(str, 4); dtostrf(y, -4, 0, str); write_byte(alt_label ? alt_label : 'Y'); write_str(str, 4); dtostrf(z, -5, 1, str); write_byte(alt_label ? alt_label : 'Z'); write_str(str, 5); }
int main(int argc, char * argv[]){ FILE * output = stdout; const char * bigram_filename = "bigram.db"; MemoryChunk * chunk = NULL; FacadePhraseIndex phrase_index; if (!load_phrase_index(&phrase_index)) exit(ENOENT); Bigram bigram; bigram.attach(bigram_filename, ATTACH_READONLY); begin_data(output); gen_unigram(output, &phrase_index); gen_bigram(output, &phrase_index, &bigram); end_data(output); return 0; }
void ST7920_Lite_Status_Screen::draw_temps(uint8_t line, const int16_t temp, const int16_t target, bool showTarget, bool targetStateChange) { switch (line) { case 0: set_ddram_address(DDRAM_LINE_1 + 1); break; case 1: set_ddram_address(DDRAM_LINE_2 + 1); break; case 2: set_ddram_address(DDRAM_LINE_3 + 1); break; case 3: set_ddram_address(DDRAM_LINE_3 + 1); break; } begin_data(); write_number(temp); if (showTarget) { write_byte('\x1A'); write_number(target); }; if (targetStateChange) { if (!showTarget) write_str_P(PSTR(" ")); draw_degree_symbol(5, line, !showTarget); draw_degree_symbol(9, line, showTarget); } }
bool CSeqDBTaxInfo::GetTaxNames(Int4 tax_id, SSeqDBTaxInfo & info ) { static CTaxDBFileInfo t; if (t.IsMissingTaxInfo()) return false; Int4 low_index = 0; Int4 high_index = t.GetTaxidCount() - 1; const char * Data = t.GetDataPtr(); const CSeqDBTaxId* Index = t.GetIndexPtr(); Int4 low_taxid = Index[low_index ].GetTaxId(); Int4 high_taxid = Index[high_index].GetTaxId(); if((tax_id < low_taxid) || (tax_id > high_taxid)) return false; Int4 new_index = (low_index+high_index)/2; Int4 old_index = new_index; while(1) { Int4 curr_taxid = Index[new_index].GetTaxId(); if (tax_id < curr_taxid) { high_index = new_index; } else if (tax_id > curr_taxid){ low_index = new_index; } else { /* Got it ! */ break; } new_index = (low_index+high_index)/2; if (new_index == old_index) { if (tax_id > curr_taxid) { new_index++; } break; } old_index = new_index; } if (tax_id == Index[new_index].GetTaxId()) { info.taxid = tax_id; Uint4 begin_data(Index[new_index].GetOffset()); Uint4 end_data(0); if (new_index == high_index) { // Last index is special... end_data = Uint4(t.GetDataFileSize()); if (end_data < begin_data) { // Should not happen. ERR_POST( "Error: Offset error at end of taxdb file."); return false; } } else { end_data = (Index[new_index+1].GetOffset()); } const char * start_ptr = &Data[begin_data]; CSeqDB_Substring buffer(start_ptr, start_ptr + (end_data - begin_data)); CSeqDB_Substring sci, com, blast, king; bool rc1, rc2, rc3; rc1 = SeqDB_SplitString(buffer, sci, '\t'); rc2 = SeqDB_SplitString(buffer, com, '\t'); rc3 = SeqDB_SplitString(buffer, blast, '\t'); king = buffer; if (rc1 && rc2 && rc3 && buffer.Size()) { sci .GetString(info.scientific_name); com .GetString(info.common_name); blast .GetString(info.blast_name); king .GetString(info.s_kingdom); return true; } } return false; }
/* This fills the entire text buffer with spaces */ void ST7920_Lite_Status_Screen::clear_ddram() { set_ddram_address(DDRAM_LINE_1); begin_data(); for (uint8_t i = 64; i--;) write_byte(' '); }
void ST7920_Lite_Status_Screen::draw_fan_icon(const bool whichIcon) { set_ddram_address(DDRAM_LINE_1 + 5); begin_data(); write_word(whichIcon ? CGRAM_ICON_3_WORD : CGRAM_ICON_4_WORD); }
void ST7920_Lite_Status_Screen::draw_fan_speed(const uint8_t value) { set_ddram_address(DDRAM_LINE_1 + 6); begin_data(); write_number(value, 3); write_byte('%'); }