QR Code (Sample)

From SEGGER Wiki
Jump to: navigation, search
GUI_QRCode.c
GUI QRCode.png
File(s) required
  • GUI_QRCode.c
Runs in simulation Yes
Runs on target Yes
Download GUI_QRCode.c

This sample shows how to draw QR codes with emWin.

Code

/*********************************************************************
*                    SEGGER Microcontroller GmbH                     *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2020  SEGGER Microcontroller GmbH                *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************

** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws.   Knowledge of the
source code may not be used to write a similar product.  This file may
only  be used  in accordance  with  a license  and should  not be  re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : GUI_QRCode.c
Purpose     : Sample that demonstrates how to draw a QR code with emWin.
Requirements: WindowManager - ( )
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  GUI_HMEM    hQR;
  GUI_QR_INFO Info;
  char        acBuffer[32];

  //
  // Init emWin.
  //
  GUI_Init();
  //
  // The QR code needs a white framing, so we make sure the background is white.
  //
  GUI_SetBkColor(GUI_WHITE);
  GUI_Clear();
  //
  // Create QR code handle.
  //
  hQR = GUI_QR_Create("www.segger.com/products/user-interface/emwin/", 5, GUI_QR_ECLEVEL_H, 0);
  //
  // Retrieve info if needed.
  //
  GUI_QR_GetInfo(hQR, &Info);
  GUI_SetColor(GUI_BLACK);
  sprintf(acBuffer, "Number of modules: %d", Info.Width);
  GUI_DispStringAt(acBuffer, 230, 10);
  sprintf(acBuffer, "Size of QR code: %d", Info.Size);
  GUI_DispStringAt(acBuffer, 230, 30);
  sprintf(acBuffer, "Version: %d", Info.Version);
  GUI_DispStringAt(acBuffer, 230, 50);
  //
  // Draw QR code.
  //
  GUI_QR_Draw(hQR, 10, 10);

  while (1) {
    GUI_Delay(100);
  }
}

/*************************** End of file ****************************/