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.
Printer.cpp
00001 #include "mbed.h" 00002 #include "Printer.h" 00003 00004 extern Serial dbg; 00005 const char * const WDAY[] = {"Minggu", "Senin", "Selasa", "Rabu", 00006 "Kamis", "Jumat", "Sabtu" 00007 }; 00008 const char * const MONT[] = {"Januari", "Februari", "Maret", "April", 00009 "Mei", "Juni", "Juli", "Agustus", "September", 00010 "Oktober", "November", "Desember" 00011 }; 00012 00013 Printer::Printer(PinName tx_, PinName rx_, int baud_) : Tm(tx_, rx_) 00014 { 00015 } 00016 00017 Printer::~Printer() 00018 { 00019 } 00020 00021 void Printer::init(const PrinterFormat &pf) 00022 { 00023 Pf = pf; 00024 //Tm.initialize(); 00025 } 00026 00027 void Printer::create_header() 00028 { 00029 // create header 00030 Tm.putc(0x0A); 00031 wait_ms(10); 00032 Tm.printModes(0x00); 00033 wait_ms(10); 00034 Tm.printf("SPBU %s", Pf.spbu.c_str()); 00035 wait_ms(10); 00036 //Tm.printModes(0x01);wait_ms(10); 00037 //Tm.printf("\n");wait_ms(10); 00038 Tm.putc(0x0A); 00039 wait_ms(10); 00040 for(int i=0; i<Pf.alamat.size(); i++) { 00041 Tm.printf("%s", Pf.alamat[i].c_str()); 00042 wait_ms(10); 00043 Tm.putc(0x0A); 00044 wait_ms(10); 00045 } 00046 Tm.printf("Telp. %s", Pf.telp.c_str()); 00047 wait_ms(10); 00048 Tm.putc(0x0A); 00049 wait_ms(10); 00050 } 00051 00052 // Private Fuction 00053 string Printer::get_product(const uint8_t code) 00054 { 00055 string ret; 00056 switch(code) { 00057 case 1: 00058 ret = "Premium"; 00059 break; 00060 case 2: 00061 ret = "Pertalite"; 00062 break; 00063 case 3: 00064 ret = "Pertamax"; 00065 break; 00066 case 4: 00067 ret = "Bio Solar"; 00068 break; 00069 case 5: 00070 ret = "Pertamina Dex"; 00071 break; 00072 } 00073 return ret; 00074 } 00075 00076 void Printer::TestPrint(const std::time_t &now) 00077 { 00078 std::tm * ptm = std::localtime(&now); 00079 char times[64]; 00080 strftime (times,64,"%Y %H:%M:%S",ptm); 00081 00082 Tm.printf("%s, %02d %s %s", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); 00083 Tm.putc(0x0A); 00084 Tm.printf("__________________________________"); 00085 Tm.putc(0x0A); 00086 Tm.printf("Nomor Printer: %d", Pf.id); 00087 Tm.putc(0x0A); 00088 Tm.printf("Nomor Selang : 2"); 00089 Tm.putc(0x0A); 00090 Tm.printf("Nomor Nota : 1"); 00091 Tm.putc(0x0A); 00092 Tm.printf("Jenis BBM : SOLAR"); 00093 Tm.putc(0x0A); 00094 Tm.printf("Liter : 5.00"); 00095 Tm.putc(0x0A); 00096 Tm.printf("Harga/Liter : Rp 10.000"); 00097 Tm.putc(0x0A); 00098 Tm.printModes(0x10); 00099 Tm.printf("Total : Rp 50.000"); 00100 00101 Tm.printModes(0x01); 00102 Tm.printf("_________________________________\n"); 00103 //for(int i=0; i<Pf.footer.size(); i++) { 00104 // Tm.printf("%s\r\n", Pf.footer[i].c_str()); 00105 // } 00106 Tm.printf("\n"); 00107 Tm.printf("\n"); 00108 Tm.printf("\n"); 00109 Tm.printf("\n"); 00110 Tm.printf("\n"); 00111 00112 create_header(); 00113 } 00114 string intwcurrency(const int &val) 00115 { 00116 char str[20]; 00117 00118 sprintf(str,"%6d", val); 00119 string input; 00120 input += str; 00121 if(val>999) { 00122 for( int i = input.size() - 3; i > 0; i -= 3 ) { 00123 input.insert( input.begin() + i, ',' ); 00124 } 00125 } else { 00126 for( int i = input.size() - 3; i > 0; i -= 3 ) { 00127 input.insert( input.begin() + i, ' ' ); 00128 } 00129 } 00130 return input; 00131 } 00132 00133 void Printer::PrintStruk(const std::time_t &now, const char *datain, const unsigned int &no_nota, const uint8_t &nozz, 00134 const uint8_t pipa, const string &Nopol, const string &Odo) 00135 { 00136 float liter=0; 00137 unsigned int harga=0; 00138 unsigned long int total=0; 00139 char times[64]; 00140 00141 00142 liter =((datain[1]-0x30)*100) + ((datain[2]-0x30)*10) + ((datain[3]-0x30)*1) + ((datain[4]-0x30)*0.1) + ((datain[5]-0x30)* 0.01); 00143 00144 harga = ((datain[7]-0x30)*1000) + ((datain[8]-0x30)*100) + ((datain[9]-0x30)*10) + ((datain[10]-0x30)*1); 00145 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); 00146 00147 if(Pf.id == 2 || Pf.id == 3 || Pf.id == 5) { 00148 harga = harga/10; 00149 total = total/10; 00150 } 00151 00152 std::tm * ptm = std::localtime(&now); 00153 strftime (times,64,"%Y %H:%M:%S",ptm); 00154 wait_ms(100); 00155 00156 Tm.printf("%s, %02d %s %s", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); 00157 wait_ms(10); 00158 Tm.lineFeed(); 00159 wait_ms(10); 00160 Tm.printf("__________________________________"); 00161 wait_ms(10); 00162 Tm.lineFeed(); 00163 wait_ms(10); 00164 // Tm.printf("Nomor Printer: %d", Pf.id); 00165 // wait_ms(10); 00166 // Tm.lineFeed(); 00167 // wait_ms(10); 00168 Tm.printf("Nomor Selang : %d", pipa); 00169 wait_ms(10); 00170 Tm.lineFeed(); 00171 wait_ms(10); 00172 Tm.printf("Nomor Nota : %d", no_nota); 00173 wait_ms(10); 00174 Tm.lineFeed(); 00175 wait_ms(10); 00176 Tm.printf("Jenis BBM : %s", get_product(nozz).c_str()); 00177 wait_ms(10); 00178 Tm.lineFeed(); 00179 wait_ms(10); 00180 Tm.printf("Liter : %3.2f",liter); 00181 wait_ms(10); 00182 Tm.lineFeed(); 00183 wait_ms(10); 00184 Tm.printf("Harga/Liter : Rp. %s",intwcurrency(harga).c_str()); 00185 wait_ms(10); 00186 Tm.lineFeed(); 00187 wait_ms(10); 00188 Tm.printModes(0x10); 00189 wait_ms(10); 00190 Tm.printf("Total : Rp. %s",intwcurrency(total).c_str()); 00191 wait_ms(10); 00192 Tm.lineFeed(); 00193 wait_ms(10); 00194 Tm.printModes(0x00); 00195 wait_ms(10); 00196 Tm.printf("__________________________________"); 00197 wait_ms(10); 00198 Tm.lineFeed(); 00199 wait_ms(10); 00200 00201 if(Nopol.size()>0)Tm.printf("Nopol : %s",Nopol.c_str()); 00202 wait_ms(10); 00203 Tm.lineFeed(); 00204 wait_ms(10); 00205 00206 if(Odo.size()>0) Tm.printf("Odometer : %s",Odo.c_str()); 00207 wait_ms(10); 00208 Tm.lineFeed(); 00209 wait_ms(10); 00210 00211 wait_ms(50); 00212 // for(int i=0; i<Pf.footer.size(); i++) { 00213 // Tm.printf("%s\r", Pf.footer[i].c_str()); 00214 // wait_ms(10); 00215 // Tm.lineFeed(); 00216 // wait_ms(10); 00217 // } 00218 Tm.lineFeed(); 00219 wait_ms(10); 00220 Tm.lineFeed(); 00221 wait_ms(10); 00222 Tm.lineFeed(); 00223 wait_ms(10); 00224 Tm.lineFeed(); 00225 wait_ms(10); 00226 Tm.lineFeed(); 00227 wait_ms(10); 00228 Tm.lineFeed(); 00229 wait_ms(10); 00230 Tm.cutPaper(); 00231 create_header(); 00232 } 00233 00234 void Printer::PrintStruk(const std::time_t &now, const ResultParsing &res, const unsigned int &no_nota, 00235 const string &Nopol, const string &Odo) 00236 { 00237 float liter=0; 00238 unsigned int harga=0; 00239 unsigned long int total=0; 00240 char times[64]; 00241 liter = res.volume; 00242 harga = res.ppu; 00243 total = res.money; 00244 00245 if(res.id == 2 || res.id == 5) { 00246 harga = harga/10; 00247 total = total/10; 00248 } 00249 std::tm * ptm = std::localtime(&now); 00250 strftime (times,64,"%Y %H:%M:%S",ptm); 00251 wait_ms(100); 00252 00253 Tm.printf("%s, %02d %s %s", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); 00254 wait_ms(30); 00255 printf("time printed\r\n"); 00256 Tm.lineFeed(); 00257 wait_ms(30); 00258 Tm.printf("__________________________________"); 00259 printf("line printed\r\n"); 00260 wait_ms(30); 00261 Tm.lineFeed(); 00262 wait_ms(30); 00263 // Tm.printf("Nomor Printer: %d", Pf.id); 00264 // wait_ms(10); 00265 // Tm.lineFeed(); 00266 // wait_ms(10); 00267 Tm.printf("Nomor Selang : %d", res.id); 00268 printf("Selang printed\r\n"); 00269 00270 wait_ms(30); 00271 Tm.lineFeed(); 00272 wait_ms(30); 00273 Tm.printf("Nomor Nota : %d", no_nota); 00274 printf("Nomor Nota printed\r\n"); 00275 wait_ms(30); 00276 Tm.lineFeed(); 00277 wait_ms(30); 00278 Tm.printf("Jenis BBM : %s", res.product.c_str()); 00279 printf("Jenis BBM printed\r\n"); 00280 wait_ms(30); 00281 Tm.lineFeed(); 00282 wait_ms(30); 00283 Tm.printf("Liter : %3.2f",liter); 00284 printf("Liter printed\r\n"); 00285 wait_ms(30); 00286 Tm.lineFeed(); 00287 wait_ms(30); 00288 Tm.printf("Harga/Liter : Rp. %s",intwcurrency(harga).c_str()); 00289 printf("Harga/Liter printed\r\n"); 00290 wait_ms(30); 00291 Tm.lineFeed(); 00292 wait_ms(30); 00293 Tm.printModes(0x10); 00294 wait_ms(30); 00295 Tm.printf("Total : Rp. %s",intwcurrency(total).c_str()); 00296 printf("Total printed\r\n"); 00297 wait_ms(30); 00298 Tm.lineFeed(); 00299 wait_ms(30); 00300 Tm.printModes(0x00); 00301 wait_ms(30); 00302 Tm.printf("__________________________________"); 00303 printf("Line printed\r\n"); 00304 wait_ms(30); 00305 Tm.lineFeed(); 00306 wait_ms(30); 00307 00308 if(Nopol.size()>0) { 00309 Tm.printf("Nopol : %s",Nopol.c_str()); 00310 wait_ms(30); 00311 Tm.lineFeed(); 00312 wait_ms(30); 00313 } 00314 00315 if(Odo.size()>0) { 00316 Tm.printf("Odometer : %s",Odo.c_str()); 00317 wait_ms(30); 00318 Tm.lineFeed(); 00319 wait_ms(30); 00320 } 00321 00322 if(Nopol.size()>0 && Odo.size() >0) { 00323 Tm.printf("=================================="); 00324 wait_ms(30); 00325 Tm.lineFeed(); 00326 wait_ms(30); 00327 } 00328 printf("Line printed\r\n"); 00329 wait_ms(50); 00330 // for(int i=0; i<Pf.footer.size(); i++) { 00331 // Tm.printf("%s", Pf.footer[i].c_str()); 00332 // wait_ms(10); 00333 // Tm.lineFeed(); 00334 // wait_ms(10); 00335 // } 00336 wait_ms(30); 00337 Tm.lineFeed(); 00338 wait_ms(30); 00339 Tm.lineFeed(); 00340 wait_ms(30); 00341 Tm.lineFeed(); 00342 wait_ms(30); 00343 Tm.lineFeed(); 00344 wait_ms(30); 00345 Tm.lineFeed(); 00346 wait_ms(30); 00347 Tm.cutPaper(); 00348 wait_ms(50); 00349 create_header(); 00350 wait_ms(30); 00351 printf("Done\r\n"); 00352 } 00353 00354 void Printer::PrintStrukManual(const std::time_t &now, const ResultParsing &res, const unsigned int &no_nota) 00355 { 00356 float liter=0; 00357 unsigned int harga=0; 00358 unsigned long int total=0; 00359 char times[64]; 00360 00361 liter = res.volume; 00362 harga = res.ppu; 00363 total = res.money; 00364 00365 if(res.id == 2 || res.id == 5) { 00366 harga = harga/10; 00367 total = total/10; 00368 00369 } 00370 00371 std::tm * ptm = std::localtime(&now); 00372 strftime (times,64,"%Y %H:%M:%S",ptm); 00373 wait_ms(100); 00374 00375 Tm.printf("%s, %02d %s %s", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); 00376 wait_ms(10); 00377 Tm.lineFeed(); 00378 wait_ms(10); 00379 Tm.printf("__________________________________"); 00380 wait_ms(10); 00381 Tm.lineFeed(); 00382 wait_ms(10); 00383 Tm.printf("Nomor Printer: %d", Pf.id); 00384 wait_ms(10); 00385 Tm.lineFeed(); 00386 wait_ms(10); 00387 // Tm.printf("Nomor Selang : %d", res.id); 00388 // wait_ms(10); 00389 // Tm.lineFeed(); 00390 // wait_ms(10); 00391 Tm.printf("Nomor Nota : %d", no_nota); 00392 wait_ms(10); 00393 Tm.lineFeed(); 00394 wait_ms(10); 00395 Tm.printf("Jenis BBM : %s", res.product.c_str()); 00396 wait_ms(10); 00397 Tm.lineFeed(); 00398 wait_ms(10); 00399 Tm.printf("Liter : %3.2f",liter); 00400 wait_ms(10); 00401 Tm.lineFeed(); 00402 wait_ms(10); 00403 Tm.printf("Harga/Liter : Rp. %s",intwcurrency(harga).c_str()); 00404 wait_ms(10); 00405 Tm.lineFeed(); 00406 wait_ms(10); 00407 Tm.printModes(0x10); 00408 wait_ms(10); 00409 Tm.printf("Total : Rp. %s\n",intwcurrency(total).c_str()); 00410 wait_ms(10); 00411 Tm.printModes(0x00); 00412 wait_ms(10); 00413 Tm.printf("_________________________________"); 00414 wait_ms(10); 00415 Tm.lineFeed(); 00416 wait_ms(10); 00417 wait_ms(50); 00418 // for(int i=0; i<Pf.footer.size(); i++) { 00419 // Tm.printf("%s", Pf.footer[i].c_str()); 00420 // wait_ms(10); 00421 // Tm.lineFeed(); 00422 // wait_ms(10); 00423 // } 00424 Tm.lineFeed(); 00425 wait_ms(10); 00426 Tm.lineFeed(); 00427 wait_ms(10); 00428 Tm.lineFeed(); 00429 wait_ms(10); 00430 Tm.lineFeed(); 00431 wait_ms(10); 00432 Tm.lineFeed(); 00433 wait_ms(10); 00434 Tm.lineFeed(); 00435 wait_ms(10); 00436 Tm.cutPaper(); 00437 create_header(); 00438 } 00439 00440 void Printer::DebugStruk(const std::time_t &now, const ResultParsing &res, const unsigned int &no_nota, 00441 const string &Nopol, const string &Odo) 00442 { 00443 float liter=0; 00444 unsigned int harga=0; 00445 unsigned long int total=0; 00446 char times[64]; 00447 00448 liter = res.volume; 00449 harga = res.ppu; 00450 total = res.money; 00451 00452 std::tm * ptm = std::localtime(&now); 00453 strftime (times,64,"%Y %H:%M:%S",ptm); 00454 wait_ms(100); 00455 00456 dbg.printf("%s, %02d %s %s\n\r", WDAY[ptm->tm_wday], ptm->tm_mday, MONT[ptm->tm_mon], times); 00457 dbg.printf("__________________________________\n\r"); 00458 dbg.printf("Nomor Printer: %d\n\r", Pf.id); 00459 dbg.printf("Nomor Selang : %d\n\r", res.id); 00460 dbg.printf("Nomor Nota : %d\n\r", no_nota); 00461 dbg.printf("Jenis BBM : %s\n\r", res.product.c_str()); 00462 dbg.printf("Liter : %3.2f\n\r",liter); 00463 dbg.printf("Harga/Liter : Rp. %s\n\r",intwcurrency(harga).c_str()); 00464 dbg.printf("Total : Rp. %s\n\r",intwcurrency(total).c_str()); 00465 dbg.printf("_________________________________\n\r"); 00466 00467 if(Nopol.size()>0)dbg.printf("Nopol : %s\n\r",Nopol.c_str()); 00468 if(Odo.size()>0) dbg.printf("Odometer : %s\n\r",Odo.c_str()); 00469 00470 wait_ms(50); 00471 // for(int i=0; i<Pf.footer.size(); i++) { 00472 // dbg.printf("%s\r\n", Pf.footer[i].c_str()); 00473 // } 00474 dbg.printf("\n\n\r"); 00475 } 00476 00477 void Printer::TestPrint2() 00478 { 00479 create_header(); 00480 Tm.printf("_________________________________"); 00481 wait_ms(10); 00482 Tm.lineFeed(); 00483 for(int i=0; i<Pf.prodak.size(); i++) { 00484 Tm.printf("Produk %d : %s",i+1, Pf.prodak[i].c_str()); 00485 wait_ms(10); 00486 Tm.lineFeed(); 00487 wait_ms(10); 00488 } 00489 Tm.printf("_________________________________"); 00490 Tm.putc(0x0A); 00491 Tm.putc(0x0A); 00492 Tm.putc(0x0A); 00493 Tm.putc(0x0A); 00494 Tm.cutPaper(); 00495 }
Generated on Fri Jul 15 2022 16:19:39 by
1.7.2