Mbed Client sample for GR-LYCHEE where ZXing is incorporated.

Dependencies:   DisplayApp AsciiFont

Fork of GR-PEACH_mbed-os-client-ZXingSample by Renesas

Overview

This sample program shows how to use mbed Client together with ZXing which is an open-source, multi-format 1D/2D barcode image processing library. For more info on ZXing, please refer to https://github.com/zxing/zxing.

Required hardware

Application setup

  1. Select the connection type. For details, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Connection-type.
  2. Set the client credentials. For details, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Client-credentials.
  3. Change Wifi settings. For details, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Wifi-settings.

Building the example

To build this example:

  1. Import this example onto mbed Compiler.
  2. Configure the example in accordance with Application setup.
  3. Compile the example on mbed Compiler and download the resultant binary file.
  4. Plug the micro-USB cable into the OpenSDA port which lies on the next to the RESET button.
  5. Copy the binary previously downloaded to your PC to GR-LYCHEE to flash this example. When the copy is successfully completed, the board is ready to work.
  6. Press the RESET button on the board to run the example.
  7. For verification, please refer to the following wiki:
    https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Monitoring-the-application.

Application resources

This example exposes four resources listed below:

  1. 3202/0/5700. Decode result of barcode data input from camera (GET).
  2. 3201/0/5850. Blink function, blinks LED when executed (POST).
  3. 3201/0/5853. Blink pattern, used by the blink function to determine how to blink. In the format of 1000:500:1000:500:1000:500 (PUT).
  4. 3201/0/5855. Blink color, used by the blink function. Any of green, yellow, orange and red is acceptable (PUT).
