Mbed Client sample for GR-LYCHEE where ZXing is incorporated.
Dependencies: DisplayApp AsciiFont
Fork of GR-PEACH_mbed-os-client-ZXingSample by
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
- GR-LYCHEE ( https://developer.mbed.org/platforms/Renesas-GR-LYCHEE/ )
Application setup
- 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. - 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. - 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:
- Import this example onto mbed Compiler.
- Configure the example in accordance with Application setup.
- Compile the example on mbed Compiler and download the resultant binary file.
- Plug the micro-USB cable into the OpenSDA port which lies on the next to the RESET button.
- 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.
- Press the RESET button on the board to run the example.
- 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:
- 3202/0/5700. Decode result of barcode data input from camera (GET).
- 3201/0/5850. Blink function, blinks LED when executed (POST).
- 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).
- 3201/0/5855. Blink color, used by the blink function. Any of green, yellow, orange and red is acceptable (PUT).
Diff: zxing_main.cpp
- Revision:
- 10:c36cf363bf55
- Parent:
- 6:4e43b6f8f772
diff -r efd96de74217 -r c36cf363bf55 zxing_main.cpp --- a/zxing_main.cpp Mon Mar 19 07:39:08 2018 +0000 +++ b/zxing_main.cpp Thu Apr 19 08:35:21 2018 +0000 @@ -2,6 +2,7 @@ #include "mbed.h" #include "EasyAttach_CameraAndLCD.h" #include "ImageReaderSource.h" +#include "AsciiFont.h" /**** User Selection *********/ /** JPEG out setting **/ @@ -10,8 +11,6 @@ #define VFIELD_INT_SKIP_CNT (0) /* A guide for GR-LYCHEE. 0:60fps, 1:30fps, 2:20fps, 3:15fps, 4:12fps, 5:10fps */ /** Decode hints **/ #define DECODE_HINTS (DecodeHints::ONED_HINT | DecodeHints::QR_CODE_HINT | DecodeHints::DATA_MATRIX_HINT | DecodeHints::AZTEC_HINT) -/** Camera setting **/ -#define OV7725_SETTING_TEST (0) /* Exposure and Gain Setting Test 0:disable 1:enable */ /*****************************/ /* Video input and LCD layer 0 output */ @@ -121,16 +120,6 @@ } } } - -#if OV7725_SETTING_TEST -static DisplayApp::touch_pos_t s_touch; - -static bool touch_notification = false; - -static void touch_callback(void) { - touch_notification = true; -} -#endif #endif static void Start_Video_Camera(void) { @@ -169,6 +158,70 @@ Thread::wait(50); EasyAttach_LcdBacklight(true); } + +#define VIDEO_PIXEL_HW_STR (VIDEO_PIXEL_HW - 64) +#define VIDEO_PIXEL_VW_STR (VIDEO_PIXEL_VW - 64) +#define FRAME_BUFFER_BYTE_PER_PIXEL_STR (2u) +#define FRAME_BUFFER_STRIDE_STR (((VIDEO_PIXEL_HW_STR * FRAME_BUFFER_BYTE_PER_PIXEL_STR) + 31u) & ~31u) + +static uint8_t user_frame_buffer_string[FRAME_BUFFER_STRIDE_STR * VIDEO_PIXEL_VW_STR]__attribute((section("NC_BSS"),aligned(32))); +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); +static bool string_draw; +static int error_cnt; + +static void decode_string_init(void) { + DisplayBase::rect_t rect; + + /* The layer by which the touch panel location is drawn */ + ascii_font.Erase(0x00000000); /* rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red */ + rect.vs = 32; + rect.vw = VIDEO_PIXEL_VW_STR; + rect.hs = 32; + rect.hw = VIDEO_PIXEL_HW_STR; + Display.Graphics_Read_Setting( + DisplayBase::GRAPHICS_LAYER_2, + (void *)user_frame_buffer_string, + FRAME_BUFFER_STRIDE_STR, + DisplayBase::GRAPHICS_FORMAT_ARGB4444, + DisplayBase::WR_RD_WRSWA_32_16BIT, + &rect + ); + Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_2); + string_draw = false; + error_cnt = 0; +} + +static void decode_string_disp(char ** decode_str) { + if ((decode_str != NULL) && (*decode_str != NULL)) { + /* Drow string */ + ascii_font.Erase(0x00000090); /* rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red */ + int rest_size = strlen(*decode_str); + int draw_idx = 0; + int draw_size; + int draw_line = 0; + + while (rest_size > 0) { + draw_size = ascii_font.DrawStr(*decode_str + draw_idx, 6, 5 + (18 * draw_line), 0x0000ffff, 2); + if (draw_size <= 0) { + break; + } + rest_size -= draw_size; + draw_idx += draw_size; + draw_line++; + } + string_draw = true; + error_cnt = 0; + } else { + if (string_draw != false) { + error_cnt++; + if (error_cnt > 15) { + /* Clear string */ + ascii_font.Erase(0x00000000); /* rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red */ + string_draw = false; + } + } + } +} #endif @@ -180,17 +233,19 @@ user_frame_buffer0[i + 1] = 0x80; } +#if MBED_CONF_APP_LCD + EasyAttach_Init(Display, 640, 360); +#else EasyAttach_Init(Display); +#endif #if JPEG_SEND Jcu.SetQuality(JPEG_ENCODE_QUALITY); // Interrupt callback function setting (Field end signal for recording function in scaler 0) Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VFIELD, 0, IntCallbackFunc_Vfield); -#if OV7725_SETTING_TEST - display_app.SetCallback(&touch_callback); -#endif #endif Start_Video_Camera(); #if MBED_CONF_APP_LCD + decode_string_init(); Start_LCD_Display(); #endif @@ -205,28 +260,6 @@ vector<Ref<Result> > results; char ** decode_str = NULL; -#if JPEG_SEND - snapshot(); -#if OV7725_SETTING_TEST - // OV7725 Setting test - if (touch_notification) { - display_app.GetCoordinates(1, &s_touch); - if (s_touch.valid) { - uint16_t usManualExposure = (uint16_t)(0xFFFF * ((float)s_touch.x / 800.f)); - uint8_t usManualGain = (uint8_t)(0xFF * ((float)s_touch.y / 480.0f)); - OV7725_config::SetExposure(false, usManualExposure, usManualGain); - printf("usManualExposure 0x%04x, usManualGain 0x%02x\r\n", usManualExposure, usManualGain); - } else { - OV7725_config::SetExposure(true, 0x0000, 0x00); - printf("SetExposure Auto\r\n"); - } - touch_notification = false; - } -#endif -#else - Thread::wait(1000); -#endif - /* Decode barcode image */ if (decode_timer.read_ms() >= decode_wait_time) { decode_timer.reset(); @@ -243,6 +276,9 @@ } else { decode_wait_time = 10; } +#if MBED_CONF_APP_LCD + decode_string_disp(decode_str); +#endif } return decode_result;