//
//  StandardModeViewController.m
//  SDK212
//
//  Created by woosimsystems on 2016. 7. 04..
//  Copyright © 2016년 woosimsystems. All rights reserved.
//

#import "RootViewController.h"
#import "StandardModeViewController.h"
#import "WSSessionController.h"
#import "WSEncoder.h"

#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

WSEncoder *_wsSM;
NSMutableData *_printDataSM;

@implementation StandardModeViewController
- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setTitle:@"Standard Mode"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionDataReceived:) name:WSDataReceivedNotification object:nil];
    
    _sessionController = [[WSSessionController sharedController]init];
    _wsSM = [[WSEncoder alloc]init];
    
}


-(void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];
    
    [[EAAccessoryManager sharedAccessoryManager] unregisterForLocalNotifications];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:EAAccessoryDidDisconnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:EAAccessoryDidConnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:WSDataReceivedNotification object:nil];
    
    
    if(_sessionController != nil) _sessionController = nil;
    if(_wsSM != nil) _wsSM = nil;
    if (_printDataSM != nil) _printDataSM = nil;
    

}

- (void)_accessoryDidDisconnect:(NSNotification *)notification{
    
    [_sessionController closeSession];
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}



-(NSString *)getCurrentDate
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
    NSDate *date = [[NSDate alloc]init];
    NSLocale *local = [[NSLocale alloc]initWithLocaleIdentifier:@"ko_KO"];
    [dateFormatter setLocale:local];
    
    return [dateFormatter stringFromDate:date];
}

-(IBAction)Btn_Align:(id)sender
{

    _printDataSM = [[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];
    
    [_printDataSM appendData:[_wsSM addString:@"* Align" encoding:NSASCIIStringEncoding]];
    
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"Left" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_CENTER]];
    [_printDataSM appendData:[_wsSM addString:@"Center" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"Right" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"AAA" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_CENTER]];
    [_printDataSM appendData:[_wsSM addString:@"BBB" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"CCC" encoding:NSASCIIStringEncoding]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
   
    [_sessionController writeData:_printDataSM];

}