Committer:
dkato
Date:
Tue Mar 28 11:02:34 2017 +0000
Revision:
2:6ec5c1c1d41c
Parent:
0:eb73febb2bba
Child:
4:076b3dd7c0e6
Memory-saving version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 0:eb73febb2bba 1
<> 0:eb73febb2bba 2 #include "mbed.h"
<> 0:eb73febb2bba 3 #include "rtos.h"
<> 0:eb73febb2bba 4 #include "DisplayBace.h"
<> 0:eb73febb2bba 5 #include "ImageReaderSource.h"
<> 0:eb73febb2bba 6
<> 0:eb73febb2bba 7 #define VIDEO_CVBS (0) /* Analog Video Signal */
<> 0:eb73febb2bba 8 #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */
<> 0:eb73febb2bba 9
<> 0:eb73febb2bba 10 /**** User Selection *********/
<> 0:eb73febb2bba 11 /** Camera setting **/
<> 0:eb73febb2bba 12 #define VIDEO_INPUT_METHOD (VIDEO_CMOS_CAMERA) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */
<> 0:eb73febb2bba 13 #define USE_VIDEO_CH (0) /* Select 0 or 1 If selecting VIDEO_CMOS_CAMERA, should be 0.) */
<> 0:eb73febb2bba 14 #define VIDEO_PAL (0) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
<> 0:eb73febb2bba 15 /** LCD setting **/
<> 0:eb73febb2bba 16 #define LCD_ONOFF (1) /* Select 0(without LCD) or 1(with LCD) */
<> 0:eb73febb2bba 17 #define LCD_TYPE (0) /* Select 0(4.3inch) or 1(7.1inch) */
dkato 2:6ec5c1c1d41c 18 /** JPEG out setting **/
dkato 2:6ec5c1c1d41c 19 #define JPEG_SEND (0) /* Select 0(JPEG images are not output to PC) or 1(JPEG images are output to PC on USB(CDC) for focusing the camera) */
dkato 2:6ec5c1c1d41c 20 /** Decode hints **/
dkato 2:6ec5c1c1d41c 21 #define DECODE_HINTS (DecodeHints::ONED_HINT | DecodeHints::QR_CODE_HINT | DecodeHints::DATA_MATRIX_HINT | DecodeHints::AZTEC_HINT)
<> 0:eb73febb2bba 22 /*****************************/
<> 0:eb73febb2bba 23
<> 0:eb73febb2bba 24 #if LCD_ONOFF
<> 0:eb73febb2bba 25 /** LCD shield config **/
<> 0:eb73febb2bba 26 #if (LCD_TYPE == 0)
<> 0:eb73febb2bba 27 #include "LCD_shield_config_4_3inch.h"
<> 0:eb73febb2bba 28 #else
<> 0:eb73febb2bba 29 #include "LCD_shield_config_7_1inch.h"
<> 0:eb73febb2bba 30 #endif
dkato 2:6ec5c1c1d41c 31 #include "AsciiFont.h"
dkato 2:6ec5c1c1d41c 32 #endif
dkato 2:6ec5c1c1d41c 33
dkato 2:6ec5c1c1d41c 34 #ifdef JPEG_SEND
dkato 2:6ec5c1c1d41c 35 #include "JPEG_Converter.h"
dkato 2:6ec5c1c1d41c 36 #include "DisplayApp.h"
<> 0:eb73febb2bba 37 #endif
<> 0:eb73febb2bba 38
<> 0:eb73febb2bba 39 /** Video and Grapics (GRAPHICS_LAYER_0) parameter **/
<> 0:eb73febb2bba 40 /* video input */
<> 0:eb73febb2bba 41 #if USE_VIDEO_CH == (0)
<> 0:eb73febb2bba 42 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0)
<> 0:eb73febb2bba 43 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD)
<> 0:eb73febb2bba 44 #else
<> 0:eb73febb2bba 45 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_1)
<> 0:eb73febb2bba 46 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S1_VFIELD)
<> 0:eb73febb2bba 47 #endif
<> 0:eb73febb2bba 48
<> 0:eb73febb2bba 49 /* NTSC or PAL */
<> 0:eb73febb2bba 50 #if VIDEO_PAL == 0
<> 0:eb73febb2bba 51 #define COL_SYS (DisplayBase::COL_SYS_NTSC_358)
<> 0:eb73febb2bba 52 #else
<> 0:eb73febb2bba 53 #define COL_SYS (DisplayBase::COL_SYS_PAL_443)
<> 0:eb73febb2bba 54 #endif
<> 0:eb73febb2bba 55
<> 0:eb73febb2bba 56 /* Video input */
dkato 2:6ec5c1c1d41c 57 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_YCBCR422)
dkato 2:6ec5c1c1d41c 58 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_YCBCR422)
dkato 2:6ec5c1c1d41c 59 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_16BIT)
dkato 2:6ec5c1c1d41c 60 #define FRAME_BUFFER_BYTE_PER_PIXEL (2u)
dkato 2:6ec5c1c1d41c 61
dkato 2:6ec5c1c1d41c 62 #if VIDEO_INPUT_METHOD == VIDEO_CVBS
dkato 2:6ec5c1c1d41c 63 #define WAIT_VFIELD_CNT (2)
dkato 2:6ec5c1c1d41c 64 #else
dkato 2:6ec5c1c1d41c 65 #define WAIT_VFIELD_CNT (1)
dkato 2:6ec5c1c1d41c 66 #endif
<> 0:eb73febb2bba 67
<> 0:eb73febb2bba 68 /* The size of the video input */
<> 0:eb73febb2bba 69 #if ((LCD_ONOFF) && (LCD_TYPE == 0))
dkato 2:6ec5c1c1d41c 70 #define VIDEO_PIXEL_HW LCD_PIXEL_WIDTH
dkato 2:6ec5c1c1d41c 71 #define VIDEO_PIXEL_VW LCD_PIXEL_HEIGHT
<> 0:eb73febb2bba 72 #else
dkato 2:6ec5c1c1d41c 73 #define VIDEO_PIXEL_HW (640) /* VGA */
dkato 2:6ec5c1c1d41c 74 #define VIDEO_PIXEL_VW (480) /* VGA */
<> 0:eb73febb2bba 75 #endif
<> 0:eb73febb2bba 76
<> 0:eb73febb2bba 77 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
<> 0:eb73febb2bba 78 in accordance with the frame buffer burst transfer mode. */
<> 0:eb73febb2bba 79 /* FRAME BUFFER Parameter GRAPHICS_LAYER_0 */
dkato 2:6ec5c1c1d41c 80 #define FRAME_BUFFER_STRIDE (((VIDEO_PIXEL_HW * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
<> 0:eb73febb2bba 81
<> 0:eb73febb2bba 82 static DisplayBase Display;
<> 0:eb73febb2bba 83 static Timer decode_timer;
<> 0:eb73febb2bba 84
<> 0:eb73febb2bba 85 /* 32 bytes aligned */
dkato 2:6ec5c1c1d41c 86 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * VIDEO_PIXEL_VW]__attribute((section("NC_BSS"),aligned(32)));
dkato 2:6ec5c1c1d41c 87
<> 0:eb73febb2bba 88 static volatile int32_t vfield_count = 0;
<> 0:eb73febb2bba 89 static bool graphics_init_end = false;
<> 0:eb73febb2bba 90 static int decode_wait_time = 0;
<> 0:eb73febb2bba 91 static void (*p_callback_func)(char * addr, int size);
<> 0:eb73febb2bba 92
<> 0:eb73febb2bba 93 #if LCD_ONOFF
<> 0:eb73febb2bba 94 /****** LCD ******/
dkato 2:6ec5c1c1d41c 95 static DigitalOut lcd_pwon(P7_15);
dkato 2:6ec5c1c1d41c 96 static DigitalOut lcd_blon(P8_1);
dkato 2:6ec5c1c1d41c 97 static PwmOut lcd_cntrst(P8_15);
dkato 2:6ec5c1c1d41c 98
<> 0:eb73febb2bba 99 static void Init_LCD_Display(void) {
<> 0:eb73febb2bba 100 DisplayBase::graphics_error_t error;
<> 0:eb73febb2bba 101 DisplayBase::lcd_config_t lcd_config;
<> 0:eb73febb2bba 102 PinName lvds_pin[8] = {
<> 0:eb73febb2bba 103 /* data pin */
<> 0:eb73febb2bba 104 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0
<> 0:eb73febb2bba 105 };
<> 0:eb73febb2bba 106
<> 0:eb73febb2bba 107 lcd_pwon = 0;
<> 0:eb73febb2bba 108 lcd_blon = 0;
<> 0:eb73febb2bba 109 Thread::wait(100);
<> 0:eb73febb2bba 110 lcd_pwon = 1;
<> 0:eb73febb2bba 111 lcd_blon = 1;
<> 0:eb73febb2bba 112
<> 0:eb73febb2bba 113 Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
<> 0:eb73febb2bba 114
<> 0:eb73febb2bba 115 /* Graphics initialization process */
<> 0:eb73febb2bba 116 lcd_config = LcdCfgTbl_LCD_shield;
<> 0:eb73febb2bba 117 error = Display.Graphics_init(&lcd_config);
<> 0:eb73febb2bba 118 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 119 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 120 mbed_die();
<> 0:eb73febb2bba 121 }
<> 0:eb73febb2bba 122 graphics_init_end = true;
<> 0:eb73febb2bba 123 }
<> 0:eb73febb2bba 124
<> 0:eb73febb2bba 125 static void Start_LCD_Display(uint8_t * p_buf) {
<> 0:eb73febb2bba 126 DisplayBase::rect_t rect;
<> 0:eb73febb2bba 127
<> 0:eb73febb2bba 128 rect.vs = 0;
<> 0:eb73febb2bba 129 rect.vw = VIDEO_PIXEL_VW;
<> 0:eb73febb2bba 130 rect.hs = 0;
<> 0:eb73febb2bba 131 rect.hw = VIDEO_PIXEL_HW;
<> 0:eb73febb2bba 132 Display.Graphics_Read_Setting(
<> 0:eb73febb2bba 133 DisplayBase::GRAPHICS_LAYER_0,
<> 0:eb73febb2bba 134 (void *)p_buf,
<> 0:eb73febb2bba 135 FRAME_BUFFER_STRIDE,
<> 0:eb73febb2bba 136 GRAPHICS_FORMAT,
<> 0:eb73febb2bba 137 WR_RD_WRSWA,
<> 0:eb73febb2bba 138 &rect
<> 0:eb73febb2bba 139 );
<> 0:eb73febb2bba 140 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
<> 0:eb73febb2bba 141 }
dkato 2:6ec5c1c1d41c 142
dkato 2:6ec5c1c1d41c 143 #define VIDEO_PIXEL_HW_STR (VIDEO_PIXEL_HW - 64)
dkato 2:6ec5c1c1d41c 144 #define VIDEO_PIXEL_VW_STR (VIDEO_PIXEL_VW - 64)
dkato 2:6ec5c1c1d41c 145 #define FRAME_BUFFER_BYTE_PER_PIXEL_STR (2u)
dkato 2:6ec5c1c1d41c 146 #define FRAME_BUFFER_STRIDE_STR (((VIDEO_PIXEL_HW_STR * FRAME_BUFFER_BYTE_PER_PIXEL_STR) + 31u) & ~31u)
dkato 2:6ec5c1c1d41c 147
dkato 2:6ec5c1c1d41c 148 static uint8_t user_frame_buffer_string[FRAME_BUFFER_STRIDE_STR * VIDEO_PIXEL_VW_STR]__attribute((section("NC_BSS"),aligned(32)));
dkato 2:6ec5c1c1d41c 149 static AsciiFont ascii_font(user_frame_buffer_string, VIDEO_PIXEL_HW_STR, VIDEO_PIXEL_VW_STR, FRAME_BUFFER_STRIDE_STR, FRAME_BUFFER_BYTE_PER_PIXEL_STR);
dkato 2:6ec5c1c1d41c 150 static bool string_draw;
dkato 2:6ec5c1c1d41c 151
dkato 2:6ec5c1c1d41c 152 static void decode_string_init(void) {
dkato 2:6ec5c1c1d41c 153 DisplayBase::rect_t rect;
dkato 2:6ec5c1c1d41c 154
dkato 2:6ec5c1c1d41c 155 /* The layer by which the touch panel location is drawn */
dkato 2:6ec5c1c1d41c 156 ascii_font.Erase(0x00000000); /* rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red */
dkato 2:6ec5c1c1d41c 157 rect.vs = 32;
dkato 2:6ec5c1c1d41c 158 rect.vw = VIDEO_PIXEL_VW_STR;
dkato 2:6ec5c1c1d41c 159 rect.hs = 32;
dkato 2:6ec5c1c1d41c 160 rect.hw = VIDEO_PIXEL_HW_STR;
dkato 2:6ec5c1c1d41c 161 Display.Graphics_Read_Setting(
dkato 2:6ec5c1c1d41c 162 DisplayBase::GRAPHICS_LAYER_1,
dkato 2:6ec5c1c1d41c 163 (void *)user_frame_buffer_string,
dkato 2:6ec5c1c1d41c 164 FRAME_BUFFER_STRIDE_STR,
dkato 2:6ec5c1c1d41c 165 DisplayBase::GRAPHICS_FORMAT_ARGB4444,
dkato 2:6ec5c1c1d41c 166 DisplayBase::WR_RD_WRSWA_32_16BIT,
dkato 2:6ec5c1c1d41c 167 &rect
dkato 2:6ec5c1c1d41c 168 );
dkato 2:6ec5c1c1d41c 169 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_1);
dkato 2:6ec5c1c1d41c 170 string_draw = false;
dkato 2:6ec5c1c1d41c 171 }
dkato 2:6ec5c1c1d41c 172
dkato 2:6ec5c1c1d41c 173 static void decode_string_disp(char ** decode_str) {
dkato 2:6ec5c1c1d41c 174 if ((decode_str != NULL) && (*decode_str != NULL)) {
dkato 2:6ec5c1c1d41c 175 /* Drow string */
dkato 2:6ec5c1c1d41c 176 ascii_font.Erase(0x00000090); /* rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red */
dkato 2:6ec5c1c1d41c 177 int rest_size = strlen(*decode_str);
dkato 2:6ec5c1c1d41c 178 int draw_idx = 0;
dkato 2:6ec5c1c1d41c 179 int draw_size;
dkato 2:6ec5c1c1d41c 180 int draw_line = 0;
dkato 2:6ec5c1c1d41c 181
dkato 2:6ec5c1c1d41c 182 while (rest_size > 0) {
dkato 2:6ec5c1c1d41c 183 draw_size = ascii_font.DrawStr(*decode_str + draw_idx, 6, 5 + (18 * draw_line), 0x0000ffff, 2);
dkato 2:6ec5c1c1d41c 184 if (draw_size <= 0) {
dkato 2:6ec5c1c1d41c 185 break;
dkato 2:6ec5c1c1d41c 186 }
dkato 2:6ec5c1c1d41c 187 rest_size -= draw_size;
dkato 2:6ec5c1c1d41c 188 draw_idx += draw_size;
dkato 2:6ec5c1c1d41c 189 draw_line++;
dkato 2:6ec5c1c1d41c 190 }
dkato 2:6ec5c1c1d41c 191 string_draw = true;
dkato 2:6ec5c1c1d41c 192 } else {
dkato 2:6ec5c1c1d41c 193 if (string_draw != false) {
dkato 2:6ec5c1c1d41c 194 /* Clear string */
dkato 2:6ec5c1c1d41c 195 ascii_font.Erase(0x00000000); /* rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red */
dkato 2:6ec5c1c1d41c 196 string_draw = false;
dkato 2:6ec5c1c1d41c 197 }
dkato 2:6ec5c1c1d41c 198 }
dkato 2:6ec5c1c1d41c 199 }
dkato 2:6ec5c1c1d41c 200 #endif // LCD_ONOFF
dkato 2:6ec5c1c1d41c 201
dkato 2:6ec5c1c1d41c 202 #ifdef JPEG_SEND
dkato 2:6ec5c1c1d41c 203 /****** Jpeg Send ******/
dkato 2:6ec5c1c1d41c 204 #define JPEG_ENC_MAX_SIZE (1024 * 63)
dkato 2:6ec5c1c1d41c 205 #define JPEG_SIGNAL_CAP_COMP (1L)
dkato 2:6ec5c1c1d41c 206
dkato 2:6ec5c1c1d41c 207 #define JPEGSEND_STB (0)
dkato 2:6ec5c1c1d41c 208 #define JPEGSEND_ENC (1)
dkato 2:6ec5c1c1d41c 209
dkato 2:6ec5c1c1d41c 210 static Thread jpegsendTask(osPriorityAboveNormal, 2048);
dkato 2:6ec5c1c1d41c 211 static DisplayApp display_app;
dkato 2:6ec5c1c1d41c 212 static uint8_t JpegBuffer[JPEG_ENC_MAX_SIZE]__attribute((section("NC_BSS"),aligned(8))); //8 bytes aligned!;
dkato 2:6ec5c1c1d41c 213 volatile static uint32_t jpegsend_status = JPEGSEND_STB;
dkato 2:6ec5c1c1d41c 214
dkato 2:6ec5c1c1d41c 215 static void jpegsendTask_main( void ) {
dkato 2:6ec5c1c1d41c 216 JPEG_Converter Jcu;
dkato 2:6ec5c1c1d41c 217 size_t jcu_encode_size;
dkato 2:6ec5c1c1d41c 218
dkato 2:6ec5c1c1d41c 219 while (1) {
dkato 2:6ec5c1c1d41c 220 Thread::signal_wait(JPEG_SIGNAL_CAP_COMP, 80);
dkato 2:6ec5c1c1d41c 221 jpegsend_status = JPEGSEND_ENC;
dkato 2:6ec5c1c1d41c 222
dkato 2:6ec5c1c1d41c 223 /* JPEG Enc Start */
dkato 2:6ec5c1c1d41c 224 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
dkato 2:6ec5c1c1d41c 225 JPEG_Converter::encode_options_t encode_options;
dkato 2:6ec5c1c1d41c 226 bitmap_buff_info.width = VIDEO_PIXEL_HW;
dkato 2:6ec5c1c1d41c 227 bitmap_buff_info.height = VIDEO_PIXEL_VW;
dkato 2:6ec5c1c1d41c 228 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422;
dkato 2:6ec5c1c1d41c 229 bitmap_buff_info.buffer_address = (void *)user_frame_buffer0;
dkato 2:6ec5c1c1d41c 230 encode_options.encode_buff_size = sizeof(JpegBuffer);
dkato 2:6ec5c1c1d41c 231 encode_options.p_EncodeCallBackFunc = NULL;
dkato 2:6ec5c1c1d41c 232 encode_options.input_swapsetting = JPEG_Converter::WR_RD_WRSWA_16_8BIT;
dkato 2:6ec5c1c1d41c 233 jcu_encode_size = 0;
dkato 2:6ec5c1c1d41c 234 if (Jcu.encode(&bitmap_buff_info, JpegBuffer, &jcu_encode_size, &encode_options) != JPEG_Converter::JPEG_CONV_OK) {
dkato 2:6ec5c1c1d41c 235 jcu_encode_size = 0;
dkato 2:6ec5c1c1d41c 236 }
dkato 2:6ec5c1c1d41c 237
dkato 2:6ec5c1c1d41c 238 /* JPEG Data Send */
dkato 2:6ec5c1c1d41c 239 if ((jcu_encode_size > 256) && (jcu_encode_size < JPEG_ENC_MAX_SIZE)) {
dkato 2:6ec5c1c1d41c 240 display_app.SendJpeg(JpegBuffer, jcu_encode_size);
dkato 2:6ec5c1c1d41c 241 }
dkato 2:6ec5c1c1d41c 242 jpegsend_status = JPEGSEND_STB;
dkato 2:6ec5c1c1d41c 243 }
dkato 2:6ec5c1c1d41c 244 }
dkato 2:6ec5c1c1d41c 245
dkato 2:6ec5c1c1d41c 246 static void jpegsendTask_init( void ) {
dkato 2:6ec5c1c1d41c 247 jpegsendTask.start(jpegsendTask_main);
dkato 2:6ec5c1c1d41c 248 }
dkato 2:6ec5c1c1d41c 249
dkato 2:6ec5c1c1d41c 250 static void jpegsend_cap_comp( void ) {
dkato 2:6ec5c1c1d41c 251 if (jpegsend_status == JPEGSEND_STB) {
dkato 2:6ec5c1c1d41c 252 jpegsendTask.signal_set(JPEG_SIGNAL_CAP_COMP);
dkato 2:6ec5c1c1d41c 253 }
dkato 2:6ec5c1c1d41c 254 }
dkato 2:6ec5c1c1d41c 255 #endif // JPEG_SEND
<> 0:eb73febb2bba 256
<> 0:eb73febb2bba 257 /****** Video ******/
<> 0:eb73febb2bba 258 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) {
<> 0:eb73febb2bba 259 /* Interrupt callback function for Vfield interruption */
<> 0:eb73febb2bba 260 if (vfield_count > 0) {
<> 0:eb73febb2bba 261 vfield_count--;
<> 0:eb73febb2bba 262 }
dkato 2:6ec5c1c1d41c 263 #ifdef JPEG_SEND
dkato 2:6ec5c1c1d41c 264 jpegsend_cap_comp();
dkato 2:6ec5c1c1d41c 265 #endif // JPEG_SEND
<> 0:eb73febb2bba 266 }
<> 0:eb73febb2bba 267
<> 0:eb73febb2bba 268 static void Wait_Vfield(const int32_t wait_count) {
<> 0:eb73febb2bba 269 /* Wait for the specified number of times Vsync occurs */
<> 0:eb73febb2bba 270 vfield_count = wait_count;
<> 0:eb73febb2bba 271 while (vfield_count > 0) {
<> 0:eb73febb2bba 272 Thread::wait(1);
<> 0:eb73febb2bba 273 }
<> 0:eb73febb2bba 274 }
<> 0:eb73febb2bba 275
<> 0:eb73febb2bba 276 static void Init_Video(void) {
<> 0:eb73febb2bba 277 DisplayBase::graphics_error_t error;
<> 0:eb73febb2bba 278
<> 0:eb73febb2bba 279 /* Graphics initialization process */
<> 0:eb73febb2bba 280 if (graphics_init_end == false) {
<> 0:eb73febb2bba 281 /* When not initializing LCD, this processing is needed. */
<> 0:eb73febb2bba 282 error = Display.Graphics_init(NULL);
<> 0:eb73febb2bba 283 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 284 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 285 mbed_die();
<> 0:eb73febb2bba 286 }
<> 0:eb73febb2bba 287 graphics_init_end = true;
<> 0:eb73febb2bba 288 }
<> 0:eb73febb2bba 289
<> 0:eb73febb2bba 290 #if VIDEO_INPUT_METHOD == VIDEO_CVBS
<> 0:eb73febb2bba 291 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
<> 0:eb73febb2bba 292 if( error != DisplayBase::GRAPHICS_OK ) {
<> 0:eb73febb2bba 293 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 294 mbed_die();
<> 0:eb73febb2bba 295 }
<> 0:eb73febb2bba 296 #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
<> 0:eb73febb2bba 297 DisplayBase::video_ext_in_config_t ext_in_config;
<> 0:eb73febb2bba 298 PinName cmos_camera_pin[11] = {
<> 0:eb73febb2bba 299 /* data pin */
<> 0:eb73febb2bba 300 P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0,
<> 0:eb73febb2bba 301 /* control pin */
<> 0:eb73febb2bba 302 P10_0, /* DV0_CLK */
<> 0:eb73febb2bba 303 P1_0, /* DV0_Vsync */
<> 0:eb73febb2bba 304 P1_1 /* DV0_Hsync */
<> 0:eb73febb2bba 305 };
<> 0:eb73febb2bba 306
<> 0:eb73febb2bba 307 /* MT9V111 camera input config */
<> 0:eb73febb2bba 308 ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
<> 0:eb73febb2bba 309 ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */
<> 0:eb73febb2bba 310 ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */
<> 0:eb73febb2bba 311 ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */
<> 0:eb73febb2bba 312 ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */
<> 0:eb73febb2bba 313 ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */
<> 0:eb73febb2bba 314 ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */
<> 0:eb73febb2bba 315 ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */
<> 0:eb73febb2bba 316 ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */
<> 0:eb73febb2bba 317 ext_in_config.inp_h_pos = DisplayBase::EXTIN_H_POS_CRYCBY; /* Y/Cb/Y/Cr data string start timing to Hsync reference */
<> 0:eb73febb2bba 318 ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */
<> 0:eb73febb2bba 319 ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */
<> 0:eb73febb2bba 320 #if ((LCD_ONOFF) && (LCD_TYPE == 0))
<> 0:eb73febb2bba 321 /* The same screen ratio as the screen ratio of the LCD. */
<> 0:eb73febb2bba 322 ext_in_config.cap_width = 640; /* Capture width */
<> 0:eb73febb2bba 323 ext_in_config.cap_height = 363; /* Capture height Max 468[line]
<> 0:eb73febb2bba 324 Due to CMOS(MT9V111) output signal timing and VDC5 specification */
<> 0:eb73febb2bba 325 #else
<> 0:eb73febb2bba 326 ext_in_config.cap_width = 640; /* Capture width */
<> 0:eb73febb2bba 327 ext_in_config.cap_height = 468; /* Capture height Max 468[line]
<> 0:eb73febb2bba 328 Due to CMOS(MT9V111) output signal timing and VDC5 specification */
<> 0:eb73febb2bba 329 #endif
<> 0:eb73febb2bba 330 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config);
<> 0:eb73febb2bba 331 if( error != DisplayBase::GRAPHICS_OK ) {
<> 0:eb73febb2bba 332 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 333 mbed_die();
<> 0:eb73febb2bba 334 }
<> 0:eb73febb2bba 335
<> 0:eb73febb2bba 336 /* Camera input port setting */
<> 0:eb73febb2bba 337 error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11);
<> 0:eb73febb2bba 338 if( error != DisplayBase::GRAPHICS_OK ) {
<> 0:eb73febb2bba 339 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 340 mbed_die();
<> 0:eb73febb2bba 341 }
<> 0:eb73febb2bba 342 #endif
<> 0:eb73febb2bba 343
<> 0:eb73febb2bba 344 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
<> 0:eb73febb2bba 345 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
<> 0:eb73febb2bba 346 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 347 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 348 mbed_die();
<> 0:eb73febb2bba 349 }
<> 0:eb73febb2bba 350 }
<> 0:eb73febb2bba 351
<> 0:eb73febb2bba 352 static void Start_Video(uint8_t * p_buf) {
<> 0:eb73febb2bba 353 DisplayBase::graphics_error_t error;
<> 0:eb73febb2bba 354
<> 0:eb73febb2bba 355 /* Video capture setting (progressive form fixed) */
<> 0:eb73febb2bba 356 error = Display.Video_Write_Setting(
<> 0:eb73febb2bba 357 VIDEO_INPUT_CH,
<> 0:eb73febb2bba 358 COL_SYS,
<> 0:eb73febb2bba 359 p_buf,
<> 0:eb73febb2bba 360 FRAME_BUFFER_STRIDE,
<> 0:eb73febb2bba 361 VIDEO_FORMAT,
<> 0:eb73febb2bba 362 WR_RD_WRSWA,
<> 0:eb73febb2bba 363 VIDEO_PIXEL_VW,
<> 0:eb73febb2bba 364 VIDEO_PIXEL_HW
<> 0:eb73febb2bba 365 );
<> 0:eb73febb2bba 366 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 367 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 368 mbed_die();
<> 0:eb73febb2bba 369 }
<> 0:eb73febb2bba 370
<> 0:eb73febb2bba 371 /* Video write process start */
<> 0:eb73febb2bba 372 error = Display.Video_Start(VIDEO_INPUT_CH);
<> 0:eb73febb2bba 373 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 374 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 375 mbed_die();
<> 0:eb73febb2bba 376 }
<> 0:eb73febb2bba 377
<> 0:eb73febb2bba 378 /* Video write process stop */
<> 0:eb73febb2bba 379 error = Display.Video_Stop(VIDEO_INPUT_CH);
<> 0:eb73febb2bba 380 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 381 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 382 mbed_die();
<> 0:eb73febb2bba 383 }
<> 0:eb73febb2bba 384
<> 0:eb73febb2bba 385 /* Video write process start */
<> 0:eb73febb2bba 386 error = Display.Video_Start(VIDEO_INPUT_CH);
<> 0:eb73febb2bba 387 if (error != DisplayBase::GRAPHICS_OK) {
<> 0:eb73febb2bba 388 printf("Line %d, error %d\n", __LINE__, error);
<> 0:eb73febb2bba 389 mbed_die();
<> 0:eb73febb2bba 390 }
<> 0:eb73febb2bba 391 }
<> 0:eb73febb2bba 392
<> 0:eb73febb2bba 393 /****** zxing_init ******/
<> 0:eb73febb2bba 394 void zxing_init(void (*pfunc)(char * addr, int size)) {
<> 0:eb73febb2bba 395
dkato 2:6ec5c1c1d41c 396 #ifdef JPEG_SEND
dkato 2:6ec5c1c1d41c 397 jpegsendTask_init();
dkato 2:6ec5c1c1d41c 398 #endif // JPEG_SEND
<> 0:eb73febb2bba 399 #if LCD_ONOFF
<> 0:eb73febb2bba 400 /* Initialization of LCD */
<> 0:eb73febb2bba 401 Init_LCD_Display(); /* When using LCD, please call before than Init_Video(). */
dkato 2:6ec5c1c1d41c 402 #endif // LCD_ONOFF
<> 0:eb73febb2bba 403 /* Initialization of Video */
<> 0:eb73febb2bba 404 Init_Video();
<> 0:eb73febb2bba 405
<> 0:eb73febb2bba 406 /* Initialization memory */
dkato 2:6ec5c1c1d41c 407 memset(user_frame_buffer0, 0, (FRAME_BUFFER_STRIDE * VIDEO_PIXEL_VW));
<> 0:eb73febb2bba 408
<> 0:eb73febb2bba 409 /* Start of Video */
dkato 2:6ec5c1c1d41c 410 Start_Video(user_frame_buffer0);
<> 0:eb73febb2bba 411 /* Wait for first video drawing */
dkato 2:6ec5c1c1d41c 412 Wait_Vfield(WAIT_VFIELD_CNT);
<> 0:eb73febb2bba 413 #if LCD_ONOFF
dkato 2:6ec5c1c1d41c 414 decode_string_init();
<> 0:eb73febb2bba 415 /* Start of LCD */
dkato 2:6ec5c1c1d41c 416 Start_LCD_Display(user_frame_buffer0);
<> 0:eb73febb2bba 417 /* Backlight on */
<> 0:eb73febb2bba 418 Thread::wait(200);
<> 0:eb73febb2bba 419 lcd_cntrst.write(1.0);
dkato 2:6ec5c1c1d41c 420 #endif // LCD_ONOFF
<> 0:eb73febb2bba 421 p_callback_func = pfunc;
<> 0:eb73febb2bba 422 decode_timer.reset();
<> 0:eb73febb2bba 423 decode_timer.start();
<> 0:eb73febb2bba 424 }
<> 0:eb73febb2bba 425
<> 0:eb73febb2bba 426 /****** zxing_main ******/
<> 0:eb73febb2bba 427 int zxing_loop() {
<> 0:eb73febb2bba 428 DisplayBase::graphics_error_t error;
<> 0:eb73febb2bba 429 int decode_result = -1;
<> 0:eb73febb2bba 430 vector<Ref<Result> > results;
dkato 2:6ec5c1c1d41c 431 char ** decode_str = NULL;
<> 0:eb73febb2bba 432
dkato 2:6ec5c1c1d41c 433 Wait_Vfield(WAIT_VFIELD_CNT);
<> 0:eb73febb2bba 434 /* Decode barcode image */
<> 0:eb73febb2bba 435 if (decode_timer.read_ms() >= decode_wait_time) {
<> 0:eb73febb2bba 436 decode_timer.reset();
dkato 2:6ec5c1c1d41c 437 DecodeHints hints(DECODE_HINTS);
dkato 2:6ec5c1c1d41c 438 hints.setTryHarder(false);
dkato 2:6ec5c1c1d41c 439 decode_result = ex_decode(user_frame_buffer0, (FRAME_BUFFER_STRIDE * VIDEO_PIXEL_VW), VIDEO_PIXEL_HW, VIDEO_PIXEL_VW, &results, hints);
<> 0:eb73febb2bba 440 if (decode_result == 0) {
<> 0:eb73febb2bba 441 decode_str = (char **)&(results[0]->getText()->getText());
dkato 2:6ec5c1c1d41c 442 int size = strlen(*decode_str);
<> 0:eb73febb2bba 443 if (p_callback_func != NULL) {
<> 0:eb73febb2bba 444 p_callback_func(*decode_str, size);
<> 0:eb73febb2bba 445 }
<> 0:eb73febb2bba 446 decode_wait_time = 500;
<> 0:eb73febb2bba 447 } else {
<> 0:eb73febb2bba 448 decode_wait_time = 10;
<> 0:eb73febb2bba 449 }
dkato 2:6ec5c1c1d41c 450 #if LCD_ONOFF
dkato 2:6ec5c1c1d41c 451 decode_string_disp(decode_str);
dkato 2:6ec5c1c1d41c 452 #endif // LCD_ONOFF
<> 0:eb73febb2bba 453 }
<> 0:eb73febb2bba 454
<> 0:eb73febb2bba 455 return decode_result;
<> 0:eb73febb2bba 456 }
dkato 2:6ec5c1c1d41c 457