Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Printer.cpp
- Revision:
- 0:7f3d28e53383
- Child:
- 1:f257e2e4e026
diff -r 000000000000 -r 7f3d28e53383 Printer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Printer.cpp Fri Jul 05 10:32:31 2019 +0000 @@ -0,0 +1,253 @@ +#include "mbed.h" +#include "Printer.h" + +extern Serial dbg; +const char * const WDAY[] = {"Minggu", "Senin", "Selasa", "Rabu", + "Kamis", "Jumat", "Sabtu"}; +const char * const MONT[] = {"Januari", "Februari", "Maret", "April", + "Mei", "Juni", "Juli", "Agustus", "September", + "Oktober", "November", "Desember"}; + +Printer::Printer(PinName tx_, PinName rx_, int baud_) : Tm(tx_, rx_) +{ +} + +Printer::~Printer() +{ +} + +void Printer::init(const PrinterFormat &pf) +{ + Pf = pf; + Tm.initialize(); +} + +void Printer::create_header() +{ + // create header + Tm.lineFeed();wait_ms(10); + Tm.printModes(0x28);wait_ms(10); + Tm.printf("SPBU %s", Pf.spbu.c_str());wait_ms(10); + Tm.printModes(0x01);wait_ms(10); + Tm.printf("\n");wait_ms(10); + + for(int i=0; i<Pf.alamat.size(); i++) + { + Tm.printf("%s\n", Pf.alamat[i].c_str());wait_ms(10); + } + Tm.printf("Telp. %s\n", Pf.telp.c_str());wait_ms(10); +} + +// Private Fuction +string Printer::get_product(const uint8_t code) +{ + string ret; + switch(code) + { + case 1: ret = "Premium";break; + case 2: ret = "Pertalite";break; + case 3: ret = "Pertamax";break; + case 4: ret = "Bio Solar";break; + case 5: ret = "Pertamina Dex";break; + } + return ret; +} + +void Printer::TestPrint(const std::time_t &now) +{ + std::tm * ptm = std::localtime(&now); + char times[64]; + strftime (times,64,"%Y %H:%M:%S",ptm); + + Tm.printf("%s, %02d %s %s\n", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); + Tm.printf("__________________________________\n"); + Tm.printf("Nomor Printer: %d\n", Pf.id); + Tm.printf("Nomor Selang : 2\n"); + Tm.printf("Nomor Nota : 1\n"); + Tm.printf("Jenis BBM : SOLAR\n"); + Tm.printf("Liter : 5.00\n"); + Tm.printf("Harga/Liter : Rp 10.000\n"); + Tm.printModes(0x19); + Tm.printf("Total : Rp 50.000\n"); + Tm.printModes(0x01); + Tm.printf("_________________________________\n"); + for(int i=0; i<Pf.footer.size(); i++) + { + Tm.printf("%s\r\n", Pf.footer[i].c_str()); + } + Tm.printf("\n"); + Tm.printf("\n"); + Tm.printf("\n"); + Tm.printf("\n"); + Tm.printf("\n"); + + create_header(); +} +string intwcurrency(const int &val) +{ + char str[20]; + + sprintf(str,"%6d", val); + string input; + input += str; + if(val>999) + { + for( int i = input.size() - 3; i > 0; i -= 3 ) + { + input.insert( input.begin() + i, '.' ); + } + } + else + { + for( int i = input.size() - 3; i > 0; i -= 3 ) + { + input.insert( input.begin() + i, ' ' ); + } + } + return input; +} + +void Printer::PrintStruk(const std::time_t &now, const char *datain, const unsigned int &no_nota, const uint8_t &nozz, + const uint8_t pipa, const string &Nopol, const string &Odo) +{ + float liter=0; + unsigned int harga=0; + unsigned long int total=0; + char times[64]; + + + liter =((datain[1]-0x30)*100) + ((datain[2]-0x30)*10) + ((datain[3]-0x30)*1) + ((datain[4]-0x30)*0.1) + ((datain[5]-0x30)* 0.01); + + harga = ((datain[7]-0x30)*1000) + ((datain[8]-0x30)*100) + ((datain[9]-0x30)*10) + ((datain[10]-0x30)*1); + total = ((datain[11]-0x30)*100000) + ((datain[12]-0x30)*10000) + ((datain[13]-0x30)*1000) + ((datain[14]-0x30)*100) + ((datain[15]-0x30)*10)+((datain[16]-0x30)*1); + + std::tm * ptm = std::localtime(&now); + strftime (times,64,"%Y %H:%M:%S",ptm); + wait_ms(100); + + Tm.printf("%s, %02d %s %s\n", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times);wait_ms(10); + Tm.printf("__________________________________\n");wait_ms(10); + Tm.printf("Nomor Printer: %d\n", Pf.id);wait_ms(10); + Tm.printf("Nomor Selang : %d\n", pipa);wait_ms(10); + Tm.printf("Nomor Nota : %d\n", no_nota);wait_ms(10); + Tm.printf("Jenis BBM : %s\n", get_product(nozz).c_str());wait_ms(10); + Tm.printf("Liter : %3.2f\n",liter);wait_ms(10); + Tm.printf("Harga/Liter : Rp. %s\n",intwcurrency(harga).c_str());wait_ms(10); + Tm.printModes(0x19);wait_ms(10); + Tm.printf("Total : Rp. %s\n",intwcurrency(total).c_str());wait_ms(10); + wait_ms(10); + Tm.printModes(0x01);wait_ms(10); + Tm.printf("_________________________________\n");wait_ms(10); + + if(Nopol.size()>0)Tm.printf("Nopol : %s\n",Nopol.c_str()); + if(Odo.size()>0) Tm.printf("Odometer : %s\n",Odo.c_str()); + + wait_ms(50); + for(int i=0; i<Pf.footer.size(); i++) + { + Tm.printf("%s\r\n", Pf.footer[i].c_str());wait_ms(10); + } + Tm.printf("\n\n\n\n");wait_ms(10); +// tm.printf("\n"); +// tm.printf("\n"); +// tm.printf("\n"); +// tm.printf("\n"); +// tm.printf("\n"); + wait_ms(50); + create_header(); +// tm.cutPaper(); +} + +void Printer::PrintStruk(const std::time_t &now, const ResultParsing &res, const unsigned int &no_nota, + const string &Nopol, const string &Odo) +{ + float liter=0; + unsigned int harga=0; + unsigned long int total=0; + char times[64]; + + liter = res.volume; + harga = res.ppu; + total = res.money; + + std::tm * ptm = std::localtime(&now); + strftime (times,64,"%Y %H:%M:%S",ptm); + wait_ms(100); + + Tm.printf("%s, %02d %s %s\n", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times);wait_ms(10); + Tm.printf("__________________________________\n");wait_ms(10); + Tm.printf("Nomor Printer: %d\n", Pf.id);wait_ms(10); + Tm.printf("Nomor Selang : %d\n", res.id);wait_ms(10); + Tm.printf("Nomor Nota : %d\n", no_nota);wait_ms(10); + Tm.printf("Jenis BBM : %s\n", res.product.c_str());wait_ms(10); + Tm.printf("Liter : %3.2f\n",liter);wait_ms(10); + Tm.printf("Harga/Liter : Rp. %s\n",intwcurrency(harga).c_str());wait_ms(10); + Tm.printModes(0x19);wait_ms(10); + Tm.printf("Total : Rp. %s\n",intwcurrency(total).c_str());wait_ms(10); + wait_ms(10); + Tm.printModes(0x01);wait_ms(10); + Tm.printf("_________________________________\n");wait_ms(10); + + if(Nopol.size()>0)Tm.printf("Nopol : %s\n",Nopol.c_str()); + if(Odo.size()>0) Tm.printf("Odometer : %s\n",Odo.c_str()); + + wait_ms(50); + for(int i=0; i<Pf.footer.size(); i++) + { + Tm.printf("%s\r\n", Pf.footer[i].c_str());wait_ms(10); + } + Tm.printf("\n\n\n\n");wait_ms(10); + wait_ms(50); + create_header();wait_ms(10); + Tm.cutPaper(); +} + +void Printer::DebugStruk(const std::time_t &now, const ResultParsing &res, const unsigned int &no_nota, + const string &Nopol, const string &Odo) +{ + float liter=0; + unsigned int harga=0; + unsigned long int total=0; + char times[64]; + + liter = res.volume; + harga = res.ppu; + total = res.money; + + std::tm * ptm = std::localtime(&now); + strftime (times,64,"%Y %H:%M:%S",ptm); + wait_ms(100); + + dbg.printf("%s, %02d %s %s\n\r", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); + dbg.printf("__________________________________\n\r"); + dbg.printf("Nomor Printer: %d\n\r", Pf.id); + dbg.printf("Nomor Selang : %d\n\r", res.id); + dbg.printf("Nomor Nota : %d\n\r", no_nota); + dbg.printf("Jenis BBM : %s\n\r", res.product.c_str()); + dbg.printf("Liter : %3.2f\n\r",liter); + dbg.printf("Harga/Liter : Rp. %s\n\r",intwcurrency(harga).c_str()); + dbg.printf("Total : Rp. %s\n\r",intwcurrency(total).c_str()); + dbg.printf("_________________________________\n\r"); + + if(Nopol.size()>0)dbg.printf("Nopol : %s\n\r",Nopol.c_str()); + if(Odo.size()>0) dbg.printf("Odometer : %s\n\r",Odo.c_str()); + + wait_ms(50); + for(int i=0; i<Pf.footer.size(); i++) + { + dbg.printf("%s\r\n", Pf.footer[i].c_str()); + } + dbg.printf("\n\n\r"); +} + +void Printer::TestPrint2() +{ + create_header(); + Tm.printf("_________________________________\n"); + for(int i=0; i<Pf.prodak.size();i++) + { + Tm.printf("Produk %d : %s\r\n",i+1, Pf.prodak[i].c_str()); + } + Tm.printf("_________________________________\n\n\n\n\n\n\n\n"); + Tm.cutPaper(); +}