-(IBAction)Btn_LeftMargin:(id)sender
{

    _printDataSM = [[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];

    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    [_printDataSM appendData:[_wsSM addString:@"* Left Margin" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM setLeftMarginInStandardMode:30]];
    [_printDataSM appendData:[_wsSM addString:@"Margin: 30dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM setLeftMarginInStandardMode:50]];
    [_printDataSM appendData:[_wsSM addString:@"Margin: 50dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setLeftMarginInStandardMode:0]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
     
    
    
    [_sessionController writeData:_printDataSM];

    
}

-(IBAction)Btn_PrintableArea:(id)sender
{

    _printDataSM = [[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"* Printable Area" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setPrintableAreaWidthInStandardMode:150]];
    [_printDataSM appendData:[_wsSM addString:@"Printable Area: 150dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setPrintableAreaWidthInStandardMode:300]];
    [_printDataSM appendData:[_wsSM addString:@"Printable Area: 300dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_sessionController writeData:_printDataSM];
   
  
}

-(IBAction)Btn_Upsidedown:(id)sender
{
    _printDataSM = [[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];

    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"* Turn upside-down mode off" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM addString:@"AAA" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"BBB" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"CCC" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setPrintingUpsideDownInStandardMode:YES]];
    [_printDataSM appendData:[_wsSM addString:@"*Turn upside-down mode on" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM addString:@"AAA" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"BBB" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"CCC" encoding:NSASCIIStringEncoding]];
    
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM setPrintingUpsideDownInStandardMode:NO]];
    
    [_sessionController writeData:_printDataSM];
    
}

-(IBAction)Btn_Image:(id)sender
{

    _printDataSM =[[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"*Image" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"woosim" ofType:@"bmp"]];
    [_printDataSM appendData:[_wsSM addString:@"Shift: 0 dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM createImageInStandardMode:[image CGImage] withShiftPosition:0 withDithering:YES]];
    [_printDataSM appendData:[_wsSM printImageInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
   
    [_printDataSM appendData:[_wsSM addString:@"Shift: 25 dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM createImageInStandardMode:[image CGImage] withShiftPosition:25 withDithering:YES]];
    [_printDataSM appendData:[_wsSM printImageInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM addString:@"Shift: 50 dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM createImageInStandardMode:[image CGImage] withShiftPosition:50 withDithering:YES]];
    [_printDataSM appendData:[_wsSM printImageInStandardMode]];
    
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_sessionController writeData:_printDataSM];

}


-(IBAction)Btn_PrintData:(id)sender
{
    
    _printDataSM = [[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];
    
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"* Print Data" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"AAA" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"BBB" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"CCC" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_sessionController writeData:_printDataSM];

}

-(IBAction)Btn_FeedPaperNDots:(id)sender
{

    _printDataSM = [[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];
    
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"* Print and feed paper n dots." encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Start feeding 20dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNDotInStandardMode:20]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Feed 20dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Start feeding 100dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNDotInStandardMode:100]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Feed 100dot" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_sessionController writeData:_printDataSM];

}

-(IBAction)Btn_FeedPaperNLines:(id)sender
{
    _printDataSM = [[NSMutableData alloc]init];
    
    _wsSM = [[WSEncoder alloc]init];
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"Print and feed paper n lines" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM addString:@"Start feeding 2 lins" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:2]];
    [_printDataSM appendData:[_wsSM addString:@"Feed 2 lines" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Start feeding 5 lines" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:5]];
    [_printDataSM appendData:[_wsSM addString:@"Feed 5 lines" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:5]];
    
    [_sessionController writeData:_printDataSM];
    
}

-(IBAction)Btn_Sample:(id)sender
{
    _printDataSM = [[NSMutableData alloc]init];
    WSEncoder *_wsSM = [[WSEncoder alloc]init];
    
    NSString *line = @"--------------------------------";
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    //font size
    [_printDataSM appendData:[_wsSM setFontSize:FONTSIZE_A]];
    
    //2inch printer: 384dot, 3inch printer: 576dot, 4inch printer: 832dot
    [_printDataSM appendData:[_wsSM setPrintableAreaWidthInStandardMode:384]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_CENTER]];
    [_printDataSM appendData:[_wsSM setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_2]];
    [_printDataSM appendData:[_wsSM setTextBold:YES]];
    [_printDataSM appendData:[_wsSM addString:@"Sales Receipt" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM shiftAbsolutePosition:[_wsSM changeDotFromCentimeter:3.7]]];
    [_printDataSM appendData:[_wsSM createBarcodeQRCode:@"http://woosim.com" symbolVersion:0 ECLevel:'Q' moduleSize:3]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:2]];
    
    //Address
    [_printDataSM appendData:[_wsSM setTextSizeWithWidth:TEXTWIDTH_1 withHeight:TEXTHEIGHT_1]];
    [_printDataSM appendData:[_wsSM setTextBold:NO]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"MERCHANT NAME" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"woosim coffee" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"MASTER" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"Gil-dong Hong" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"ADDRESS" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"#501, Daerung Techno" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM addString:@"town 3rd 448,Gasan-dong" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Gumcheon-gu Seoul Korea" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"HELP DESK" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"(+82-2)2107-3721" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    
    [_printDataSM appendData:[_wsSM addString:line encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"Product" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM shiftAbsolutePosition:[_wsSM changeDotFromCentimeter:2.3]]];
    [_printDataSM appendData:[_wsSM addString:@"Sale" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"Price" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:line encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:1]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM setLeftMarginInStandardMode:20]];
    [_printDataSM appendData:[_wsSM addString:@"Cafe mocha" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM shiftAbsolutePosition:[_wsSM changeDotFromCentimeter:2.2]]];
    [_printDataSM appendData:[_wsSM addString:@"2" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString: @"7.5$" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"Cafe latte" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM shiftAbsolutePosition:[_wsSM changeDotFromCentimeter:2.2]]];
    [_printDataSM appendData:[_wsSM addString:@"1" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString: @"7.0$" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"Cappucino" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM shiftAbsolutePosition:[_wsSM changeDotFromCentimeter:2.2]]];
    [_printDataSM appendData:[_wsSM addString:@"1" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString: @"7.0$" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:1]];
    
    
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM setLeftMarginInStandardMode:0]];
    
    [_printDataSM appendData:[_wsSM addString:line encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM addString:@"Total" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"29.0$" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:2]];
    [_printDataSM appendData:[_wsSM setTextAlignInStandardMode:ALIGN_LEFT]];
    
    //print image
    UIImage *logo = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"bmp"]];
    [_printDataSM appendData:[_wsSM createImageInStandardMode:[logo CGImage] withShiftPosition:0 withDithering:YES]];
    [_printDataSM appendData:[_wsSM printImageInStandardMode]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:1]];
    
    //1D Barcode
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"MMddyyyyHHmmssZ"];
    NSDate *now = [NSDate date];
    NSString *dateStr = [dateFormat stringFromDate:now];
    [_printDataSM appendData:[_wsSM shiftAbsolutePosition:25]];
    [_printDataSM appendData:[_wsSM createBarcode:dateStr barcodeType:BARCODE_CODE128]];
    [_printDataSM appendData:[_wsSM printAndFeedNLineInStandardMode:5]];
    
    [_sessionController writeData:_printDataSM];
}

-(IBAction)Btn_AlignImage:(id)sender
{

    _printDataSM =[[NSMutableData alloc]init];
    _wsSM = [[WSEncoder alloc]init];
    [_printDataSM appendData:[_wsSM clearPrinterBuffer]];
    
    [_printDataSM appendData:[_wsSM addString:@"*Image" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"woosim" ofType:@"bmp"]];
    
    [_printDataSM appendData:[_wsSM setAlignInStandardMode:ALIGN_RIGHT]];
    [_printDataSM appendData:[_wsSM addString:@"Right" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printCompressedImageInStandardMode:[image CGImage] withShiftPosition:0x00 withDithering:YES]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setAlignInStandardMode:ALIGN_CENTER]];
    [_printDataSM appendData:[_wsSM addString:@"Center" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printCompressedImageInStandardMode:[image CGImage] withDithering:NO]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    
    [_printDataSM appendData:[_wsSM setAlignInStandardMode:ALIGN_LEFT]];
    [_printDataSM appendData:[_wsSM addString:@"Left" encoding:NSASCIIStringEncoding]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printCompressedImageInStandardMode:[image CGImage] withDithering:NO]];
   
    
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
    [_printDataSM appendData:[_wsSM printDataInStandardMode]];
  
    [_sessionController writeData:_printDataSM];

}



@end
