QR Gen

mail@pastecode.io avatar
unknown
c_cpp
a month ago
2.0 kB
2
Indexable
Never
int QRGen(char* String, char* formattedAmount)
{
	int Length = strlen(String);
	int SizeLevel = 4;
	int CorrectionLevel = 1;
	//int Size = 0;
	int Branch = 2;
	int Times = 1; /*Only effective for one dimensional bitmap data. */
	XuiImg* Img = NULL;
	XuiWindow* RootCanvas = NULL;

	XuiColor AmountTextColor;
	memset(&AmountTextColor, 0, sizeof(AmountTextColor));
	AmountTextColor.r = 0x00;
	AmountTextColor.g = 0x00;
	AmountTextColor.b = 0x00;
	AmountTextColor.a = 0xff;

	ResetInactivityTimeUpQR();
	clearScreen();
	drawRead(4);

	ST_BITMAP_QR Bitmap = { 0 };
	Bitmap.Data = malloc(300 * 400 * 4);
	Bitmap.Size = 300 * 400 * 4;
	memset(Bitmap.Data, 0, Bitmap.Size);

	ST_ENCODED_INFO BeEncodedInfo = {
	.Type = QRCODE,
	.String = String,
	.Len = Length,
	.SizeLevel = SizeLevel,
	.CorrectionLevel = CorrectionLevel,
	.Column = 1,
	.AztecSize = 4,

	};

	OsBarcodeGetBitmap(&BeEncodedInfo, &Bitmap);

	OsLog(LOG_DEBUG, "ST_BITMAP = %d,%d,%d", Bitmap.Width, Bitmap.Height, Bitmap.Size);


	Img = ConvertXuiImgData(&Bitmap, Branch, Times);
	RootCanvas = XuiRootCanvas();

	if (screenSize == 1)//320
	{
		XuiCanvasDrawImg(RootCanvas, 80, 10, 800, 800, XUI_BG_NORMAL, Img);
		drawTextOnScreen(formattedAmount, AmountTextColor, 170, 40, 20);
		LOGGER(LOG_DEBUG, "paso %s ", formattedAmount);
	}
	else //240
	{
		XuiCanvasDrawImg(RootCanvas, 10, 10, 800, 800, XUI_BG_NORMAL, Img);
		drawTextOnScreen(formattedAmount, AmountTextColor, 12, 40, 20);
		LOGGER(LOG_DEBUG, "paso %s ", formattedAmount);
	}


	OsLog(LOG_DEBUG, "Draw QR Code-------------------------");

	int key;
	while (WaittinqApprovedQR) {
		OsSleep(1);
		key = readKey();
		if (key == KEYCANCEL)
		{
			WaittinqApprovedQR = 0;
		}

		if (InactivityTimeUpQR()) {
			//DestroyMenuConfig();
			//return TIMEOUT;
			WaittinqApprovedQR = 0;
			key = KEYCANCEL;
		}



	}

	free(Bitmap.Data);
	XuiImgFree(Img);


	return  key == KEYCANCEL ? KEYCANCEL : 0;
}
Leave a Comment