//
//  ViewController_PtrButtonAction.m
//  sample
//
//  Created by savin on 13. 8. 7..
//  Copyright (c) 2013 savin. All rights reserved.
//

#define _USE_LINESPACE_ENTER 0

#ifdef _PRINTER_BUTTON_ACTIONS_



- (IBAction) buttonUp_PrintText:(id)sender
{
    NSLog(@" PrintText Button Up.");
    [_pController printText:@"This is Default Text\r\n\r\n"];
//    _pController.attribute = BXL_FT_BOLD;
//    nResult = [_pController printText:@"This is Bold Text\r\n\r\n"];
//    _pController.attribute = BXL_FT_UNDERLINE;
//    nResult = [_pController printText:@"This is underline Text\r\n\r\n"];
//
//    _pController.alignment = BXL_ALIGNMENT_CENTER;
//    _pController.attribute = BXL_FT_BOLD|BXL_FT_FONTB;
//    _pController.textSize = BXL_TS_1WIDTH|BXL_TS_1HEIGHT;
//    nResult = [_pController printText:@"This is Printing Sample2\r\n\r\n"];
//
//    NSLog(@"result : %ld", (long) nResult);
//    _pController.alignment = BXL_ALIGNMENT_LEFT;
//    _pController.attribute = BXL_FT_DEFAULT;
//    _pController.textSize = BXL_TS_0WIDTH|BXL_TS_0HEIGHT;
//    nResult = [_pController printText:@"This is Printing Sample2\r\n\r\n"];
//    NSLog(@"result : %ld", (long) nResult);

    [_pController lineFeed:3];
    
}

- (IBAction) buttonUp_DirectIO:(id)sender
{
    
    // Add 15
    //  Keyboard Hidden
    if ([_uiDirectIoInput isFirstResponder]) {
        [_uiDirectIoInput resignFirstResponder];
    }
    
    //  Data Create & string to hexa
    const char *buf = [[_uiDirectIoInput text] UTF8String];
    NSMutableData *sendData = [NSMutableData data];
    if (buf)
    {
        uint32_t len = strlen(buf);
        
        char singleNumberString[3] = {'\0', '\0', '\0'};
        uint32_t singleNumber = 0;
        for(uint32_t i = 0 ; i < len; i+=2)
        {
            if ( ((i+1) < len) && isxdigit(buf[i]) && (isxdigit(buf[i+1])) )
            {
                singleNumberString[0] = buf[i];
                singleNumberString[1] = buf[i + 1];
                sscanf(singleNumberString, "%x", &singleNumber);
                uint8_t tmp = (uint8_t)(singleNumber & 0x000000FF);
                [sendData appendBytes:(void *)(&tmp) length:1];
            }
            else
            {
                break;
            }
        }
        
    }
    
    //  Send
    [_pController directIO:sendData requiredSize:0 response:nil];
}

- (IBAction) buttonUp_PrintBarcode:(id)sender
{
    NSLog(@" PrintBarcode Button Up.");
    
    //Add 12
    [_pController printBarcode:"1234567890123456789012"
                     symbology:BXL_BCS_ITF
                         width:2
                        height:100];
}


- (IBAction) buttonUp_NextPrintPos:(id)sender
{
    NSLog(@" NextPrintPos Button Up.");
    //Add 16
	[_pController nextPrintPos];
    
}

- (IBAction) buttonUp_Disconnect:(id)sender
{
    NSLog(@" Disconnect Button Up.[NSThread isMainThread] = %d",[NSThread isMainThread]);
   
    [_pController disconnect];
    
    if( _pMyCustomTarget )
    {
        [_pMyCustomTarget release];
        _pMyCustomTarget = nil;
    }

}


#endif
