Jack Purdum
Mark: Where is the display_fields[field].width object defined? I don't seem to have the source code. Jack, W8TEE From: Mark Pilant <mark@...> To: [email protected] Sent: Tuesday, October 3, 2017 3:03 PM Subject: Re: [BITX20] A bit OT, blame it on W8TEE Another way to minimize LCD activity is to only display the text "delta". The following function is one I created to display text on an LCD.? The display being "broken" into a number of "fields" (row, column, and width) and when the function is called to display the text, it will only display the positions having changed. This function will also clear out anything in the row after the field. I have found this very handy. One other note, the changes to the display are done under mutex control because the program using this function is multi-threaded. I hope this helps, and doesn't confuse things too much.? Although I will be happy to answer any questions. - Mark --------------------------------------------------------------------------------- /* Define the display information. */ #define ROW_MAXIMUM? ? ? ? 4 #define COLUMN_MAXIMUM? ? ? 20 #define FULL_ROW_WIDTH? ? ? COLUMN_MAXIMUM #define HALF_ROW_WIDTH? ? ? (COLUMN_MAXIMUM - (COLUMN_MAXIMUM / 2)) /* Display fields. */ #define? ? DISP_DATE_TIME? 0 #define? ? DISP_WEEKDAY? ? 1 #define? ? DISP_SCHEDULE? ? 2 #define? ? DISP_PROG_NAME? 3 #define? ? DISP_ZONE_INFO? 4 /* Must be last. */ #define? ? DISP_MAX? ? ? ? 5 char? ? ? ? ? ? old_display_data[ROW_MAXIMUM][COLUMN_MAXIMUM]; void display_text(uint8_t field, const char *text) { ? ? uint8_t? ? ? ? cur_column; ? ? uint8_t? ? ? ? row; ? ? uint8_t? ? ? ? start_column; ? ? uint8_t? ? ? ? text_len = strlen(text); ? ? /* Make sure the field number is valid. */ ? ? if (field >= DISP_MAX) return; ? ? row = display_fields[field].row; ? ? start_column = display_fields[field].column; ? ? /* Only display the changed text. */ ? ? for (cur_column = 0; cur_column < display_fields[field].width; cur_column++) { ? ? ? ? /* If the end of the string, we are done. */ ? ? ? ? if (text[cur_column] == '\0') break; ? ? ? ? /* If the the character is different, write it and save for next time. */ ? ? ? ? if (old_display_data[row][start_column + cur_column] != text[cur_column]) { ? ? ? ? ? ? /* Lock the display mutex so the display may be updated. */ ? ? ? ? ? ? pthread_mutex_lock(&display_mutex); ? ? ? ? ? ? lcd_setCursor(row, start_column + cur_column); ? ? ? ? ? ? lcd_printc(text[cur_column]); ? ? ? ? ? ? /* We're done so unlock the display mutex. */ ? ? ? ? ? ? pthread_mutex_unlock(&display_mutex); ? ? ? ? ? ? old_display_data[row][start_column + cur_column] = text[cur_column]; ? ? ? ? } ? ? } ? ? /* If there is anything left in the row, clear it out. */ ? ? while (cur_column < display_fields[field].width) { ? ? ? ? /* Lock the display mutex so the display may be updated. */ ? ? ? ? pthread_mutex_lock(&display_mutex); ? ? ? ? lcd_setCursor(row, start_column + cur_column); ? ? ? ? lcd_printc(' '); ? ? ? ? /* We're done so unlock the display mutex. */ ? ? ? ? pthread_mutex_unlock(&display_mutex); ? ? ? ? old_display_data[row][start_column + cur_column] = ' '; ? ? ? ? cur_column++; ? ? } } |