Skip to content

Instantly share code, notes, and snippets.

@Kakise
Last active August 10, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kakise/fbc24ae75cb64d22a270c70781315324 to your computer and use it in GitHub Desktop.
Save Kakise/fbc24ae75cb64d22a270c70781315324 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <bitset>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <zint.h> // libzint is needed to compile
#define CLEAR if (system("CLS")) system("clear");
std::bitset<2> selectTemp() {
int tmp;
select:
CLEAR
std::cout << "Please select the temperature of your beverage." << std::endl;
std::cout << "0 for cold" << std::endl;
std::cout << "1 for warm" << std::endl;
std::cout << "2 for 85°C" << std::endl;
std::cout << "3 for 95°C" << std::endl;
std::cin >> tmp;
if (tmp < 0 || tmp > 3) goto select;
return std::bitset<2>(tmp);
}
std::bitset<2> selectCharge() {
int tmp;
select:
CLEAR
std::cout << "Please select the cartridge charge mode of your beverage." << std::endl;
std::cout << "0 for a fast charge with soak" << std::endl;
std::cout << "1 for a fast charge without soak" << std::endl;
std::cout << "2 for a slow charge with soak" << std::endl;
std::cout << "3 for a slow charge without soak" << std::endl;
std::cin >> tmp;
if (tmp < 0 || tmp > 3) goto select;
return std::bitset<2>(tmp);
}
std::bitset<4> selectVolume() {
int tmp;
select:
CLEAR
std::cout << "Please select the volume of your beverage." << std::endl;
std::cout << "0 = 50ml" << std::endl;
std::cout << "1 = 60ml" << std::endl;
std::cout << "2 = 70ml" << std::endl;
std::cout << "3 = 80ml" << std::endl;
std::cout << "4 = 90ml" << std::endl;
std::cout << "5 = 100ml" << std::endl;
std::cout << "6 = 110ml" << std::endl;
std::cout << "7 = 130ml" << std::endl;
std::cout << "8 = 150ml" << std::endl;
std::cout << "9 = 170ml" << std::endl;
std::cout << "10 = 190ml" << std::endl;
std::cout << "11 = 210ml" << std::endl;
std::cout << "12 = 230ml" << std::endl;
std::cout << "13 = 250ml" << std::endl;
std::cout << "14 = 275ml" << std::endl;
std::cout << "15 = 300ml" << std::endl;
std::cin >> tmp;
if (tmp < 0 || tmp > 15) goto select;
return std::bitset<4>(tmp);
}
std::bitset<3> selectFlowRate() {
int tmp;
select:
CLEAR
std::cout << "Please select the flow rate of the pump." << std::endl;
std::cout << "0 = 30%" << std::endl;
std::cout << "1 = 40%" << std::endl;
std::cout << "2 = 50%" << std::endl;
std::cout << "3 = 60%" << std::endl;
std::cout << "4 = 70%" << std::endl;
std::cout << "5 = 80%" << std::endl;
std::cout << "6 = 90%" << std::endl;
std::cout << "7 = 100%" << std::endl;
std::cin >> tmp;
if (tmp < 0 || tmp > 7) goto select;
return std::bitset<3>(tmp);
}
std::bitset<2> selectPurge() {
int tmp;
select:
CLEAR
std::cout << "Please select the purge mode of your cartridge." << std::endl;
std::cout << "0 = slow flow/short period" << std::endl;
std::cout << "1 = slow flow/long period" << std::endl;
std::cout << "2 = fast flow/short period" << std::endl;
std::cout << "3 = fast flow/long period" << std::endl;
std::cin >> tmp;
if (tmp < 0 || tmp > 3) goto select;
return std::bitset<2>(tmp);
}
int main() {
std::string t;
std::cout << "############################################################" << std::endl;
std::cout << "# T-Disk barcode generator version 2 #" << std::endl;
std::cout << "# #" << std::endl;
std::cout << "# Author: Kakise <mail@kakise.me> #" << std::endl;
std::cout << "# Blog: https://kakise.me #" << std::endl;
std::cout << "# #" << std::endl;
std::cout << "# I won't be responsible for any damage done to your #" << std::endl;
std::cout << "# machine ! #" << std::endl;
std::cout << "# #" << std::endl;
std::cout << "# Press <Enter> to continue. #" << std::endl;
std::cout << "############################################################" << std::endl;
getchar();
auto temp = selectTemp();
auto charge = selectCharge();
auto volume = selectVolume();
auto flowRate = selectFlowRate();
auto purge = selectPurge();
// Calculate the checksum digit
std::string barcode0 = temp.to_string() + charge.to_string() + volume.to_string() + flowRate.to_string() + purge.to_string();
std::bitset<13> barcodeDec(barcode0);
int bcint = (int)(barcodeDec.to_ulong());
int rem = 50 - bcint / 1000 - 3 * ((bcint % 1000 - bcint % 100)/100) - (bcint % 100 - bcint % 10)/10 - 3 * (bcint%10);
int a = rem / 3;
int f = rem - 3 * a;
std::bitset<20> barcode(std::stoi(std::to_string(a) + std::to_string(bcint) + std::to_string(f)));
// Prints the binary barcode
CLEAR
std::cout << "Barcode: " << std::endl;
std::cout << "Binary: " << barcode.to_string() << std::endl;
std::cout << "Decimal: " << (int)(barcode.to_ulong()) << std::endl;
struct zint_symbol *my_symbol;
my_symbol = ZBarcode_Create();
my_symbol->symbology = BARCODE_C25MATRIX;
ZBarcode_Encode_and_Print(my_symbol, reinterpret_cast<unsigned char *>(const_cast<char *>(std::to_string((int)(barcode.to_ulong())).c_str())), 0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment