GR-PEACH Digital Signage sample.

Dependencies:   Display_shield_config GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP SDBlockDevice_GR_PEACH USBHost_custom scan_folder

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.



What is this ?

This example is decording JPEG files in onboard flash memory using the GR-PEACH hardware decoders. You can easily operate the screen with your fingers or USB mouse. When micro SD card or USB memory is detected, the sample will show JPEG giles on the deteted filesystem.
After displaying a certain period of time, to display the next JPEG file. JPEG files will be enlarged / reduced in accordance with the image resolution to be output to the display. For this reason, the JPEG file resolution is most clearly displayed when the same as the resolution of the display output. Display order of the JPEG file is a directory analyze order. Please write the JPEG file to the memory in the order you want to display.

/media/uploads/dkato/digital_signage_1.jpg

Supported JPEG image

The location of the fileThe depth of the folder is to 8 hierarchies.
Extension".jpg" , ".JPG"
Resolution restrictionUpper limit 1280 x 800 Pixel. MCU unit.
The size upper limit450Kbyte
The formatJPEG baseline. (Optimization and progressive are not supported.)


Touch panel operation

The following operation is possible by a touch panel.

operationwork
Left flickThe next JPEG file is indicated.
(In the case of "SCROLL_DIRECTION=1", the previous JPEG file is indicated.)
Right flickThe previous JPEG file is indicated.
(In the case of "SCROLL_DIRECTION=1", the next JPEG file is indicated.)
Pinch outEnlarge the image.
Pinch inReduced the image.
Double tapReturn the image to its original size.


Mouse operation

The following operation is possible by a usb mouse.

operationwork
Left clickhe next JPEG file is indicated.
Right clickThe previous JPEG file is indicated.
Center click
(Center wheel push)
Mouse pointer display. While a mouse pointer is being indicated, automatic page turning isn't done.
Center wheelWhen a mouse pointer is indicated:Enlarge / Reduced the image.
When a mouse pointer is not indicated:The automatic page turning interval is changed.

The USB mouse which functions by the following sample can be used.
https://developer.mbed.org/handbook/USBHostMouse

Function settings

The function setting can be changed by the following macro.

main.cpp

/**** User Selection *********/
#define WAIT_TIME                           (10000) /* wait time (ms) 0:infinite */
#define DISSOLVE_STEP_NUM                   (16)    /* minimum 1 */
#define SCROLL_STEP_NUM                     (8)     /* minimum 1 */
#define SCROLL_DIRECTION                    (-1)    /* Select 1(left to right) or -1(right to left) */
/** LCD setting **/
#define LCD_TYPE                            (0)     /* Select 0(4.3inch) , 1(7.1inch), 2(Display shield) or 3(RSK TFT) */
/*****************************/


WAIT_TIMEThe automatic page turning interval is changed. The unit is ms.
The center wheel of USB mouse or USER_BUTTON0 can be changed.
DISSOLVE_STEP_NUMThe effect amount at automatic page turning is set. The minimum value is 1.
SCROLL_STEP_NUMThe effect amount at manual page turning is set. The minimum value is 1.
SCROLL_DIRECTIONThe scrolling direction at manual page turning is set. 1:left to right. -1:right to left.
LCD_TYPEType of LCD. 0:GR-PEACH 4.3 inch LCD Shield. 1:GR-PEACH 7.1 inch LCD Shield. 2:DISPLAY SHIELD(Not for sale).3:RSK TFT.
When using the DISPLAY SHIELD, you need to close the JP3, JP8, JP9, JP10 and JP11. For more details, see here.


Constitution

GR-PEACH, micro SD card or USB memory, USB mouse(If you want to mouse operation), USB HUB(If you use both USB memory and USB mouse), LCD Shield
You need to close the JP3 when using USB.. /media/uploads/RyoheiHagimoto/usb.jpg

Examples of creating images that conform to the JPEG baseline using the GIMP

In this sample, you can display only JPEG files that conform to the JPEG baseline.
Please try the following steps if there is a JPEG file that can not be displayed.

  1. Install picture edit tool GIMP
  2. Open an image file in GIMP.
    1. Right-click on the image file.
    2. Choose "Edit with GIMP".
  3. Change the picture size
    1. "Image" -> "Scale Image"
  4. Save it by the JPEG form.
    1. "File" -> "Export As..."
    2. Choose the save places.(The file extension ".jpg".)
    3. Click on the "Export".
    4. Click on "+Advanced Options".
    5. Remove the check of the "Progressive" and "Optimize".
    6. Click on "Export". (Attention: When the output size exceeds 450Kbyte, please adjust the quality value.)


概要

オンボードフラッシュメモリに書き込まれたJPEGファイルをGR-PEACHのハードウエアでデコードしています。 表示画面はタッチパネルやUSBマウスで操作することができます。 micro SDカード、または、USBメモリを接続すると、ファイルシステム上のJPEGファイルを表示します。
一定時間表示(時間の変更可)すると次のJPEGファイルを表示します。 JPEGファイルはディスプレイに出力する画像解像度にあわせて拡大/縮小されます。そのため、JPEGファイルはディスプレイ出力に近い解像度のほうが鮮明に表示されます。 JPEGファイルの表示順はディレクトリ解析順です。表示したい順にJPEGファイルを1ファイルずつUSBメモリに書き込んでください。

/media/uploads/dkato/digital_signage_1.jpg

表示可能なJPEGファイル

ファイル位置フォルダの深さはルートフォルダを含め8階層まで。
ファイル名半角英数字 (全角には対応していません)
拡張子".jpg" , ".JPG"
解像度制限上限1280 x 800 ピクセル。MCU単位のサイズ。
サイズ上限450Kbyte
フォーマットJPEGベースラインに準拠 (最適化、および、プログレッシブには対応していません)


タッチパネル操作

LCD上のタッチパネルにて、以下の操作が可能です。

操作動作
左フリック次のJPEGファイルを表示します。
(SCROLL_DIRECTION=1時は一つ前のJPEGファイルを表示します。)
右フリック一つ前のJPEGファイルを表示します。
(SCROLL_DIRECTION=1時は次のJPEGファイルを表示します。)
ピンチアウト画面を拡大します。
ピンチイン拡大した画面を縮小します。
ダブルタップ拡大中に、素早く画面を2回タップすると元のサイズに戻します。


マウス操作

USBマウスを接続することで、以下の操作が可能です。

操作動作
左クリック次のJPEGファイルを表示します。
右クリック一つ前のJPEGファイルを表示します。
センタークリック
(センターホイール押し込み)
マウスポインタ表示。マウスポインタ表示中は時間経過による次ファイル遷移は行いません。
センターホイールマウスポインタ表示中:画面の拡大/縮小。
マウスポインタ非表示中:JPEGファイルの表示する時間を変更。

一部使用できないUSBマウスがあります。使用可能なUSBマウスは下記サンプルで動作するデバイスのみです。
https://developer.mbed.org/handbook/USBHostMouse

機能設定

下記のマクロを変更することで、一部機能を変更できます。

main.cpp

/**** User Selection *********/
#define WAIT_TIME                           (10000) /* wait time (ms) 0:infinite */
#define DISSOLVE_STEP_NUM                   (16)    /* minimum 1 */
#define SCROLL_STEP_NUM                     (8)     /* minimum 1 */
#define SCROLL_DIRECTION                    (-1)    /* Select 1(left to right) or -1(right to left) */
/** LCD setting **/
#define LCD_TYPE                            (0)    /* Select 0(4.3inch) , 1(7.1inch), 2(Display shield) or 3(RSK TFT) */
/*****************************/


WAIT_TIME一つのJPEGファイルを表示する時間(デフォルト値)を設定します。単位はmsです。
動作後はUSER_BUTTON0、または、マウスのホイールで表示時間を変更できます。
DISSOLVE_STEP_NUM時間経過によって表示が変わる際のDISSOLVEエフェクトの長さを設定します。設定可能な最小値は1です。
SCROLL_STEP_NUM画面遷移時のスクロールエフェクトの長さを設定します。設定可能な最小値は1です。
SCROLL_DIRECTION次画面遷移時のスクロール方向を設定します。1を設定すると左から右へスクロール、-1を設定すると右から左へスクロールします。
LCD_TYPE0を設定するとGR-PEACH 4.3 inch LCD Shield、1を設定するとGR-PEACH 7.1 inch LCD Shield、2を設定するとDISPLAY SHIELD(非売品)、3を設定するとRSKボード用TFTの設定となります。
DISPLAY SHIELDを使用する際は、GR-PEACHのJP3、JP8、JP9、JP10、JP11をショートする必要があります。Jumper位置についてはこちらを参照ください。


構成

GR-PEACH、micro SDカード または USBメモリ、USBマウス(マウス操作を行わない場合は不要)、USB HUB(USBメモリとUSBマウスを両方使用する場合)、LCD Shield。
USBを使用する際はJP3をショートする必要があります。 /media/uploads/RyoheiHagimoto/usb.jpg

GIMPを使ったJPEGベースラインに準拠 したJPEGファイルの作成例

このサンプルでは、JPEGベースラインに準拠したJPEGファイルのみ表示可能です。
表示できないJPEGファイルがある場合は以下の手順をお試しください。

  1. 画像編集ツールGIMPをインストールする
  2. GIMPで画像ファイルを開く
    1. 画像ファイル上で右クリック
    2. Edit with GIMPを選択
  3. 画像サイズを変更する
    1. 「画像」→「画像の拡大・縮小」を選んで、画像の拡大・縮小ダイアログをから変更する
  4. JPEG形式で保存
    1. 「ファイル」→「名前をつけてエクスポート」で保存ダイアログを表示
    2. 保存先フォルダを選択 (ファイルの拡張子は.jpg)
    3. 「エクスポート」をクリックし、エクスポートダイアログを表示
    4. 「+詳細設定」の「+」部分をクリックして詳細設定画面を表示
    5. 「最適化」と「プログレッシブ」のチェックを外す
    6. エクスポートボタンを押す (注意:出力サイズが450Kbyteを超える場合は、品質値を調整して下さい。)
