diff --git a/build-number.txt b/build-number.txt index 11a42ac..02a6b26 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -615 +641 diff --git a/src/bmp.c b/src/bmp.c index 0603975..5524ae0 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -64,7 +64,7 @@ void BMP_ConstructFilename(int number, char *buffer, unsigned int size) memcpy(buffer + size - 5, ".BMP", 5); } -void BMP_Save(uint8_t *data, int width, int height) +int BMP_Save(uint8_t *data, int width, int height) { FATFS fs; FIL fp; @@ -74,19 +74,19 @@ void BMP_Save(uint8_t *data, int width, int height) rc = f_mount(&fs, "", 0); if(rc) { - return; + return -1; } int file_number = BMP_PickFileNumber(); if(file_number == -1) - return; + return -2; char filename[13]; BMP_ConstructFilename(file_number, filename, sizeof(filename)); rc = f_open(&fp, filename, FA_WRITE | FA_CREATE_NEW); if(rc) { - return; + return -3; } // Rows must be padded to a multiple of 4 bytes @@ -121,24 +121,26 @@ void BMP_Save(uint8_t *data, int width, int height) }; if(f_write(&fp, &file_header, sizeof(file_header), &bw) != FR_OK) - return; + return -4; if(f_write(&fp, &core_header, sizeof(core_header), &bw) != FR_OK) - return; + return -4; if(f_write(&fp, &colour_table, sizeof(colour_table), &bw) != FR_OK) - return; + return -4; // BMPs are stored with their rows from the bottom upwards for(int y = height - 1; y >= 0; y--) { uint8_t *row = data + y * (width / 8); if(f_write(&fp, row, width / 8, &bw) != FR_OK) - return; + return -4; if(padding_length != 0) { if(f_write(&fp, padding_bytes, padding_length, &bw) != FR_OK) - return; + return -4; } } f_close(&fp); + + return file_number; } diff --git a/src/bmp.h b/src/bmp.h index 117d3aa..758db22 100644 --- a/src/bmp.h +++ b/src/bmp.h @@ -4,4 +4,4 @@ #include #include -void BMP_Save(uint8_t *data, int width, int height); +int BMP_Save(uint8_t *data, int width, int height); diff --git a/src/config.h b/src/config.h index 7a9b0db..2e255fb 100644 --- a/src/config.h +++ b/src/config.h @@ -18,4 +18,7 @@ #define CONFIG_MAX_FRAMES 15 // Print number of black pixels per captured frame -// #define CONFIG_PRINT_EXPOSURE_DEBUG_INFORMATION \ No newline at end of file +// #define CONFIG_PRINT_EXPOSURE_DEBUG_INFORMATION + +// Print file number if a file was saved to SD card +#define CONFIG_PRINT_FILE_NUMBER \ No newline at end of file diff --git a/src/main.c b/src/main.c index 108a766..cdffd8f 100644 --- a/src/main.c +++ b/src/main.c @@ -14,8 +14,7 @@ int main(void) Camera_Init(); LTP1245_Init(); - LTP1245_FeedPaper(100); - LTP1245_FeedPaper(10); + LTP1245_FeedPaper(50); while(!Camera_Captured); @@ -26,8 +25,9 @@ int main(void) char buffer[32] = "Finished after lines: "; itoa(Camera_FinalFrameCount, buffer + strlen(buffer), 10); - Print_Text(buffer, &Arpegius_32); - Print_Text("Black pixel counts:", &Arpegius_32); + Print_Text(buffer, &Hannover_Messe_Serif_26, Print_LeftAligned); + Print_Text("Black pixel counts:", &Hannover_Messe_Serif_26, + Print_LeftAligned); for(int i = 0; i < Camera_FinalFrameCount; i++) { if(i >= (int)(sizeof(Camera_BlackPixelCounts) @@ -36,14 +36,26 @@ int main(void) break; } itoa(Camera_BlackPixelCounts[i], buffer, 10); - Print_Text(buffer, &Arpegius_32); + Print_Text(buffer, &Hannover_Messe_Serif_26, Print_LeftAligned); } #endif - LTP1245_FeedPaper(100); + int file_number = BMP_Save(ImageBuffer, CAMERA_IMAGE_WIDTH, + CAMERA_IMAGE_HEIGHT); + (void)file_number; - BMP_Save(ImageBuffer, CAMERA_IMAGE_WIDTH, CAMERA_IMAGE_HEIGHT); +#ifdef CONFIG_PRINT_FILE_NUMBER + LTP1245_FeedPaper(10); + char buffer[32] = "- "; + if(file_number >= 0) + { + itoa(file_number, buffer + strlen(buffer), 10); + strcpy(buffer + strlen(buffer), " -"); + Print_Text(buffer, &Hannover_Messe_Serif_26, Print_Centred); + } +#endif + LTP1245_FeedPaper(80); LTP1245_FeedPaper(10); GPIOC->BRR = (1 << PIN_SUPPLY); diff --git a/src/print.c b/src/print.c index 82ad27a..9147d05 100644 --- a/src/print.c +++ b/src/print.c @@ -3,12 +3,45 @@ static uint8_t Print_Buffer[PRINT_BUFFER_LINES * LTP1245_LINE_BYTES]; -void Print_Text(const char *text, const Font_t *font) +int Print_MeasureTextWidth(const char *text, const Font_t *font) +{ + char c; + int width = 0; + while((c = *text++) != 0) + { + if(c > font->glyphcount + font->charoffset + || c < font->charoffset) + { + continue; + } + + width += font->glyphs[c - font->charoffset].width; + } + return width; +} + +void Print_Text(const char *text, const Font_t *font, + Print_TextAlignment_t alignment) { int height = font->height; memset(Print_Buffer, 0, LTP1245_LINE_BYTES * height); char c; int xpos = 0; + if(alignment != Print_LeftAligned) + { + int width = Print_MeasureTextWidth(text, font); + if(width < LTP1245_LINEWIDTH) + { + if(alignment == Print_Centred) + { + xpos = LTP1245_LINEWIDTH / 2 - width / 2; + } + else + { + xpos = LTP1245_LINEWIDTH - width; + } + } + } while((c = *text++) != 0) { if(c > font->glyphcount + font->charoffset diff --git a/src/print.h b/src/print.h index 168594d..d21b5f1 100644 --- a/src/print.h +++ b/src/print.h @@ -7,5 +7,13 @@ #define PRINT_BUFFER_LINES 64 -void Print_Text(const char *text, const Font_t *font); +typedef enum +{ + Print_LeftAligned, + Print_Centred, + Print_RightAligned, +} Print_TextAlignment_t; + +void Print_Text(const char *text, const Font_t *font, + Print_TextAlignment_t alignment); void Print_Image(const uint8_t *data, int width, int height, int scale); \ No newline at end of file