diff --git a/avrtft.c b/avrtft.c index 18b92ac..c1e49d5 100644 --- a/avrtft.c +++ b/avrtft.c @@ -123,9 +123,7 @@ touch = false; // do something at the start - if (sdcard) { - readBMPFromSD(0); - } else { + if (!sdcard) { initPaint(); } // hackDemo(); @@ -136,7 +134,11 @@ Point point = {0}; // memset(&point, 0, sizeof (Point)); uint8_t event = readTouch(&point); - paintEvent(event, &point); + if (sdcard) { + bmpEvent(event, &point); + } else { + paintEvent(event, &point); + } } if (isStreamingData()) { diff --git a/bmp.c b/bmp.c index 01d417a..02725db 100644 --- a/bmp.c +++ b/bmp.c @@ -8,10 +8,6 @@ */ #include "bmp.h" -#include "display.h" -#include "tft.h" -#include "usart.h" -#include "hack.h" #define BUF_SIZE 4 @@ -31,6 +27,9 @@ static uint32_t imageSize = 0; // static uint16_t rowSize = 0; +static uint32_t address = 0; +static uint16_t blocks = 0; + /** * Resets the state. */ @@ -62,6 +61,18 @@ buf[BUF_SIZE - 1] = byte; } +// TODO consider HFLIP + VFLIP +void bmpEvent(uint8_t event, Point *point) { + if (event == EVENT_PRESS_DOWN) { + // if (point->x < DISPLAY_WIDTH / 2) { + // go to previous image + // } else { + address += blocks; + // } + blocks = readBMPFromSD(address); + } +} + void prepareBMP(row_t srow, col_t scol) { reset(); row = srow; @@ -126,10 +137,12 @@ if (offset == 0x12 + 3) { memcpy(&bitmapWidth, &buf, sizeof (bitmapWidth)); + // TODO error if > DISPLAY_WIDTH } if (offset == 0x16 + 3) { memcpy(&bitmapHeight, &buf, sizeof (bitmapHeight)); + // TODO error if > DISPLAY_HEIGHT } if (offset == 0x1c + 1) { @@ -173,10 +186,11 @@ return BMP_BUSY; } -void readBMPFromSD(uint32_t address) { +uint16_t readBMPFromSD(uint32_t address) { reset(); uint8_t block[SD_BLOCK_SIZE]; uint8_t status; + uint32_t start = address; do { displayDes(); bool success = readSingleBlock(address++, block); @@ -192,4 +206,6 @@ break; } } while (status == BMP_BUSY); + + return address - start; } diff --git a/bmp.h b/bmp.h index b5ee515..38d985a 100644 --- a/bmp.h +++ b/bmp.h @@ -13,12 +13,25 @@ #include #include "types.h" #include "sdcard.h" +#include "display.h" +#include "tft.h" +#include "usart.h" +#include "hack.h" +#include "touch.h" #define BMP_READY 0 #define BMP_BUSY 1 #define BMP_ERROR 2 /** + * Handles the given touch event and point. + * + * @param event + * @param point + */ +void bmpEvent(uint8_t event, Point *point); + +/** * Prepares to "stream" a BMP image via USART to the display, * with its upper left corner at the given coordinates. * @@ -42,8 +55,9 @@ * Reads a BMP image raw from the SD card starting at the given address. * * @param address start address + * @return length of image in blocks */ -void readBMPFromSD(uint32_t address); +uint16_t readBMPFromSD(uint32_t address); #endif /* BMP_H */ diff --git a/emojis.c b/emojis.c index c17b1c8..b9d62bc 100644 --- a/emojis.c +++ b/emojis.c @@ -825,12 +825,12 @@ // smile if emoji is a stranger {0x3f, 16, SMILE}, {'A', 16, CAT_ANGRY}, - {'B', 16, BEERS}, - {'C', 16, CAR}, + // {'B', 16, BEERS}, + // {'C', 16, CAR}, {'D', 16, THUMB_DOWN}, {'F', 16, FLOWER}, {'H', 16, HEART}, - {'O', 16, SNOWMAN}, + // {'O', 16, SNOWMAN}, {'P', 16, PIZZA}, {'R', 16, HERBS}, {'S', 16, CAT_SMILE}, @@ -838,13 +838,12 @@ {'U', 16, THUMB_UP}, {'a', 16, SAD}, {'b', 16, BLUSH}, - // {'e', 16, SMILE_TEAR}, sacrificed for flash memory + // {'e', 16, SMILE_TEAR}, {'g', 16, GRIN}, {'h', 16, HUG}, {'m', 16, MELT}, - // {'n', 16, GRIN_TEAR}, sacrificed for flash memory + // {'n', 16, GRIN_TEAR}, {'o', 16, MOON}, - {'r', 16, HERBS}, {'s', 16, SMILE}, {'t', 16, TONGUE}, {'u', 16, SUN} diff --git a/emojis/emojis.sh b/emojis/emojis.sh index 94c841f..736eccf 100755 --- a/emojis/emojis.sh +++ b/emojis/emojis.sh @@ -13,17 +13,17 @@ echo -e 't 16 16 \tb' > /dev/ttyUSB0 sleep 0.1 echo -e 't 16 32 \tg' > /dev/ttyUSB0 -sleep 0.1 -# echo -e 't 16 48 \tn' > /dev/ttyUSB0 # sleep 0.1 +# echo -e 't 16 48 \tn' > /dev/ttyUSB0 +sleep 0.1 echo -e 't 16 48 \tm' > /dev/ttyUSB0 sleep 0.1 echo -e 't 16 64 \th' > /dev/ttyUSB0 sleep 0.1 echo -e 't 16 80 \tt' > /dev/ttyUSB0 -sleep 0.1 -# echo -e 't 16 112 \te' > /dev/ttyUSB0 # sleep 0.1 +# echo -e 't 16 112 \te' > /dev/ttyUSB0 +sleep 0.1 echo -e 't 16 96 \ta' > /dev/ttyUSB0 sleep 0.1 echo -e 't 32 0 \tU' > /dev/ttyUSB0 @@ -37,8 +37,8 @@ echo -e 't 32 64 \tu' > /dev/ttyUSB0 sleep 0.1 echo -e 't 32 80 \to' > /dev/ttyUSB0 -sleep 0.1 -echo -e 't 32 96 \tO' > /dev/ttyUSB0 +# sleep 0.1 +# echo -e 't 32 96 \tO' > /dev/ttyUSB0 sleep 0.1 echo -e 't 48 0 \tH' > /dev/ttyUSB0 sleep 0.1 @@ -51,5 +51,5 @@ echo -e 't 48 64 \tF' > /dev/ttyUSB0 sleep 0.1 echo -e 't 48 80 \tR' > /dev/ttyUSB0 -sleep 0.1 -echo -e 't 48 96 \tC' > /dev/ttyUSB0 +# sleep 0.1 +# echo -e 't 48 96 \tC' > /dev/ttyUSB0 diff --git a/scripts/bmp.sh b/scripts/bmp.sh new file mode 100755 index 0000000..3bb86d8 --- /dev/null +++ b/scripts/bmp.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -eu +set -o pipefail + +WIDTH=320 +HEIGHT=240 +BLOCKSIZE=512 +DEVICE=/dev/mmcblk0 +IMAGE="sdcard.img" + +cat /dev/null > $IMAGE + +for i in *.jpg; do + bmp="${i%.*}.bmp" + convert $i -scale ${WIDTH}x${HEIGHT} -define bmp:subtype=RGB565 "$bmp" + size=$(stat --printf="%s" "$bmp") + blocks=$((($size+$BLOCKSIZE-1)/$BLOCKSIZE)) + bsize=$((blocks*$BLOCKSIZE)) + truncate -s $bsize "$bmp" + cat "$bmp" >> "$IMAGE" + echo "$bmp" $bsize +done + +sudo dd if="$IMAGE" of=$DEVICE bs=$BLOCKSIZE status=progress diff --git a/sdcard.c b/sdcard.c index 5198603..9d3670e 100644 --- a/sdcard.c +++ b/sdcard.c @@ -214,7 +214,7 @@ return success; } -bool readMultiBlock(uint32_t address, consumer consume) { +bool readMultiBlock(uint32_t address, Consumer consume) { select(); command(CMD18, address, CMD18_CRC); diff --git a/sdcard.h b/sdcard.h index dfb74fb..93899b2 100644 --- a/sdcard.h +++ b/sdcard.h @@ -83,7 +83,7 @@ * @param consume * @return success */ -bool readMultiBlock(uint32_t address, consumer consume); +bool readMultiBlock(uint32_t address, Consumer consume); /** * Writes a single block of 512 bytes starting at the given address diff --git a/types.h b/types.h index 0a398b0..726a167 100644 --- a/types.h +++ b/types.h @@ -40,7 +40,7 @@ * Pointer to a function that takes an array of bytes * and returns a boolean. */ -typedef bool (*consumer)(uint8_t*); +typedef bool (*Consumer)(uint8_t*); #endif /* TYPES_H */