テスト
DisplayApp.h@8:19305047debb, 2018-11-21 (annotated)
- Committer:
- yagyag
- Date:
- Wed Nov 21 02:26:17 2018 +0000
- Revision:
- 8:19305047debb
- Parent:
- 7:99022c278aa1
Display Lesson
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:13c1f522bbef | 1 | /**************************************************************************//** |
dkato | 0:13c1f522bbef | 2 | * @file DisplayApp.h |
dkato | 0:13c1f522bbef | 3 | * @brief DisplayApp API |
dkato | 0:13c1f522bbef | 4 | ******************************************************************************/ |
dkato | 0:13c1f522bbef | 5 | |
dkato | 0:13c1f522bbef | 6 | #ifndef DISPLAY_APP_H |
dkato | 0:13c1f522bbef | 7 | #define DISPLAY_APP_H |
dkato | 0:13c1f522bbef | 8 | |
dkato | 0:13c1f522bbef | 9 | #include "mbed.h" |
dkato | 0:13c1f522bbef | 10 | #include "rtos.h" |
dkato | 0:13c1f522bbef | 11 | #include "USBSerial.h" |
dkato | 0:13c1f522bbef | 12 | |
dkato | 0:13c1f522bbef | 13 | /** A class to communicate a DisplayApp |
dkato | 0:13c1f522bbef | 14 | * |
dkato | 0:13c1f522bbef | 15 | */ |
dkato | 0:13c1f522bbef | 16 | class DisplayApp { |
dkato | 0:13c1f522bbef | 17 | public: |
yagyag | 8:19305047debb | 18 | |
yagyag | 8:19305047debb | 19 | USBSerial PcApp; |
dkato | 0:13c1f522bbef | 20 | /** Touch position structure */ |
dkato | 0:13c1f522bbef | 21 | typedef struct { |
dkato | 0:13c1f522bbef | 22 | uint32_t x; /**< The position of the x-coordinate. */ |
dkato | 0:13c1f522bbef | 23 | uint32_t y; /**< The position of the y-coordinate. */ |
dkato | 0:13c1f522bbef | 24 | bool valid; /**< Whether a valid data.. */ |
dkato | 0:13c1f522bbef | 25 | } touch_pos_t; |
dkato | 0:13c1f522bbef | 26 | |
dkato | 0:13c1f522bbef | 27 | /** Constructor: Initializes DisplayApp. |
dkato | 0:13c1f522bbef | 28 | * |
dkato | 2:b7ffe5216cd7 | 29 | * @param tsk_pri Priority of the thread function. (default: osPriorityNormal). |
dkato | 2:b7ffe5216cd7 | 30 | * @param init_pri Priority of before the USB is connected. (default: osPriorityLow). |
dkato | 2:b7ffe5216cd7 | 31 | * @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). |
dkato | 0:13c1f522bbef | 32 | */ |
dkato | 4:3c46efbe6d21 | 33 | DisplayApp(osPriority tsk_pri = osPriorityNormal, uint32_t stack_size = DEFAULT_STACK_SIZE); |
dkato | 0:13c1f522bbef | 34 | |
dkato | 0:13c1f522bbef | 35 | /** Send RGB888 data |
dkato | 0:13c1f522bbef | 36 | * |
dkato | 0:13c1f522bbef | 37 | * @param buf data buffer address |
dkato | 0:13c1f522bbef | 38 | * @param pic_width picture width |
dkato | 0:13c1f522bbef | 39 | * @param pic_height picture height |
dkato | 0:13c1f522bbef | 40 | * @return send data size |
dkato | 0:13c1f522bbef | 41 | */ |
dkato | 0:13c1f522bbef | 42 | int SendRgb888(uint8_t * buf, uint32_t pic_width, uint32_t pic_height); |
dkato | 0:13c1f522bbef | 43 | |
dkato | 0:13c1f522bbef | 44 | /** Send JPEG data |
dkato | 0:13c1f522bbef | 45 | * |
dkato | 0:13c1f522bbef | 46 | * @param buf data buffer address |
dkato | 0:13c1f522bbef | 47 | * @param size data size |
dkato | 0:13c1f522bbef | 48 | * @return send data size |
dkato | 0:13c1f522bbef | 49 | */ |
dkato | 0:13c1f522bbef | 50 | int SendJpeg(uint8_t * buf, uint32_t size); |
dkato | 0:13c1f522bbef | 51 | |
dkato | 3:693902c86ca0 | 52 | /** Attach a function to call whenever a serial interrupt is generated |
dkato | 3:693902c86ca0 | 53 | * |
dkato | 3:693902c86ca0 | 54 | * @param func A pointer to a void function, or 0 to set as none |
dkato | 3:693902c86ca0 | 55 | */ |
dkato | 3:693902c86ca0 | 56 | void SetCallback(Callback<void()> func); |
dkato | 3:693902c86ca0 | 57 | |
dkato | 0:13c1f522bbef | 58 | /** Attach a function to call when touch panel int |
dkato | 0:13c1f522bbef | 59 | * |
dkato | 3:693902c86ca0 | 60 | * @param obj pointer to the object to call the member function on |
dkato | 3:693902c86ca0 | 61 | * @param method pointer to the member function to be called |
dkato | 0:13c1f522bbef | 62 | */ |
dkato | 3:693902c86ca0 | 63 | template<typename T> |
dkato | 3:693902c86ca0 | 64 | void SetCallback(T* obj, void (T::*method)()) { |
dkato | 3:693902c86ca0 | 65 | // Underlying call thread safe |
dkato | 3:693902c86ca0 | 66 | SetCallback(callback(obj, method)); |
dkato | 0:13c1f522bbef | 67 | } |
dkato | 3:693902c86ca0 | 68 | |
dkato | 0:13c1f522bbef | 69 | /** Attach a member function to call when touch panel int |
dkato | 0:13c1f522bbef | 70 | * |
dkato | 3:693902c86ca0 | 71 | * @param obj pointer to the object to call the member function on |
dkato | 3:693902c86ca0 | 72 | * @param method pointer to the member function to be called |
dkato | 0:13c1f522bbef | 73 | */ |
dkato | 0:13c1f522bbef | 74 | template<typename T> |
dkato | 3:693902c86ca0 | 75 | void SetCallback(T* obj, void (*method)(T*)) { |
dkato | 3:693902c86ca0 | 76 | // Underlying call thread safe |
dkato | 3:693902c86ca0 | 77 | SetCallback(callback(obj, method)); |
dkato | 0:13c1f522bbef | 78 | } |
dkato | 0:13c1f522bbef | 79 | /** Get the maximum number of simultaneous touches |
dkato | 0:13c1f522bbef | 80 | * |
dkato | 0:13c1f522bbef | 81 | * @return The maximum number of simultaneous touches. |
dkato | 0:13c1f522bbef | 82 | */ |
dkato | 0:13c1f522bbef | 83 | int GetMaxTouchNum(void); |
dkato | 0:13c1f522bbef | 84 | |
dkato | 0:13c1f522bbef | 85 | /** Get the coordinates |
dkato | 0:13c1f522bbef | 86 | * |
dkato | 0:13c1f522bbef | 87 | * @param touch_buff_num The number of structure p_touch. |
dkato | 0:13c1f522bbef | 88 | * @param p_touch Touch position information. |
dkato | 0:13c1f522bbef | 89 | * @return The number of touch points. |
dkato | 0:13c1f522bbef | 90 | */ |
dkato | 0:13c1f522bbef | 91 | int GetCoordinates(int touch_buff_num, touch_pos_t * p_touch); |
yagyag | 7:99022c278aa1 | 92 | |
yagyag | 7:99022c278aa1 | 93 | char Getgetc(); |
yagyag | 8:19305047debb | 94 | |
dkato | 0:13c1f522bbef | 95 | |
dkato | 0:13c1f522bbef | 96 | private: |
dkato | 0:13c1f522bbef | 97 | typedef enum { |
dkato | 0:13c1f522bbef | 98 | POS_SEQ_INIT, |
dkato | 0:13c1f522bbef | 99 | POS_SEQ_START, |
dkato | 0:13c1f522bbef | 100 | POS_SEQ_X, |
dkato | 0:13c1f522bbef | 101 | POS_SEQ_X_POS, |
dkato | 0:13c1f522bbef | 102 | POS_SEQ_X_M, |
dkato | 0:13c1f522bbef | 103 | POS_SEQ_C, |
dkato | 0:13c1f522bbef | 104 | POS_SEQ_Y, |
dkato | 0:13c1f522bbef | 105 | POS_SEQ_Y_POS, |
dkato | 0:13c1f522bbef | 106 | POS_SEQ_Y_M, |
dkato | 0:13c1f522bbef | 107 | POS_SEQ_END, |
dkato | 0:13c1f522bbef | 108 | } pos_seq_t; |
dkato | 0:13c1f522bbef | 109 | |
dkato | 0:13c1f522bbef | 110 | Thread displayThread; |
dkato | 0:13c1f522bbef | 111 | pos_seq_t pos_seq; |
dkato | 0:13c1f522bbef | 112 | int pos_x; |
dkato | 0:13c1f522bbef | 113 | int pos_y; |
dkato | 3:693902c86ca0 | 114 | Callback<void()> event; |
dkato | 0:13c1f522bbef | 115 | |
dkato | 0:13c1f522bbef | 116 | void touch_int_callback(void); |
dkato | 0:13c1f522bbef | 117 | void display_app_process(); |
dkato | 0:13c1f522bbef | 118 | void SendHeader(uint32_t size); |
dkato | 0:13c1f522bbef | 119 | void SendData(uint8_t * buf, uint32_t size); |
dkato | 0:13c1f522bbef | 120 | }; |
dkato | 0:13c1f522bbef | 121 | #endif |