Committer:
dkato
Date:
Thu Mar 23 08:55:11 2017 +0000
Revision:
3:fdd3f557d2df
Parent:
2:45e172d6f8b2
Supports mbed os 5.4.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:2156833a74a8 1 #include "mbed.h"
dkato 0:2156833a74a8 2 #include "DisplayBace.h"
dkato 0:2156833a74a8 3 #include "rtos.h"
dkato 0:2156833a74a8 4 #include "RGA.h"
dkato 0:2156833a74a8 5 #include "BinaryImage_RZ_A1H.h"
dkato 3:fdd3f557d2df 6 #include "FATFileSystem.h"
dkato 3:fdd3f557d2df 7 #include "SDBlockDevice_GR_PEACH.h"
dkato 3:fdd3f557d2df 8 #include "USBHostMSD.h"
dkato 0:2156833a74a8 9 #include "USBHostMouse.h"
dkato 0:2156833a74a8 10 #include "scan_folder.h"
dkato 0:2156833a74a8 11
dkato 0:2156833a74a8 12 /**** User Selection *********/
dkato 0:2156833a74a8 13 #define WAIT_TIME (10000) /* wait time (ms) 0:infinite */
dkato 0:2156833a74a8 14 #define DISSOLVE_STEP_NUM (16) /* minimum 1 */
dkato 0:2156833a74a8 15 #define SCROLL_STEP_NUM (8) /* minimum 1 */
dkato 0:2156833a74a8 16 #define SCROLL_DIRECTION (-1) /* Select 1(left to right) or -1(right to left) */
dkato 0:2156833a74a8 17 /** LCD setting **/
dkato 1:73b6cf66cb9a 18 #define LCD_TYPE (0) /* Select 0(4.3inch) , 1(7.1inch), 2(Display shield) or 3(RSK TFT) */
dkato 0:2156833a74a8 19 /*****************************/
dkato 0:2156833a74a8 20
dkato 0:2156833a74a8 21 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_RGB565)
dkato 0:2156833a74a8 22 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32_16BIT)
dkato 0:2156833a74a8 23
dkato 0:2156833a74a8 24 /** LCD shield config **/
dkato 0:2156833a74a8 25 #if (LCD_TYPE == 0)
dkato 0:2156833a74a8 26 #include "LCD_shield_config_4_3inch.h"
dkato 0:2156833a74a8 27 #elif (LCD_TYPE == 1)
dkato 0:2156833a74a8 28 #include "LCD_shield_config_7_1inch.h"
dkato 1:73b6cf66cb9a 29 #elif (LCD_TYPE == 2)
dkato 1:73b6cf66cb9a 30 #include "Display_shield_config.h"
dkato 0:2156833a74a8 31 #else
dkato 1:73b6cf66cb9a 32 #include "LCD_shield_config_RSK_TFT.h"
dkato 0:2156833a74a8 33 #endif
dkato 0:2156833a74a8 34
dkato 0:2156833a74a8 35 #if (SCROLL_DIRECTION == -1)
dkato 0:2156833a74a8 36 #define SCROLL_DIRECTION_NEXT (-1)
dkato 0:2156833a74a8 37 #define SCROLL_DIRECTION_PREV (1)
dkato 0:2156833a74a8 38 #else
dkato 0:2156833a74a8 39 #define SCROLL_DIRECTION_NEXT (1)
dkato 0:2156833a74a8 40 #define SCROLL_DIRECTION_PREV (-1)
dkato 0:2156833a74a8 41 #endif
dkato 0:2156833a74a8 42
dkato 0:2156833a74a8 43 /* FRAME BUFFER Parameter */
dkato 0:2156833a74a8 44 #define FRAME_BUFFER_BYTE_PER_PIXEL (2)
dkato 0:2156833a74a8 45 #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
dkato 0:2156833a74a8 46
dkato 0:2156833a74a8 47 #define EVENT_NONE (0)
dkato 0:2156833a74a8 48 #define EVENT_DISP (1)
dkato 0:2156833a74a8 49 #define EVENT_NEXT (2)
dkato 0:2156833a74a8 50 #define EVENT_PREV (3)
dkato 0:2156833a74a8 51 #define EVENT_MOVE (4)
dkato 0:2156833a74a8 52 #define EVENT_MOVE_END (5)
dkato 0:2156833a74a8 53
dkato 0:2156833a74a8 54 #define MAX_JPEG_SIZE (1024 * 450)
dkato 0:2156833a74a8 55 #define MOUNT_NAME "storage"
dkato 0:2156833a74a8 56
dkato 0:2156833a74a8 57 #define TOUCH_NUM (2u)
dkato 0:2156833a74a8 58
dkato 0:2156833a74a8 59 typedef struct {
dkato 0:2156833a74a8 60 int pos_x;
dkato 0:2156833a74a8 61 int pos_y;
dkato 0:2156833a74a8 62 bool disp_pos;
dkato 0:2156833a74a8 63 bool disp_time;
dkato 0:2156833a74a8 64 bool change;
dkato 0:2156833a74a8 65 } mouse_info_t;
dkato 0:2156833a74a8 66
dkato 0:2156833a74a8 67 typedef struct {
dkato 0:2156833a74a8 68 int event_req;
dkato 0:2156833a74a8 69 uint8_t * p_pic_next;
dkato 0:2156833a74a8 70 uint8_t * p_pic_now;
dkato 0:2156833a74a8 71 float32_t magnification;
dkato 0:2156833a74a8 72 int x_move;
dkato 0:2156833a74a8 73 int swipe_end_move;
dkato 0:2156833a74a8 74 int drow_pos_x;
dkato 0:2156833a74a8 75 int drow_pos_y;
dkato 0:2156833a74a8 76 int scale_end_move_x;
dkato 0:2156833a74a8 77 int scale_end_move_y;
dkato 0:2156833a74a8 78 int min_x;
dkato 0:2156833a74a8 79 int min_y;
dkato 0:2156833a74a8 80 bool scroll;
dkato 0:2156833a74a8 81 } efect_info_t;
dkato 0:2156833a74a8 82
dkato 0:2156833a74a8 83 static const char_t * extension_tbl[] = {
dkato 0:2156833a74a8 84 ".jpg",
dkato 0:2156833a74a8 85 NULL
dkato 0:2156833a74a8 86 };
dkato 0:2156833a74a8 87 static InterruptIn button(USER_BUTTON0);
dkato 0:2156833a74a8 88 static DisplayBase Display;
dkato 0:2156833a74a8 89 static Canvas2D_ContextClass canvas2d;
dkato 0:2156833a74a8 90 #if (LCD_TYPE != 2)
dkato 0:2156833a74a8 91 static DigitalOut lcd_pwon(P7_15);
dkato 0:2156833a74a8 92 static DigitalOut lcd_blon(P8_1);
dkato 0:2156833a74a8 93 static PwmOut lcd_cntrst(P8_15);
dkato 0:2156833a74a8 94 #endif
dkato 0:2156833a74a8 95 static Serial pc(USBTX, USBRX);
dkato 0:2156833a74a8 96 static Timer system_timer;
dkato 0:2156833a74a8 97 static Semaphore sem_touch_int(0);
dkato 3:fdd3f557d2df 98 static Thread mouseTask(osPriorityNormal, 1024);
dkato 3:fdd3f557d2df 99 #ifdef TouckKey_LCD_shield
dkato 3:fdd3f557d2df 100 static Thread touchTask(osPriorityNormal, 1024 * 8);
dkato 3:fdd3f557d2df 101 #endif
dkato 0:2156833a74a8 102
dkato 0:2156833a74a8 103 #if defined(__ICCARM__)
dkato 0:2156833a74a8 104 #pragma data_alignment=32
dkato 0:2156833a74a8 105 static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
dkato 2:45e172d6f8b2 106 #pragma data_alignment=32
dkato 0:2156833a74a8 107 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
dkato 0:2156833a74a8 108 #pragma data_alignment=8
dkato 0:2156833a74a8 109 static uint8_t JpegBuffer[MAX_JPEG_SIZE]@ ".mirrorram"; //8 bytes aligned!;
dkato 0:2156833a74a8 110 #else
dkato 0:2156833a74a8 111 static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */
dkato 0:2156833a74a8 112 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */
dkato 0:2156833a74a8 113 static uint8_t JpegBuffer[MAX_JPEG_SIZE]__attribute((section("NC_BSS"),aligned(8))); //8 bytes aligned!;
dkato 0:2156833a74a8 114 #endif
dkato 0:2156833a74a8 115 static frame_buffer_t frame_buffer_info;
dkato 0:2156833a74a8 116 static volatile int32_t vsync_count = 0;
dkato 0:2156833a74a8 117 static ScanFolder scan_foler;
dkato 0:2156833a74a8 118
dkato 0:2156833a74a8 119 static mouse_info_t mouse_info = {0, 0, false, false, false};
dkato 0:2156833a74a8 120
dkato 0:2156833a74a8 121 static int disp_wait_time = WAIT_TIME;
dkato 0:2156833a74a8 122 static uint32_t file_id_now = 0xffffffff;
dkato 0:2156833a74a8 123 static uint32_t file_id_next = 0xffffffff;
dkato 0:2156833a74a8 124 static int dissolve_seq = 0;
dkato 0:2156833a74a8 125 static efect_info_t efect_info;
dkato 0:2156833a74a8 126
dkato 0:2156833a74a8 127 #define ROM_PIC_NUM (4)
dkato 0:2156833a74a8 128 static bool storage_mode = false;
dkato 0:2156833a74a8 129 static uint32_t total_file_num = ROM_PIC_NUM;
dkato 0:2156833a74a8 130
dkato 0:2156833a74a8 131 static const graphics_image_t* number_tbl[10] = {
dkato 0:2156833a74a8 132 number0_Img,
dkato 0:2156833a74a8 133 number1_Img,
dkato 0:2156833a74a8 134 number2_Img,
dkato 0:2156833a74a8 135 number3_Img,
dkato 0:2156833a74a8 136 number4_Img,
dkato 0:2156833a74a8 137 number5_Img,
dkato 0:2156833a74a8 138 number6_Img,
dkato 0:2156833a74a8 139 number7_Img,
dkato 0:2156833a74a8 140 number8_Img,
dkato 0:2156833a74a8 141 number9_Img
dkato 0:2156833a74a8 142 };
dkato 0:2156833a74a8 143
dkato 0:2156833a74a8 144 /****** LCD ******/
dkato 0:2156833a74a8 145 static void IntCallbackFunc_LoVsync(DisplayBase::int_type_t int_type) {
dkato 0:2156833a74a8 146 /* Interrupt callback function for Vsync interruption */
dkato 0:2156833a74a8 147 if (vsync_count > 0) {
dkato 0:2156833a74a8 148 vsync_count--;
dkato 0:2156833a74a8 149 }
dkato 0:2156833a74a8 150 }
dkato 0:2156833a74a8 151
dkato 0:2156833a74a8 152 static void Wait_Vsync(const int32_t wait_count) {
dkato 0:2156833a74a8 153 /* Wait for the specified number of times Vsync occurs */
dkato 0:2156833a74a8 154 vsync_count = wait_count;
dkato 0:2156833a74a8 155 while (vsync_count > 0) {
dkato 0:2156833a74a8 156 /* Do nothing */
dkato 0:2156833a74a8 157 }
dkato 0:2156833a74a8 158 }
dkato 0:2156833a74a8 159
dkato 0:2156833a74a8 160 static void Init_LCD_Display(void) {
dkato 0:2156833a74a8 161 DisplayBase::graphics_error_t error;
dkato 0:2156833a74a8 162 DisplayBase::lcd_config_t lcd_config;
dkato 0:2156833a74a8 163 #if (LCD_TYPE == 2)
dkato 0:2156833a74a8 164 PinName lcd_pin[28] = {
dkato 0:2156833a74a8 165 /* data pin */
dkato 0:2156833a74a8 166 P11_15, P11_14, P11_13, P11_12, P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0,
dkato 0:2156833a74a8 167 P4_7, P4_6, P4_5, P4_4, P10_12, P10_13, P10_14, P10_15, P3_15, P3_14, P3_13,
dkato 0:2156833a74a8 168 P3_12, P3_11, P3_10, P3_9, P3_8
dkato 0:2156833a74a8 169 };
dkato 0:2156833a74a8 170 Display.Graphics_Lcd_Port_Init(lcd_pin, 28);
dkato 0:2156833a74a8 171 #else
dkato 0:2156833a74a8 172 PinName lvds_pin[8] = {
dkato 0:2156833a74a8 173 /* data pin */
dkato 0:2156833a74a8 174 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0
dkato 0:2156833a74a8 175 };
dkato 0:2156833a74a8 176
dkato 0:2156833a74a8 177 lcd_pwon = 0;
dkato 0:2156833a74a8 178 lcd_blon = 0;
dkato 0:2156833a74a8 179 Thread::wait(100);
dkato 0:2156833a74a8 180 lcd_pwon = 1;
dkato 0:2156833a74a8 181 lcd_blon = 1;
dkato 0:2156833a74a8 182
dkato 0:2156833a74a8 183 Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
dkato 0:2156833a74a8 184 #endif
dkato 0:2156833a74a8 185
dkato 0:2156833a74a8 186 /* Graphics initialization process */
dkato 0:2156833a74a8 187 lcd_config = LcdCfgTbl_LCD_shield;
dkato 0:2156833a74a8 188 error = Display.Graphics_init(&lcd_config);
dkato 0:2156833a74a8 189 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2156833a74a8 190 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2156833a74a8 191 mbed_die();
dkato 0:2156833a74a8 192 }
dkato 0:2156833a74a8 193
dkato 0:2156833a74a8 194 /* Interrupt callback function setting (Vsync signal output from scaler 0) */
dkato 0:2156833a74a8 195 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_LoVsync);
dkato 0:2156833a74a8 196 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:2156833a74a8 197 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:2156833a74a8 198 mbed_die();
dkato 0:2156833a74a8 199 }
dkato 0:2156833a74a8 200 }
dkato 0:2156833a74a8 201
dkato 0:2156833a74a8 202 static void Start_LCD_Display(uint8_t * p_buf) {
dkato 0:2156833a74a8 203 DisplayBase::rect_t rect;
dkato 0:2156833a74a8 204
dkato 0:2156833a74a8 205 rect.vs = 0;
dkato 0:2156833a74a8 206 rect.vw = LCD_PIXEL_HEIGHT;
dkato 0:2156833a74a8 207 rect.hs = 0;
dkato 0:2156833a74a8 208 rect.hw = LCD_PIXEL_WIDTH;
dkato 0:2156833a74a8 209 Display.Graphics_Read_Setting(
dkato 0:2156833a74a8 210 DisplayBase::GRAPHICS_LAYER_0,
dkato 0:2156833a74a8 211 (void *)p_buf,
dkato 0:2156833a74a8 212 FRAME_BUFFER_STRIDE,
dkato 0:2156833a74a8 213 GRAPHICS_FORMAT,
dkato 0:2156833a74a8 214 WR_RD_WRSWA,
dkato 0:2156833a74a8 215 &rect
dkato 0:2156833a74a8 216 );
dkato 0:2156833a74a8 217 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
dkato 0:2156833a74a8 218 }
dkato 0:2156833a74a8 219
dkato 0:2156833a74a8 220 static void Update_LCD_Display(frame_buffer_t * frmbuf_info) {
dkato 0:2156833a74a8 221 Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0,
dkato 0:2156833a74a8 222 (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]);
dkato 0:2156833a74a8 223 Wait_Vsync(1);
dkato 0:2156833a74a8 224 }
dkato 0:2156833a74a8 225
dkato 0:2156833a74a8 226 static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) {
dkato 0:2156833a74a8 227 if (frmbuf_info->draw_buffer_index == 1) {
dkato 0:2156833a74a8 228 frmbuf_info->draw_buffer_index = 0;
dkato 0:2156833a74a8 229 } else {
dkato 0:2156833a74a8 230 frmbuf_info->draw_buffer_index = 1;
dkato 0:2156833a74a8 231 }
dkato 0:2156833a74a8 232 }
dkato 0:2156833a74a8 233
dkato 0:2156833a74a8 234
dkato 0:2156833a74a8 235 /****** Draw Image ******/
dkato 0:2156833a74a8 236 static void draw_mouse_pos(void) {
dkato 0:2156833a74a8 237 if (mouse_info.disp_pos != false) {
dkato 0:2156833a74a8 238 /* Draw a image */
dkato 0:2156833a74a8 239 canvas2d.drawImage(mousu_pos_Img, mouse_info.pos_x, mouse_info.pos_y);
dkato 0:2156833a74a8 240 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 241 }
dkato 0:2156833a74a8 242 }
dkato 0:2156833a74a8 243
dkato 0:2156833a74a8 244 static void draw_disp_time(void) {
dkato 0:2156833a74a8 245 if (mouse_info.disp_time != false) {
dkato 0:2156833a74a8 246 int wk_ofs = (LCD_PIXEL_WIDTH - 215) / 2 + 103;
dkato 0:2156833a74a8 247 int wk_sec;
dkato 0:2156833a74a8 248
dkato 0:2156833a74a8 249 /* Draw a image */
dkato 0:2156833a74a8 250 canvas2d.drawImage(disp_xsec_Img, (LCD_PIXEL_WIDTH - 215) / 2, LCD_PIXEL_HEIGHT / 2);
dkato 0:2156833a74a8 251 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 252
dkato 0:2156833a74a8 253 if (disp_wait_time == 0) {
dkato 0:2156833a74a8 254 /* Draw a image */
dkato 0:2156833a74a8 255 canvas2d.drawImage(number_inf_Img, wk_ofs, LCD_PIXEL_HEIGHT / 2);
dkato 0:2156833a74a8 256 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 257 } else {
dkato 0:2156833a74a8 258 wk_sec = (disp_wait_time / 10000) % 10;
dkato 0:2156833a74a8 259 if (wk_sec != 0) {
dkato 0:2156833a74a8 260 /* Draw a image */
dkato 0:2156833a74a8 261 canvas2d.drawImage(number_tbl[wk_sec], wk_ofs, LCD_PIXEL_HEIGHT / 2);
dkato 0:2156833a74a8 262 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 263 wk_ofs += 12;
dkato 0:2156833a74a8 264 } else {
dkato 0:2156833a74a8 265 wk_ofs += 6;
dkato 0:2156833a74a8 266 }
dkato 0:2156833a74a8 267 wk_sec = (disp_wait_time / 1000) % 10;
dkato 0:2156833a74a8 268 /* Draw a image */
dkato 0:2156833a74a8 269 canvas2d.drawImage(number_tbl[wk_sec], wk_ofs, LCD_PIXEL_HEIGHT / 2);
dkato 0:2156833a74a8 270 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 271 }
dkato 0:2156833a74a8 272 }
dkato 0:2156833a74a8 273 }
dkato 0:2156833a74a8 274
dkato 0:2156833a74a8 275 static void draw_image_scroll(frame_buffer_t* frmbuf_info, const graphics_image_t* image_last,
dkato 0:2156833a74a8 276 const graphics_image_t* image_new, float32_t scroll, int ditection) {
dkato 0:2156833a74a8 277 Swap_FrameBuffer(frmbuf_info);
dkato 0:2156833a74a8 278 /* Clear */
dkato 0:2156833a74a8 279 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 280 /* Draw a image */
dkato 0:2156833a74a8 281 canvas2d.globalAlpha = 1.0f;
dkato 0:2156833a74a8 282 canvas2d.drawImage((const graphics_image_t*)image_last,
dkato 0:2156833a74a8 283 (int_t)(frmbuf_info->width * scroll) * ditection, 0,
dkato 0:2156833a74a8 284 frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 285 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 286 canvas2d.globalAlpha = 1.0f;
dkato 0:2156833a74a8 287 canvas2d.drawImage((const graphics_image_t*)image_new,
dkato 0:2156833a74a8 288 ((int_t)(frmbuf_info->width * scroll) - frmbuf_info->width) * ditection, 0,
dkato 0:2156833a74a8 289 frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 290 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 291 /* mouse pos */
dkato 0:2156833a74a8 292 draw_mouse_pos();
dkato 0:2156833a74a8 293 draw_disp_time();
dkato 0:2156833a74a8 294 /* Complete drawing */
dkato 0:2156833a74a8 295 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
dkato 0:2156833a74a8 296 Update_LCD_Display(frmbuf_info);
dkato 0:2156833a74a8 297 }
dkato 0:2156833a74a8 298
dkato 0:2156833a74a8 299 static void draw_image_dissolve(frame_buffer_t* frmbuf_info, const graphics_image_t* image_last,
dkato 0:2156833a74a8 300 const graphics_image_t* image_new, float32_t alpha) {
dkato 0:2156833a74a8 301 Swap_FrameBuffer(frmbuf_info);
dkato 0:2156833a74a8 302 /* Clear */
dkato 0:2156833a74a8 303 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 304 /* Draw a image */
dkato 0:2156833a74a8 305 canvas2d.globalAlpha = 1.0f - alpha;
dkato 0:2156833a74a8 306 canvas2d.drawImage((const graphics_image_t*)image_last, 0, 0, frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 307 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 308 canvas2d.globalAlpha = alpha;
dkato 0:2156833a74a8 309 canvas2d.drawImage((const graphics_image_t*)image_new, 0, 0, frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 310 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 311 /* mouse pos */
dkato 0:2156833a74a8 312 draw_mouse_pos();
dkato 0:2156833a74a8 313 draw_disp_time();
dkato 0:2156833a74a8 314 /* Complete drawing */
dkato 0:2156833a74a8 315 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
dkato 0:2156833a74a8 316 Update_LCD_Display(frmbuf_info);
dkato 0:2156833a74a8 317 }
dkato 0:2156833a74a8 318
dkato 0:2156833a74a8 319 static void draw_image(frame_buffer_t* frmbuf_info, const graphics_image_t* image_new,
dkato 0:2156833a74a8 320 uint32_t pos_x, uint32_t pos_y, graphics_matrix_float_t zoom) {
dkato 0:2156833a74a8 321 int_t dest_width;
dkato 0:2156833a74a8 322 int_t dest_height;
dkato 0:2156833a74a8 323
dkato 0:2156833a74a8 324 Swap_FrameBuffer(frmbuf_info);
dkato 0:2156833a74a8 325 /* Clear */
dkato 0:2156833a74a8 326 canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height);
dkato 0:2156833a74a8 327 /* Draw a image */
dkato 0:2156833a74a8 328 canvas2d.globalAlpha = 1.0f;
dkato 0:2156833a74a8 329 dest_width = frmbuf_info->width * zoom;
dkato 0:2156833a74a8 330 dest_height = frmbuf_info->height * zoom;
dkato 0:2156833a74a8 331 canvas2d.drawImage((const graphics_image_t*)image_new,
dkato 0:2156833a74a8 332 pos_x, pos_y, dest_width, dest_height);
dkato 0:2156833a74a8 333 R_OSPL_CLEAR_ERROR();
dkato 0:2156833a74a8 334 /* mouse pos */
dkato 0:2156833a74a8 335 draw_mouse_pos();
dkato 0:2156833a74a8 336 draw_disp_time();
dkato 0:2156833a74a8 337 /* Complete drawing */
dkato 0:2156833a74a8 338 R_GRAPHICS_Finish(canvas2d.c_LanguageContext);
dkato 0:2156833a74a8 339 Update_LCD_Display(frmbuf_info);
dkato 0:2156833a74a8 340 }
dkato 0:2156833a74a8 341
dkato 0:2156833a74a8 342
dkato 0:2156833a74a8 343 /****** File Access ******/
dkato 0:2156833a74a8 344 static bool read_new_file(uint8_t ** pp_buf, uint32_t file_id) {
dkato 0:2156833a74a8 345 bool ret = false;
dkato 0:2156833a74a8 346
dkato 0:2156833a74a8 347 if (storage_mode == false) {
dkato 0:2156833a74a8 348 ret = true;
dkato 0:2156833a74a8 349 switch (file_id) {
dkato 0:2156833a74a8 350 case 0: *pp_buf = (uint8_t *)img01_File; break;
dkato 0:2156833a74a8 351 case 1: *pp_buf = (uint8_t *)img02_File; break;
dkato 0:2156833a74a8 352 case 2: *pp_buf = (uint8_t *)img03_File; break;
dkato 0:2156833a74a8 353 case 3: *pp_buf = (uint8_t *)img04_File; break;
dkato 0:2156833a74a8 354 default: ret = false; break;
dkato 0:2156833a74a8 355 }
dkato 0:2156833a74a8 356 } else {
dkato 0:2156833a74a8 357 FILE * fp = scan_foler.open(file_id);
dkato 0:2156833a74a8 358 size_t read_size;
dkato 0:2156833a74a8 359
dkato 0:2156833a74a8 360 read_size = fread(*pp_buf, sizeof(char), MAX_JPEG_SIZE, fp);
dkato 0:2156833a74a8 361 scan_foler.close(fp);
dkato 0:2156833a74a8 362 if (read_size < MAX_JPEG_SIZE) {
dkato 0:2156833a74a8 363 ret = true;
dkato 0:2156833a74a8 364 }
dkato 0:2156833a74a8 365 }
dkato 0:2156833a74a8 366
dkato 0:2156833a74a8 367 return ret;
dkato 0:2156833a74a8 368 }
dkato 0:2156833a74a8 369
dkato 0:2156833a74a8 370 static void swap_file_buff(void) {
dkato 0:2156833a74a8 371 uint8_t * p_wk_pic = efect_info.p_pic_now;
dkato 0:2156833a74a8 372 uint32_t wk_file_id = file_id_now;
dkato 0:2156833a74a8 373
dkato 0:2156833a74a8 374 efect_info.p_pic_now = efect_info.p_pic_next;
dkato 0:2156833a74a8 375 efect_info.p_pic_next = p_wk_pic;
dkato 0:2156833a74a8 376 file_id_now = file_id_next;
dkato 0:2156833a74a8 377 file_id_next = wk_file_id;
dkato 0:2156833a74a8 378 }
dkato 0:2156833a74a8 379
dkato 0:2156833a74a8 380 static bool read_next_file(void) {
dkato 0:2156833a74a8 381 uint32_t wk_file_id;
dkato 0:2156833a74a8 382 bool ret = false;
dkato 0:2156833a74a8 383
dkato 0:2156833a74a8 384 if (file_id_now < (total_file_num - 1)) {
dkato 0:2156833a74a8 385 wk_file_id = file_id_now + 1;
dkato 0:2156833a74a8 386 } else {
dkato 0:2156833a74a8 387 wk_file_id = 0;
dkato 0:2156833a74a8 388 }
dkato 0:2156833a74a8 389 if (wk_file_id != file_id_next) {
dkato 0:2156833a74a8 390 ret = read_new_file(&efect_info.p_pic_next, wk_file_id);
dkato 0:2156833a74a8 391 if (ret != false) {
dkato 0:2156833a74a8 392 file_id_next = wk_file_id;
dkato 0:2156833a74a8 393 }
dkato 0:2156833a74a8 394 } else {
dkato 0:2156833a74a8 395 ret = true;
dkato 0:2156833a74a8 396 }
dkato 0:2156833a74a8 397
dkato 0:2156833a74a8 398 return ret;
dkato 0:2156833a74a8 399 }
dkato 0:2156833a74a8 400
dkato 0:2156833a74a8 401 static bool read_prev_file(void) {
dkato 0:2156833a74a8 402 uint32_t wk_file_id;
dkato 0:2156833a74a8 403 bool ret = false;
dkato 0:2156833a74a8 404
dkato 0:2156833a74a8 405 if (file_id_now >= total_file_num) {
dkato 0:2156833a74a8 406 wk_file_id = 0;
dkato 0:2156833a74a8 407 } else if (file_id_now != 0) {
dkato 0:2156833a74a8 408 wk_file_id = file_id_now - 1;
dkato 0:2156833a74a8 409 } else {
dkato 0:2156833a74a8 410 wk_file_id = total_file_num - 1;
dkato 0:2156833a74a8 411 }
dkato 0:2156833a74a8 412 if (wk_file_id != file_id_next) {
dkato 0:2156833a74a8 413 ret = read_new_file(&efect_info.p_pic_next, wk_file_id);
dkato 0:2156833a74a8 414 if (ret != false) {
dkato 0:2156833a74a8 415 file_id_next = wk_file_id;
dkato 0:2156833a74a8 416 }
dkato 0:2156833a74a8 417 } else {
dkato 0:2156833a74a8 418 ret = true;
dkato 0:2156833a74a8 419 }
dkato 0:2156833a74a8 420
dkato 0:2156833a74a8 421 return ret;
dkato 0:2156833a74a8 422 }
dkato 0:2156833a74a8 423
dkato 0:2156833a74a8 424
dkato 0:2156833a74a8 425 /****** Efect setting ******/
dkato 0:2156833a74a8 426 static void zoom_scroll(int x, int y) {
dkato 0:2156833a74a8 427 efect_info.drow_pos_x += x;
dkato 0:2156833a74a8 428 if (efect_info.drow_pos_x < efect_info.min_x) {
dkato 0:2156833a74a8 429 efect_info.drow_pos_x = efect_info.min_x;
dkato 0:2156833a74a8 430 }
dkato 0:2156833a74a8 431 if (efect_info.drow_pos_x > 0) {
dkato 0:2156833a74a8 432 efect_info.drow_pos_x = 0;
dkato 0:2156833a74a8 433 }
dkato 0:2156833a74a8 434 efect_info.drow_pos_y += y;
dkato 0:2156833a74a8 435 if (efect_info.drow_pos_y < efect_info.min_y) {
dkato 0:2156833a74a8 436 efect_info.drow_pos_y = efect_info.min_y;
dkato 0:2156833a74a8 437 }
dkato 0:2156833a74a8 438 if (efect_info.drow_pos_y > 0) {
dkato 0:2156833a74a8 439 efect_info.drow_pos_y = 0;
dkato 0:2156833a74a8 440 }
dkato 0:2156833a74a8 441 }
dkato 0:2156833a74a8 442
dkato 0:2156833a74a8 443 static void move_func(int x, int y) {
dkato 0:2156833a74a8 444 if (efect_info.magnification != 1.0f) {
dkato 0:2156833a74a8 445 zoom_scroll(x, y);
dkato 0:2156833a74a8 446 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 447 } else {
dkato 0:2156833a74a8 448 efect_info.scroll = true;
dkato 0:2156833a74a8 449 efect_info.x_move += x;
dkato 0:2156833a74a8 450 efect_info.event_req = EVENT_MOVE;
dkato 0:2156833a74a8 451 }
dkato 0:2156833a74a8 452 }
dkato 0:2156833a74a8 453
dkato 0:2156833a74a8 454 static void move_end_func(int x, int y) {
dkato 0:2156833a74a8 455 if (efect_info.magnification != 1.0f) {
dkato 0:2156833a74a8 456 efect_info.scale_end_move_x = x;
dkato 0:2156833a74a8 457 efect_info.scale_end_move_y = y;
dkato 0:2156833a74a8 458 } else {
dkato 0:2156833a74a8 459 if (efect_info.scroll != false) {
dkato 0:2156833a74a8 460 efect_info.scroll = false;
dkato 0:2156833a74a8 461 if (efect_info.x_move != 0) {
dkato 0:2156833a74a8 462 efect_info.swipe_end_move = x;
dkato 0:2156833a74a8 463 efect_info.event_req = EVENT_MOVE_END;
dkato 0:2156833a74a8 464 }
dkato 0:2156833a74a8 465 }
dkato 0:2156833a74a8 466 }
dkato 0:2156833a74a8 467 }
dkato 0:2156833a74a8 468
dkato 0:2156833a74a8 469 static void zoom_func(uint32_t center_x_last, uint32_t center_y_last, uint32_t center_x, uint32_t center_y, float32_t new_magnification) {
dkato 0:2156833a74a8 470 if (new_magnification != efect_info.magnification) {
dkato 0:2156833a74a8 471 if (new_magnification < 1.0f) {
dkato 0:2156833a74a8 472 new_magnification = 1.0f;
dkato 0:2156833a74a8 473 }
dkato 0:2156833a74a8 474 if (new_magnification > 10.0f) {
dkato 0:2156833a74a8 475 new_magnification = 10.0f;
dkato 0:2156833a74a8 476 }
dkato 0:2156833a74a8 477 efect_info.min_x = 0 - (frame_buffer_info.width * (new_magnification - 1.0f));
dkato 0:2156833a74a8 478 efect_info.min_y = 0 - (frame_buffer_info.height * (new_magnification - 1.0f));
dkato 0:2156833a74a8 479
dkato 0:2156833a74a8 480 efect_info.drow_pos_x = -((center_x_last - efect_info.drow_pos_x) / efect_info.magnification * new_magnification - center_x);
dkato 0:2156833a74a8 481 if (efect_info.drow_pos_x < efect_info.min_x) {
dkato 0:2156833a74a8 482 efect_info.drow_pos_x = efect_info.min_x;
dkato 0:2156833a74a8 483 }
dkato 0:2156833a74a8 484 if (efect_info.drow_pos_x > 0) {
dkato 0:2156833a74a8 485 efect_info.drow_pos_x = 0;
dkato 0:2156833a74a8 486 }
dkato 0:2156833a74a8 487
dkato 0:2156833a74a8 488 efect_info.drow_pos_y = -((center_y_last - efect_info.drow_pos_y) / efect_info.magnification * new_magnification - center_y);
dkato 0:2156833a74a8 489 if (efect_info.drow_pos_y < efect_info.min_y) {
dkato 0:2156833a74a8 490 efect_info.drow_pos_y = efect_info.min_y;
dkato 0:2156833a74a8 491 }
dkato 0:2156833a74a8 492 if (efect_info.drow_pos_y > 0) {
dkato 0:2156833a74a8 493 efect_info.drow_pos_y = 0;
dkato 0:2156833a74a8 494 }
dkato 0:2156833a74a8 495 if (new_magnification == 1.0f) {
dkato 0:2156833a74a8 496 efect_info.drow_pos_x = 0;
dkato 0:2156833a74a8 497 efect_info.drow_pos_y = 0;
dkato 0:2156833a74a8 498 }
dkato 0:2156833a74a8 499 efect_info.x_move = 0;
dkato 0:2156833a74a8 500 efect_info.magnification = new_magnification;
dkato 0:2156833a74a8 501 if (efect_info.event_req == EVENT_NONE) {
dkato 0:2156833a74a8 502 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 503 }
dkato 0:2156833a74a8 504 }
dkato 0:2156833a74a8 505 }
dkato 0:2156833a74a8 506
dkato 0:2156833a74a8 507 /****** Mouse ******/
dkato 0:2156833a74a8 508 void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
dkato 0:2156833a74a8 509 static uint8_t last_buttons = 0;
dkato 0:2156833a74a8 510 int wk_pos;
dkato 0:2156833a74a8 511 int wk_disp_time;
dkato 0:2156833a74a8 512 int mouse_move_x;
dkato 0:2156833a74a8 513 int mouse_move_y;
dkato 0:2156833a74a8 514
dkato 0:2156833a74a8 515 // printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
dkato 0:2156833a74a8 516
dkato 0:2156833a74a8 517 wk_pos = mouse_info.pos_x;
dkato 0:2156833a74a8 518 wk_pos += x;
dkato 0:2156833a74a8 519 mouse_move_x = x;
dkato 0:2156833a74a8 520 if (wk_pos < 0) {
dkato 0:2156833a74a8 521 wk_pos = 0;
dkato 0:2156833a74a8 522 mouse_move_x = 0;
dkato 0:2156833a74a8 523 }
dkato 0:2156833a74a8 524 if (wk_pos > (LCD_PIXEL_WIDTH - 10)) {
dkato 0:2156833a74a8 525 wk_pos = LCD_PIXEL_WIDTH - 10;
dkato 0:2156833a74a8 526 mouse_move_x = 0;
dkato 0:2156833a74a8 527 }
dkato 0:2156833a74a8 528 mouse_info.pos_x = wk_pos;
dkato 0:2156833a74a8 529
dkato 0:2156833a74a8 530 wk_pos = mouse_info.pos_y;
dkato 0:2156833a74a8 531 wk_pos += y;
dkato 0:2156833a74a8 532 mouse_move_y = y;
dkato 0:2156833a74a8 533 if (wk_pos < 0) {
dkato 0:2156833a74a8 534 wk_pos = 0;
dkato 0:2156833a74a8 535 mouse_move_y = 0;
dkato 0:2156833a74a8 536 }
dkato 0:2156833a74a8 537 if (wk_pos > (LCD_PIXEL_HEIGHT - 10)) {
dkato 0:2156833a74a8 538 wk_pos = (LCD_PIXEL_HEIGHT - 10);
dkato 0:2156833a74a8 539 mouse_move_y = 0;
dkato 0:2156833a74a8 540 }
dkato 0:2156833a74a8 541 mouse_info.pos_y = wk_pos;
dkato 0:2156833a74a8 542
dkato 0:2156833a74a8 543 if (mouse_info.disp_pos != false) {
dkato 0:2156833a74a8 544 if ((buttons & 0x01) != 0) {
dkato 0:2156833a74a8 545 move_func(mouse_move_x, mouse_move_y);
dkato 0:2156833a74a8 546 } else if (((buttons & 0x01) == 0) && ((last_buttons & 0x01) != 0)) {
dkato 0:2156833a74a8 547 move_end_func(mouse_move_x, mouse_move_y);
dkato 0:2156833a74a8 548 } else if ((efect_info.event_req == EVENT_NONE) && (dissolve_seq == 0)) {
dkato 0:2156833a74a8 549 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 550 } else {
dkato 0:2156833a74a8 551 /* do nothing */
dkato 0:2156833a74a8 552 }
dkato 0:2156833a74a8 553 } else {
dkato 0:2156833a74a8 554 // left
dkato 0:2156833a74a8 555 if (((buttons & 0x01) == 0) && ((last_buttons & 0x01) != 0)) {
dkato 0:2156833a74a8 556 efect_info.event_req = EVENT_NEXT;
dkato 0:2156833a74a8 557 }
dkato 0:2156833a74a8 558
dkato 0:2156833a74a8 559 // rigth
dkato 0:2156833a74a8 560 if (((buttons & 0x02) == 0) && ((last_buttons & 0x02) != 0)) {
dkato 0:2156833a74a8 561 efect_info.event_req = EVENT_PREV;
dkato 0:2156833a74a8 562 }
dkato 0:2156833a74a8 563 }
dkato 0:2156833a74a8 564
dkato 0:2156833a74a8 565 if (((buttons & 0x04) != 0) && ((last_buttons & 0x04) == 0)) {
dkato 0:2156833a74a8 566 mouse_info.disp_pos = !mouse_info.disp_pos;
dkato 0:2156833a74a8 567 if ((efect_info.event_req == EVENT_NONE) && (dissolve_seq == 0)) {
dkato 0:2156833a74a8 568 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 569 }
dkato 0:2156833a74a8 570 }
dkato 0:2156833a74a8 571
dkato 0:2156833a74a8 572 if (z != 0) {
dkato 0:2156833a74a8 573 if (mouse_info.disp_pos == false) {
dkato 0:2156833a74a8 574 wk_disp_time = disp_wait_time;
dkato 0:2156833a74a8 575 if (z > 0) {
dkato 0:2156833a74a8 576 wk_disp_time += 1000;
dkato 0:2156833a74a8 577 if (wk_disp_time > 15000) {
dkato 0:2156833a74a8 578 wk_disp_time = 15000;
dkato 0:2156833a74a8 579 }
dkato 0:2156833a74a8 580 } else {
dkato 0:2156833a74a8 581 wk_disp_time -= 1000;
dkato 0:2156833a74a8 582 if (wk_disp_time < 1000) {
dkato 0:2156833a74a8 583 wk_disp_time = 0;
dkato 0:2156833a74a8 584 }
dkato 0:2156833a74a8 585 }
dkato 0:2156833a74a8 586 disp_wait_time = wk_disp_time;
dkato 0:2156833a74a8 587 system_timer.reset();
dkato 0:2156833a74a8 588 system_timer.start();
dkato 0:2156833a74a8 589 mouse_info.disp_time = true;
dkato 0:2156833a74a8 590 if ((efect_info.event_req == EVENT_NONE) && (dissolve_seq == 0)) {
dkato 0:2156833a74a8 591 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 592 }
dkato 0:2156833a74a8 593 } else {
dkato 0:2156833a74a8 594 zoom_func(mouse_info.pos_x + 3, mouse_info.pos_y + 3,
dkato 0:2156833a74a8 595 mouse_info.pos_x + 3, mouse_info.pos_y + 3,
dkato 0:2156833a74a8 596 efect_info.magnification * (1.0f + (float_t)z / 10.0f));
dkato 0:2156833a74a8 597 }
dkato 0:2156833a74a8 598 }
dkato 0:2156833a74a8 599
dkato 0:2156833a74a8 600 last_buttons = buttons;
dkato 0:2156833a74a8 601 }
dkato 0:2156833a74a8 602
dkato 3:fdd3f557d2df 603 void mouse_task(void) {
dkato 0:2156833a74a8 604 USBHostMouse mouse;
dkato 0:2156833a74a8 605
dkato 0:2156833a74a8 606 while (1) {
dkato 0:2156833a74a8 607 /* try to connect a USB mouse */
dkato 0:2156833a74a8 608 while (!mouse.connect()) {
dkato 0:2156833a74a8 609 Thread::wait(500);
dkato 0:2156833a74a8 610 }
dkato 0:2156833a74a8 611
dkato 0:2156833a74a8 612 /* when connected, attach handler called on mouse event */
dkato 0:2156833a74a8 613 mouse.attachEvent(onMouseEvent);
dkato 0:2156833a74a8 614
dkato 0:2156833a74a8 615 /* wait until the mouse is disconnected */
dkato 0:2156833a74a8 616 while (mouse.connected()) {
dkato 0:2156833a74a8 617 Thread::wait(500);
dkato 0:2156833a74a8 618 }
dkato 0:2156833a74a8 619 mouse_info.disp_pos = false;
dkato 0:2156833a74a8 620 mouse_info.disp_time = false;
dkato 0:2156833a74a8 621 if ((efect_info.event_req == EVENT_NONE) && (dissolve_seq == 0)) {
dkato 0:2156833a74a8 622 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 623 }
dkato 0:2156833a74a8 624 }
dkato 0:2156833a74a8 625 }
dkato 0:2156833a74a8 626
dkato 0:2156833a74a8 627
dkato 0:2156833a74a8 628 /****** Touch ******/
dkato 0:2156833a74a8 629 #ifdef TouckKey_LCD_shield
dkato 0:2156833a74a8 630 static float32_t get_distance(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) {
dkato 0:2156833a74a8 631 float32_t distance_x;
dkato 0:2156833a74a8 632 float32_t distance_y;
dkato 0:2156833a74a8 633
dkato 0:2156833a74a8 634 if (x0 > x1) {
dkato 0:2156833a74a8 635 distance_x = x0 - x1;
dkato 0:2156833a74a8 636 } else {
dkato 0:2156833a74a8 637 distance_x = x1 - x0;
dkato 0:2156833a74a8 638 }
dkato 0:2156833a74a8 639 if (y0 > y1) {
dkato 0:2156833a74a8 640 distance_y = y0 - y1;
dkato 0:2156833a74a8 641 } else {
dkato 0:2156833a74a8 642 distance_y = y1 - y0;
dkato 0:2156833a74a8 643 }
dkato 0:2156833a74a8 644 return hypotf(distance_x, distance_y);
dkato 0:2156833a74a8 645 }
dkato 0:2156833a74a8 646
dkato 0:2156833a74a8 647 static uint32_t get_center(uint32_t xy0, uint32_t xy1) {
dkato 0:2156833a74a8 648 uint32_t center_pos;
dkato 0:2156833a74a8 649
dkato 0:2156833a74a8 650 if (xy0 > xy1) {
dkato 0:2156833a74a8 651 center_pos = (xy0 - xy1) / 2 + xy1;
dkato 0:2156833a74a8 652 } else {
dkato 0:2156833a74a8 653 center_pos = (xy1 - xy0) / 2 + xy0;
dkato 0:2156833a74a8 654 }
dkato 0:2156833a74a8 655
dkato 0:2156833a74a8 656 return center_pos;
dkato 0:2156833a74a8 657 }
dkato 0:2156833a74a8 658
dkato 0:2156833a74a8 659 static void touch_int_callback(void) {
dkato 0:2156833a74a8 660 sem_touch_int.release();
dkato 0:2156833a74a8 661 }
dkato 0:2156833a74a8 662
dkato 3:fdd3f557d2df 663 static void touch_task(void) {
dkato 0:2156833a74a8 664 bool skip = false;
dkato 0:2156833a74a8 665 bool zoom_on = false;
dkato 0:2156833a74a8 666 uint32_t center_x;
dkato 0:2156833a74a8 667 uint32_t center_y;
dkato 0:2156833a74a8 668 uint32_t center_x_last = 0;
dkato 0:2156833a74a8 669 uint32_t center_y_last = 0;
dkato 0:2156833a74a8 670 int click_cnt = 0;
dkato 0:2156833a74a8 671 int move_x = 0;
dkato 0:2156833a74a8 672 int move_y = 0;
dkato 0:2156833a74a8 673 float32_t distance;
dkato 0:2156833a74a8 674 float32_t distance_last;
dkato 0:2156833a74a8 675 int down_time = 0;;
dkato 0:2156833a74a8 676 int last_down_time = 0;
dkato 0:2156833a74a8 677 int event_time = 0;;
dkato 0:2156833a74a8 678 int event_time_last = 0;
dkato 0:2156833a74a8 679 TouchKey::touch_pos_t touch_pos[TOUCH_NUM];
dkato 0:2156833a74a8 680 TouchKey::touch_pos_t touch_pos_last[TOUCH_NUM];
dkato 0:2156833a74a8 681 int touch_num = 0;
dkato 0:2156833a74a8 682 int touch_num_last = 0;
dkato 0:2156833a74a8 683 Timer touch_timer;
dkato 0:2156833a74a8 684 TouckKey_LCD_shield touch(P4_0, P2_13, I2C_SDA, I2C_SCL);
dkato 0:2156833a74a8 685
dkato 0:2156833a74a8 686 /* Callback setting */
dkato 0:2156833a74a8 687 touch.SetCallback(&touch_int_callback);
dkato 0:2156833a74a8 688
dkato 0:2156833a74a8 689 /* Reset touch IC */
dkato 0:2156833a74a8 690 touch.Reset();
dkato 0:2156833a74a8 691
dkato 0:2156833a74a8 692 touch_timer.reset();
dkato 0:2156833a74a8 693 touch_timer.start();
dkato 0:2156833a74a8 694
dkato 0:2156833a74a8 695 while (1) {
dkato 0:2156833a74a8 696 /* Wait touch event */
dkato 0:2156833a74a8 697 sem_touch_int.wait();
dkato 0:2156833a74a8 698
dkato 0:2156833a74a8 699 /* Get touch coordinates */
dkato 0:2156833a74a8 700 touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
dkato 0:2156833a74a8 701 event_time = touch_timer.read_ms();
dkato 0:2156833a74a8 702 if (touch_num > touch_num_last) {
dkato 0:2156833a74a8 703 if (touch_num_last == 0) {
dkato 0:2156833a74a8 704 down_time = event_time;
dkato 0:2156833a74a8 705 }
dkato 0:2156833a74a8 706 if (touch_num == 2) {
dkato 0:2156833a74a8 707 zoom_on = true;
dkato 0:2156833a74a8 708 }
dkato 0:2156833a74a8 709 move_x = 0;
dkato 0:2156833a74a8 710 move_y = 0;
dkato 0:2156833a74a8 711 distance_last = 0;
dkato 0:2156833a74a8 712 if ((down_time - last_down_time) > 500) {
dkato 0:2156833a74a8 713 click_cnt = 0;
dkato 0:2156833a74a8 714 }
dkato 0:2156833a74a8 715 last_down_time = down_time;
dkato 0:2156833a74a8 716 } else if ((touch_num == 0) && (touch_num_last != 0)) {
dkato 0:2156833a74a8 717 if (((event_time - down_time) < 200)
dkato 0:2156833a74a8 718 && (abs(move_x) < 10) && (abs(move_y) < 10)) {
dkato 0:2156833a74a8 719 click_cnt++;
dkato 0:2156833a74a8 720 if (click_cnt == 2) {
dkato 0:2156833a74a8 721 zoom_func(0, 0, 0, 0, 1.0f);
dkato 0:2156833a74a8 722 }
dkato 0:2156833a74a8 723 move_x = 0;
dkato 0:2156833a74a8 724 move_y = 0;
dkato 0:2156833a74a8 725 } else {
dkato 0:2156833a74a8 726 click_cnt = 0;
dkato 0:2156833a74a8 727 }
dkato 0:2156833a74a8 728 if (zoom_on == false) {
dkato 0:2156833a74a8 729 move_end_func(move_x, move_y);
dkato 0:2156833a74a8 730 }
dkato 0:2156833a74a8 731 zoom_on = false;
dkato 0:2156833a74a8 732 distance_last = 0;
dkato 0:2156833a74a8 733 } else if ((touch_num == 1) && (touch_num_last == 2)) {
dkato 0:2156833a74a8 734 distance_last = 0;
dkato 0:2156833a74a8 735 } else if ((touch_num != 0) && ((event_time - event_time_last) >= 50)) {
dkato 0:2156833a74a8 736 event_time_last = event_time;
dkato 0:2156833a74a8 737 if (touch_num == 1) {
dkato 0:2156833a74a8 738 if (zoom_on == false) {
dkato 0:2156833a74a8 739 move_x = (touch_pos[0].x - touch_pos_last[0].x);
dkato 0:2156833a74a8 740 move_y = (touch_pos[0].y - touch_pos_last[0].y);
dkato 0:2156833a74a8 741 move_func(move_x, move_y);
dkato 0:2156833a74a8 742 }
dkato 0:2156833a74a8 743 } else {
dkato 0:2156833a74a8 744 center_x = get_center(touch_pos[0].x, touch_pos[1].x);
dkato 0:2156833a74a8 745 center_y = get_center(touch_pos[0].y, touch_pos[1].y);
dkato 0:2156833a74a8 746 distance = get_distance(touch_pos[0].x, touch_pos[0].y, touch_pos[1].x, touch_pos[1].y);
dkato 0:2156833a74a8 747 if (distance < 1) {
dkato 0:2156833a74a8 748 distance = 1;
dkato 0:2156833a74a8 749 }
dkato 0:2156833a74a8 750 if (distance_last != 0) {
dkato 0:2156833a74a8 751 zoom_func(center_x_last, center_y_last, center_x, center_y, efect_info.magnification * (distance / distance_last));
dkato 0:2156833a74a8 752 }
dkato 0:2156833a74a8 753 center_x_last = center_x;
dkato 0:2156833a74a8 754 center_y_last = center_y;
dkato 0:2156833a74a8 755 distance_last = distance;
dkato 0:2156833a74a8 756 }
dkato 0:2156833a74a8 757 } else {
dkato 0:2156833a74a8 758 skip = true;
dkato 0:2156833a74a8 759 }
dkato 0:2156833a74a8 760 if (skip == false) {
dkato 0:2156833a74a8 761 touch_pos_last[0] = touch_pos[0];
dkato 0:2156833a74a8 762 touch_pos_last[1] = touch_pos[1];
dkato 0:2156833a74a8 763 touch_num_last = touch_num;
dkato 0:2156833a74a8 764 }
dkato 0:2156833a74a8 765 skip = false;
dkato 0:2156833a74a8 766 }
dkato 0:2156833a74a8 767 }
dkato 0:2156833a74a8 768 #endif
dkato 0:2156833a74a8 769
dkato 0:2156833a74a8 770 static void button_rise(void) {
dkato 0:2156833a74a8 771 int wk_disp_time;
dkato 0:2156833a74a8 772
dkato 0:2156833a74a8 773 wk_disp_time = disp_wait_time;
dkato 0:2156833a74a8 774 wk_disp_time += 1000;
dkato 0:2156833a74a8 775 if (wk_disp_time > 15000) {
dkato 0:2156833a74a8 776 wk_disp_time = 0;
dkato 0:2156833a74a8 777 }
dkato 0:2156833a74a8 778 disp_wait_time = wk_disp_time;
dkato 0:2156833a74a8 779 system_timer.reset();
dkato 0:2156833a74a8 780 system_timer.start();
dkato 0:2156833a74a8 781 mouse_info.disp_time = true;
dkato 0:2156833a74a8 782 if ((efect_info.event_req == EVENT_NONE) && (dissolve_seq == 0)) {
dkato 0:2156833a74a8 783 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 784 }
dkato 0:2156833a74a8 785 }
dkato 0:2156833a74a8 786
dkato 0:2156833a74a8 787 int main(void) {
dkato 0:2156833a74a8 788 errnum_t err;
dkato 0:2156833a74a8 789 Canvas2D_ContextConfigClass config;
dkato 0:2156833a74a8 790
dkato 0:2156833a74a8 791 /* Change the baud rate of the printf() */
dkato 0:2156833a74a8 792 pc.baud(921600);
dkato 0:2156833a74a8 793
dkato 0:2156833a74a8 794 /* Initialization of LCD */
dkato 0:2156833a74a8 795 Init_LCD_Display(); /* When using LCD, please call before than Init_Video(). */
dkato 0:2156833a74a8 796
dkato 0:2156833a74a8 797 memset(user_frame_buffer1, 0, sizeof(user_frame_buffer1));
dkato 0:2156833a74a8 798 memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2));
dkato 0:2156833a74a8 799 frame_buffer_info.buffer_address[0] = user_frame_buffer1;
dkato 0:2156833a74a8 800 frame_buffer_info.buffer_address[1] = user_frame_buffer2;
dkato 0:2156833a74a8 801 frame_buffer_info.buffer_count = 2;
dkato 0:2156833a74a8 802 frame_buffer_info.show_buffer_index = 0;
dkato 0:2156833a74a8 803 frame_buffer_info.draw_buffer_index = 0;
dkato 0:2156833a74a8 804 frame_buffer_info.width = LCD_PIXEL_WIDTH;
dkato 0:2156833a74a8 805 frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL;
dkato 0:2156833a74a8 806 frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL;
dkato 0:2156833a74a8 807 frame_buffer_info.height = LCD_PIXEL_HEIGHT;
dkato 0:2156833a74a8 808 frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565;
dkato 0:2156833a74a8 809
dkato 0:2156833a74a8 810 config.frame_buffer = &frame_buffer_info;
dkato 0:2156833a74a8 811 canvas2d = R_RGA_New_Canvas2D_ContextClass(config);
dkato 0:2156833a74a8 812 err = R_OSPL_GetErrNum();
dkato 0:2156833a74a8 813 if (err != 0) {
dkato 0:2156833a74a8 814 printf("Line %d, error %d\n", __LINE__, err);
dkato 0:2156833a74a8 815 mbed_die();
dkato 0:2156833a74a8 816 }
dkato 0:2156833a74a8 817
dkato 0:2156833a74a8 818 /* Start of LCD */
dkato 0:2156833a74a8 819 Start_LCD_Display(frame_buffer_info.buffer_address[0]);
dkato 0:2156833a74a8 820
dkato 0:2156833a74a8 821 #if (LCD_TYPE != 2)
dkato 0:2156833a74a8 822 /* Backlight on */
dkato 0:2156833a74a8 823 Thread::wait(200);
dkato 0:2156833a74a8 824 lcd_cntrst.write(1.0);
dkato 0:2156833a74a8 825 #endif
dkato 0:2156833a74a8 826
dkato 3:fdd3f557d2df 827 mouseTask.start(callback(mouse_task));
dkato 0:2156833a74a8 828 #ifdef TouckKey_LCD_shield
dkato 3:fdd3f557d2df 829 touchTask.start(callback(touch_task));
dkato 0:2156833a74a8 830 #endif
dkato 0:2156833a74a8 831 button.rise(&button_rise);
dkato 0:2156833a74a8 832
dkato 3:fdd3f557d2df 833 FATFileSystem fs(MOUNT_NAME);
dkato 3:fdd3f557d2df 834 SDBlockDevice_GR_PEACH sd;
dkato 3:fdd3f557d2df 835 USBHostMSD usb;
dkato 3:fdd3f557d2df 836 int storage_type = 0;
dkato 3:fdd3f557d2df 837 int next_storage_type = 0;
dkato 0:2156833a74a8 838 int wait_time = 0;
dkato 0:2156833a74a8 839 uint8_t * temp_buf[2];
dkato 0:2156833a74a8 840 bool touch_key_in = false;
dkato 0:2156833a74a8 841 int direction;
dkato 0:2156833a74a8 842 int i;
dkato 0:2156833a74a8 843 int wk_event_req;
dkato 0:2156833a74a8 844 int type;
dkato 0:2156833a74a8 845 int wk_abs_x_pos;
dkato 0:2156833a74a8 846
dkato 0:2156833a74a8 847 temp_buf[0] = JpegBuffer;
dkato 0:2156833a74a8 848 temp_buf[1] = new uint8_t[MAX_JPEG_SIZE];
dkato 0:2156833a74a8 849 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 850 efect_info.p_pic_now = (uint8_t *)Renesas_logo_File;
dkato 0:2156833a74a8 851 efect_info.p_pic_next = NULL;
dkato 0:2156833a74a8 852 efect_info.magnification = 1.0f;
dkato 0:2156833a74a8 853 efect_info.swipe_end_move = 0;
dkato 0:2156833a74a8 854 efect_info.drow_pos_x = 0;
dkato 0:2156833a74a8 855 efect_info.drow_pos_y = 0;
dkato 0:2156833a74a8 856 efect_info.scale_end_move_x = 0;
dkato 0:2156833a74a8 857 efect_info.scale_end_move_y = 0;
dkato 0:2156833a74a8 858 efect_info.min_x = 0;
dkato 0:2156833a74a8 859 efect_info.min_y = 0;
dkato 0:2156833a74a8 860 efect_info.scroll = false;
dkato 0:2156833a74a8 861 zoom_func(0, 0, 0, 0, 1.0f);
dkato 0:2156833a74a8 862
dkato 0:2156833a74a8 863 while (1) {
dkato 3:fdd3f557d2df 864 if (storage_type == 1) {
dkato 3:fdd3f557d2df 865 if (!sd.connected()) {
dkato 3:fdd3f557d2df 866 fs.unmount();
dkato 3:fdd3f557d2df 867 next_storage_type = 0;
dkato 3:fdd3f557d2df 868 }
dkato 3:fdd3f557d2df 869 }
dkato 3:fdd3f557d2df 870 if (storage_type == 2) {
dkato 3:fdd3f557d2df 871 if (!usb.connected()) {
dkato 3:fdd3f557d2df 872 fs.unmount();
dkato 3:fdd3f557d2df 873 next_storage_type = 0;
dkato 3:fdd3f557d2df 874 }
dkato 3:fdd3f557d2df 875 }
dkato 3:fdd3f557d2df 876 if (storage_type == 0) {
dkato 3:fdd3f557d2df 877 if (sd.connect()) {
dkato 3:fdd3f557d2df 878 next_storage_type = 1; // SD
dkato 3:fdd3f557d2df 879 fs.mount(&sd);
dkato 3:fdd3f557d2df 880 } else if (usb.connect()) {
dkato 3:fdd3f557d2df 881 next_storage_type = 2; // USB
dkato 3:fdd3f557d2df 882 fs.mount(&usb);
dkato 0:2156833a74a8 883 } else {
dkato 3:fdd3f557d2df 884 // do nothing
dkato 3:fdd3f557d2df 885 }
dkato 3:fdd3f557d2df 886 }
dkato 3:fdd3f557d2df 887 if (next_storage_type != storage_type) {
dkato 3:fdd3f557d2df 888 if (next_storage_type == 0) {
dkato 3:fdd3f557d2df 889 storage_mode = false;
dkato 3:fdd3f557d2df 890 total_file_num = ROM_PIC_NUM;
dkato 3:fdd3f557d2df 891 file_id_now = 0xffffffff;
dkato 3:fdd3f557d2df 892 file_id_next = 0xffffffff;
dkato 3:fdd3f557d2df 893 efect_info.p_pic_now = (uint8_t *)Renesas_logo_File;
dkato 3:fdd3f557d2df 894 efect_info.p_pic_next = NULL;
dkato 3:fdd3f557d2df 895 zoom_func(0, 0, 0, 0, 1.0f);
dkato 3:fdd3f557d2df 896 efect_info.event_req = EVENT_DISP;
dkato 3:fdd3f557d2df 897 } else {
dkato 0:2156833a74a8 898 storage_mode = true;
dkato 0:2156833a74a8 899 scan_foler.scan("/"MOUNT_NAME, extension_tbl);
dkato 0:2156833a74a8 900 total_file_num = scan_foler.getTotalFile();
dkato 0:2156833a74a8 901 file_id_now = 0;
dkato 0:2156833a74a8 902 file_id_next = 0xffffffff;
dkato 0:2156833a74a8 903 efect_info.p_pic_now = temp_buf[0];
dkato 0:2156833a74a8 904 efect_info.p_pic_next = temp_buf[1];
dkato 0:2156833a74a8 905 read_new_file(&efect_info.p_pic_now, file_id_now);
dkato 0:2156833a74a8 906 zoom_func(0, 0, 0, 0, 1.0f);
dkato 0:2156833a74a8 907 efect_info.event_req = EVENT_DISP;
dkato 0:2156833a74a8 908 }
dkato 3:fdd3f557d2df 909 storage_type = next_storage_type;
dkato 0:2156833a74a8 910 }
dkato 0:2156833a74a8 911
dkato 0:2156833a74a8 912 wk_event_req = efect_info.event_req;
dkato 0:2156833a74a8 913 efect_info.event_req = EVENT_NONE;
dkato 0:2156833a74a8 914
dkato 0:2156833a74a8 915 if (wk_event_req != EVENT_NONE) {
dkato 0:2156833a74a8 916 dissolve_seq = 0;
dkato 0:2156833a74a8 917 }
dkato 0:2156833a74a8 918
dkato 0:2156833a74a8 919 switch (wk_event_req) {
dkato 0:2156833a74a8 920 case EVENT_NEXT:
dkato 0:2156833a74a8 921 case EVENT_PREV:
dkato 0:2156833a74a8 922 zoom_func(0, 0, 0, 0, 1.0f);
dkato 0:2156833a74a8 923 if (wk_event_req == EVENT_NEXT) {
dkato 0:2156833a74a8 924 direction = SCROLL_DIRECTION_NEXT;
dkato 0:2156833a74a8 925 read_next_file();
dkato 0:2156833a74a8 926 } else {
dkato 0:2156833a74a8 927 direction = SCROLL_DIRECTION_PREV;
dkato 0:2156833a74a8 928 read_prev_file();
dkato 0:2156833a74a8 929 }
dkato 0:2156833a74a8 930 for (i = 1; i <= SCROLL_STEP_NUM; i++) {
dkato 0:2156833a74a8 931 draw_image_scroll(&frame_buffer_info,
dkato 0:2156833a74a8 932 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 933 (const graphics_image_t*)efect_info.p_pic_next,
dkato 0:2156833a74a8 934 (float32_t)i / (float32_t)SCROLL_STEP_NUM, direction);
dkato 0:2156833a74a8 935 }
dkato 0:2156833a74a8 936 swap_file_buff();
dkato 0:2156833a74a8 937 break;
dkato 0:2156833a74a8 938 case EVENT_MOVE:
dkato 0:2156833a74a8 939 if ((efect_info.x_move * SCROLL_DIRECTION) >= 0) {
dkato 0:2156833a74a8 940 direction = SCROLL_DIRECTION_NEXT;
dkato 0:2156833a74a8 941 read_next_file();
dkato 0:2156833a74a8 942 } else {
dkato 0:2156833a74a8 943 direction = SCROLL_DIRECTION_PREV;
dkato 0:2156833a74a8 944 read_prev_file();
dkato 0:2156833a74a8 945 }
dkato 0:2156833a74a8 946 draw_image_scroll(&frame_buffer_info,
dkato 0:2156833a74a8 947 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 948 (const graphics_image_t*)efect_info.p_pic_next,
dkato 0:2156833a74a8 949 (float32_t)abs(efect_info.x_move) / (float32_t)LCD_PIXEL_WIDTH, direction);
dkato 0:2156833a74a8 950 break;
dkato 0:2156833a74a8 951 case EVENT_MOVE_END:
dkato 0:2156833a74a8 952 type = 0;
dkato 0:2156833a74a8 953 if ((efect_info.x_move * SCROLL_DIRECTION) >= 0) {
dkato 0:2156833a74a8 954 direction = SCROLL_DIRECTION_NEXT;
dkato 0:2156833a74a8 955 read_next_file();
dkato 0:2156833a74a8 956 } else {
dkato 0:2156833a74a8 957 direction = SCROLL_DIRECTION_PREV;
dkato 0:2156833a74a8 958 read_prev_file();
dkato 0:2156833a74a8 959 }
dkato 0:2156833a74a8 960
dkato 0:2156833a74a8 961 wk_abs_x_pos = abs(efect_info.x_move);
dkato 0:2156833a74a8 962 if (abs(efect_info.swipe_end_move) > 10) {
dkato 0:2156833a74a8 963 if ((efect_info.swipe_end_move * SCROLL_DIRECTION) >= 0) {
dkato 0:2156833a74a8 964 if (direction != SCROLL_DIRECTION_NEXT) {
dkato 0:2156833a74a8 965 type = 1;
dkato 0:2156833a74a8 966 }
dkato 0:2156833a74a8 967 } else {
dkato 0:2156833a74a8 968 if (direction != SCROLL_DIRECTION_PREV) {
dkato 0:2156833a74a8 969 type = 1;
dkato 0:2156833a74a8 970 }
dkato 0:2156833a74a8 971 }
dkato 0:2156833a74a8 972 } else {
dkato 0:2156833a74a8 973 if (wk_abs_x_pos < (LCD_PIXEL_WIDTH / 2)) {
dkato 0:2156833a74a8 974 type = 1;
dkato 0:2156833a74a8 975 }
dkato 0:2156833a74a8 976 }
dkato 0:2156833a74a8 977
dkato 0:2156833a74a8 978 if (type == 0) {
dkato 0:2156833a74a8 979 while (wk_abs_x_pos < LCD_PIXEL_WIDTH) {
dkato 0:2156833a74a8 980 wk_abs_x_pos += (LCD_PIXEL_WIDTH / SCROLL_STEP_NUM);
dkato 0:2156833a74a8 981 if (wk_abs_x_pos > LCD_PIXEL_WIDTH) {
dkato 0:2156833a74a8 982 wk_abs_x_pos = LCD_PIXEL_WIDTH;
dkato 0:2156833a74a8 983 }
dkato 0:2156833a74a8 984 draw_image_scroll(&frame_buffer_info,
dkato 0:2156833a74a8 985 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 986 (const graphics_image_t*)efect_info.p_pic_next,
dkato 0:2156833a74a8 987 (float32_t)wk_abs_x_pos / (float32_t)LCD_PIXEL_WIDTH, direction);
dkato 0:2156833a74a8 988 }
dkato 0:2156833a74a8 989 swap_file_buff();
dkato 0:2156833a74a8 990 } else {
dkato 0:2156833a74a8 991 while (wk_abs_x_pos > 0) {
dkato 0:2156833a74a8 992 wk_abs_x_pos -= (LCD_PIXEL_WIDTH / SCROLL_STEP_NUM);
dkato 0:2156833a74a8 993 if (wk_abs_x_pos < 0) {
dkato 0:2156833a74a8 994 wk_abs_x_pos = 0;
dkato 0:2156833a74a8 995 }
dkato 0:2156833a74a8 996 draw_image_scroll(&frame_buffer_info,
dkato 0:2156833a74a8 997 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 998 (const graphics_image_t*)efect_info.p_pic_next,
dkato 0:2156833a74a8 999 (float32_t)wk_abs_x_pos / (float32_t)LCD_PIXEL_WIDTH, direction);
dkato 0:2156833a74a8 1000 }
dkato 0:2156833a74a8 1001 }
dkato 0:2156833a74a8 1002 efect_info.x_move = 0;
dkato 0:2156833a74a8 1003 break;
dkato 0:2156833a74a8 1004 case EVENT_NONE:
dkato 0:2156833a74a8 1005 case EVENT_DISP:
dkato 0:2156833a74a8 1006 default:
dkato 0:2156833a74a8 1007 if ((efect_info.scale_end_move_x != 0) || (efect_info.scale_end_move_y != 0) || (wk_event_req == EVENT_DISP)) {
dkato 0:2156833a74a8 1008 if ((efect_info.scale_end_move_x != 0) || (efect_info.scale_end_move_y != 0)) {
dkato 0:2156833a74a8 1009 efect_info.scale_end_move_x *= 0.8f;
dkato 0:2156833a74a8 1010 efect_info.scale_end_move_y *= 0.8f;
dkato 0:2156833a74a8 1011 zoom_scroll(efect_info.scale_end_move_x, efect_info.scale_end_move_y);
dkato 0:2156833a74a8 1012 if (abs(efect_info.scale_end_move_x) < 5) {
dkato 0:2156833a74a8 1013 efect_info.scale_end_move_x = 0;
dkato 0:2156833a74a8 1014 }
dkato 0:2156833a74a8 1015 if (abs(efect_info.scale_end_move_y) < 5) {
dkato 0:2156833a74a8 1016 efect_info.scale_end_move_y = 0;
dkato 0:2156833a74a8 1017 }
dkato 0:2156833a74a8 1018 }
dkato 0:2156833a74a8 1019 draw_image(&frame_buffer_info,
dkato 0:2156833a74a8 1020 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 1021 efect_info.drow_pos_x,
dkato 0:2156833a74a8 1022 efect_info.drow_pos_y,
dkato 0:2156833a74a8 1023 efect_info.magnification);
dkato 0:2156833a74a8 1024 wait_time = 0;
dkato 0:2156833a74a8 1025 } else if (((file_id_now == 0xffffffff) && (wait_time >= 3000))
dkato 0:2156833a74a8 1026 || ((disp_wait_time != 0) && (wait_time >= disp_wait_time) && (mouse_info.disp_pos == false))) {
dkato 0:2156833a74a8 1027 efect_info.magnification = 1.0f;
dkato 0:2156833a74a8 1028 read_next_file();
dkato 0:2156833a74a8 1029 dissolve_seq = 1;
dkato 0:2156833a74a8 1030 } else {
dkato 0:2156833a74a8 1031 /* do nothing */
dkato 0:2156833a74a8 1032 }
dkato 0:2156833a74a8 1033 if (dissolve_seq != 0) {
dkato 0:2156833a74a8 1034 draw_image_dissolve(&frame_buffer_info,
dkato 0:2156833a74a8 1035 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 1036 (const graphics_image_t*)efect_info.p_pic_next,
dkato 0:2156833a74a8 1037 (float32_t)dissolve_seq / (float32_t)DISSOLVE_STEP_NUM);
dkato 0:2156833a74a8 1038 if (dissolve_seq >= DISSOLVE_STEP_NUM) {
dkato 0:2156833a74a8 1039 dissolve_seq = 0;
dkato 0:2156833a74a8 1040 swap_file_buff();
dkato 0:2156833a74a8 1041 } else {
dkato 0:2156833a74a8 1042 dissolve_seq++;
dkato 0:2156833a74a8 1043 }
dkato 0:2156833a74a8 1044 wait_time = 0;
dkato 0:2156833a74a8 1045 }
dkato 0:2156833a74a8 1046 break;
dkato 0:2156833a74a8 1047 }
dkato 0:2156833a74a8 1048 if ((mouse_info.disp_time != false) && (system_timer.read_ms() > 1500)) {
dkato 0:2156833a74a8 1049 mouse_info.disp_time = false;
dkato 0:2156833a74a8 1050 if ((efect_info.event_req == EVENT_NONE) && (dissolve_seq == 0)) {
dkato 0:2156833a74a8 1051 draw_image(&frame_buffer_info,
dkato 0:2156833a74a8 1052 (const graphics_image_t*)efect_info.p_pic_now,
dkato 0:2156833a74a8 1053 efect_info.drow_pos_x,
dkato 0:2156833a74a8 1054 efect_info.drow_pos_y,
dkato 0:2156833a74a8 1055 efect_info.magnification);
dkato 0:2156833a74a8 1056 }
dkato 0:2156833a74a8 1057 }
dkato 0:2156833a74a8 1058 if ((wk_event_req != EVENT_NONE) || (touch_key_in != false) || (efect_info.magnification != 1.0f) || (dissolve_seq != 0)
dkato 0:2156833a74a8 1059 || (mouse_info.disp_pos != false) || (mouse_info.disp_time != false) || (efect_info.scroll != false)) {
dkato 0:2156833a74a8 1060 wait_time = 0;
dkato 0:2156833a74a8 1061 } else {
dkato 0:2156833a74a8 1062 Thread::wait(50);
dkato 0:2156833a74a8 1063 if (wait_time < 100000) {
dkato 0:2156833a74a8 1064 wait_time += 50;
dkato 0:2156833a74a8 1065 }
dkato 0:2156833a74a8 1066 }
dkato 0:2156833a74a8 1067 }
dkato 0:2156833a74a8 1068 }