Automatically calculate qr version
This commit is contained in:
@ -9,20 +9,18 @@
|
|||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
SwitchQrDisplayAction::SwitchQrDisplayAction(const qraction::QrMenu &qrmenu) :
|
SwitchQrDisplayAction::SwitchQrDisplayAction(const qraction::QrMenu &qrmenu) :
|
||||||
m_msg{qrmenu.message},
|
m_msg{qrmenu.message}
|
||||||
m_ver{qrmenu.ver}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchQrDisplayAction::SwitchQrDisplayAction(qraction::QrMenu &&qrmenu) :
|
SwitchQrDisplayAction::SwitchQrDisplayAction(qraction::QrMenu &&qrmenu) :
|
||||||
m_msg{std::move(qrmenu.message)},
|
m_msg{std::move(qrmenu.message)}
|
||||||
m_ver{qrmenu.ver}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchQrDisplayAction::triggered()
|
void SwitchQrDisplayAction::triggered()
|
||||||
{
|
{
|
||||||
switchScreen<QrDisplay>(m_msg, m_ver);
|
switchScreen<QrDisplay>(m_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchQrImportDisplayAction::SwitchQrImportDisplayAction(const std::string &nvskey) :
|
SwitchQrImportDisplayAction::SwitchQrImportDisplayAction(const std::string &nvskey) :
|
||||||
|
@ -9,7 +9,6 @@ namespace qraction {
|
|||||||
struct QrMenu {
|
struct QrMenu {
|
||||||
std::string message;
|
std::string message;
|
||||||
std::string text;
|
std::string text;
|
||||||
uint8_t ver;
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -22,7 +21,6 @@ public:
|
|||||||
void triggered() override;
|
void triggered() override;
|
||||||
private:
|
private:
|
||||||
std::string m_msg;
|
std::string m_msg;
|
||||||
uint8_t m_ver;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SwitchQrImportDisplayAction : public virtual espgui::ActionInterface
|
class SwitchQrImportDisplayAction : public virtual espgui::ActionInterface
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
espgui::switchScreen<QrDisplay>(m_qrmenu.message, m_qrmenu.ver);
|
espgui::switchScreen<QrDisplay>(m_qrmenu.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@ -74,7 +74,7 @@ GreenPassMenu::GreenPassMenu()
|
|||||||
{
|
{
|
||||||
if (const auto certTxt = qrimport::get_qr_code(nvs_key); certTxt)
|
if (const auto certTxt = qrimport::get_qr_code(nvs_key); certTxt)
|
||||||
{
|
{
|
||||||
constructMenuItem<CertMenuItem>(qraction::QrMenu{.message=*certTxt, .text=nvs_key , .ver=15});
|
constructMenuItem<CertMenuItem>(qraction::QrMenu{.message=*certTxt, .text=nvs_key });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -9,17 +9,104 @@
|
|||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
QrDisplay::QrDisplay(std::string_view msg, uint8_t ver) :
|
QrDisplay::QrDisplay(std::string_view msg) :
|
||||||
m_msg{msg},
|
m_msg{msg}
|
||||||
m_ver{ver}
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t get_qrver_from_strlen(std::string_view str)
|
||||||
|
{
|
||||||
|
// alpha numeric, ECC Level M
|
||||||
|
// version 1-40
|
||||||
|
uint32_t len = str.length();
|
||||||
|
if (len <= 20)
|
||||||
|
return 1;
|
||||||
|
else if (len <= 38)
|
||||||
|
return 2;
|
||||||
|
else if (len <= 61)
|
||||||
|
return 3;
|
||||||
|
else if (len <= 90)
|
||||||
|
return 4;
|
||||||
|
else if (len <= 122)
|
||||||
|
return 5;
|
||||||
|
else if (len <= 154)
|
||||||
|
return 6;
|
||||||
|
else if (len <= 178)
|
||||||
|
return 7;
|
||||||
|
else if (len <= 221)
|
||||||
|
return 8;
|
||||||
|
else if (len <= 262)
|
||||||
|
return 9;
|
||||||
|
else if (len <= 311)
|
||||||
|
return 10;
|
||||||
|
else if (len <= 366)
|
||||||
|
return 11;
|
||||||
|
else if (len <= 419)
|
||||||
|
return 12;
|
||||||
|
else if (len <= 483)
|
||||||
|
return 13;
|
||||||
|
else if (len <= 528)
|
||||||
|
return 14;
|
||||||
|
else if (len <= 600)
|
||||||
|
return 15;
|
||||||
|
else if (len <= 656)
|
||||||
|
return 16;
|
||||||
|
else if (len <= 734)
|
||||||
|
return 17;
|
||||||
|
else if (len <= 816)
|
||||||
|
return 18;
|
||||||
|
else if (len <= 909)
|
||||||
|
return 19;
|
||||||
|
else if (len <= 970)
|
||||||
|
return 20;
|
||||||
|
else if (len <= 1035)
|
||||||
|
return 21;
|
||||||
|
else if (len <= 1134)
|
||||||
|
return 22;
|
||||||
|
else if (len <= 1248)
|
||||||
|
return 23;
|
||||||
|
else if (len <= 1326)
|
||||||
|
return 24;
|
||||||
|
else if (len <= 1451)
|
||||||
|
return 25;
|
||||||
|
else if (len <= 1542)
|
||||||
|
return 26;
|
||||||
|
else if (len <= 1637)
|
||||||
|
return 27;
|
||||||
|
else if (len <= 1732)
|
||||||
|
return 28;
|
||||||
|
else if (len <= 1839)
|
||||||
|
return 29;
|
||||||
|
else if (len <= 1994)
|
||||||
|
return 30;
|
||||||
|
else if (len <= 2113)
|
||||||
|
return 31;
|
||||||
|
else if (len <= 2238)
|
||||||
|
return 32;
|
||||||
|
else if (len <= 2369)
|
||||||
|
return 33;
|
||||||
|
else if (len <= 2506)
|
||||||
|
return 34;
|
||||||
|
else if (len <= 2632)
|
||||||
|
return 35;
|
||||||
|
else if (len <= 2780)
|
||||||
|
return 36;
|
||||||
|
else if (len <= 2894)
|
||||||
|
return 37;
|
||||||
|
else if (len <= 3054)
|
||||||
|
return 38;
|
||||||
|
else if (len <= 3220)
|
||||||
|
return 39;
|
||||||
|
else
|
||||||
|
return 40;
|
||||||
|
}
|
||||||
|
|
||||||
void QrDisplay::initScreen()
|
void QrDisplay::initScreen()
|
||||||
{
|
{
|
||||||
QRCode qrcode;
|
QRCode qrcode;
|
||||||
uint8_t qrcodeBytes[qrcode_getBufferSize(m_ver)];
|
const auto ver = get_qrver_from_strlen(m_msg);
|
||||||
qrcode_initText(&qrcode, qrcodeBytes, m_ver, ECC_MEDIUM, m_msg.data());
|
uint8_t qrcodeBytes[qrcode_getBufferSize(ver)];
|
||||||
|
qrcode_initText(&qrcode, qrcodeBytes, ver, ECC_MEDIUM, m_msg.data());
|
||||||
|
|
||||||
const uint8_t multiplier = (tft.width() - 9) / qrcode.size;
|
const uint8_t multiplier = (tft.width() - 9) / qrcode.size;
|
||||||
const uint8_t x_offset = (tft.width() - qrcode.size * multiplier) / 2;
|
const uint8_t x_offset = (tft.width() - qrcode.size * multiplier) / 2;
|
||||||
@ -45,9 +132,10 @@ void QrDisplay::buttonPressed(espgui::Button button)
|
|||||||
|
|
||||||
switch (button)
|
switch (button)
|
||||||
{
|
{
|
||||||
using espgui::Button;
|
case espgui::Button::Left:
|
||||||
case Button::Left: switchScreen<GreenPassMenu>(); break;
|
case espgui::Button::Right:
|
||||||
case Button::Right: switchScreen<GreenPassMenu>(); break;
|
switchScreen<GreenPassMenu>();
|
||||||
|
break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "bobbydisplay.h"
|
#include "bobbydisplay.h"
|
||||||
|
|
||||||
|
uint16_t get_qrver_from_strlen(std::string_view str);
|
||||||
|
|
||||||
class QrDisplay : public BobbyDisplay
|
class QrDisplay : public BobbyDisplay
|
||||||
{
|
{
|
||||||
using Base = BobbyDisplay;
|
using Base = BobbyDisplay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QrDisplay(std::string_view msg, uint8_t ver);
|
explicit QrDisplay(std::string_view msg);
|
||||||
|
|
||||||
void initScreen() override;
|
void initScreen() override;
|
||||||
|
|
||||||
@ -19,5 +21,4 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string_view m_msg;
|
std::string_view m_msg;
|
||||||
uint8_t m_ver;
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user