Skip to content

Commit

Permalink
refactor: update add pulse params
Browse files Browse the repository at this point in the history
  • Loading branch information
tr3v3r committed Nov 18, 2021
1 parent 2bc21eb commit 4a29d6e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void performDiscovery(MyCallbackInterface callback, ReadableMap paramsMa
final Handler handler = new Handler();

// Default to 5000 if the value is not passed.
int scanningTimeout = 5000
int scanningTimeout = 5000;

if (paramsMap != null) {
if (paramsMap.hasKey("scanningTimeoutAndroid")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public Map<String, Object> getConstants() {
constants.put("EPOS2_HALFTONE_ERROR_DIFFUSION", Printer.HALFTONE_ERROR_DIFFUSION);
constants.put("EPOS2_HALFTONE_THRESHOLD", Printer.HALFTONE_THRESHOLD);

// Add pulse settings
constants.put("EPOS2_DRAWER_2PIN", Printer.DRAWER_2PIN);
constants.put("EPOS2_DRAWER_5PIN", Printer.DRAWER_5PIN);

return constants;
}

Expand Down Expand Up @@ -596,8 +600,7 @@ private void handleCommand(int command, ReadableArray params) throws Epos2Except
mPrinter.addText(params.getString(0));
break;
case PrintingCommands.COMMAND_ADD_PULSE:
String pinNumber = params.getString(0);
mPrinter.addPulse(pinNumber, Printer.PARAM_DEFAULT);
mPrinter.addPulse(params.getInt(0), Printer.PARAM_DEFAULT);
break;
case PrintingCommands.COMMAND_ADD_NEW_LINE:
mPrinter.addFeedLine(params.getInt(0));
Expand Down
9 changes: 6 additions & 3 deletions ios/EscPosPrinter.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ - (NSDictionary *)constantsToExport
@"EPOS2_HALFTONE_DITHER": @(EPOS2_HALFTONE_DITHER),
@"EPOS2_HALFTONE_ERROR_DIFFUSION": @(EPOS2_HALFTONE_ERROR_DIFFUSION),
@"EPOS2_HALFTONE_THRESHOLD": @(EPOS2_HALFTONE_THRESHOLD),

// Add pulse settings
@"EPOS2_DRAWER_2PIN": @(EPOS2_DRAWER_2PIN),
@"EPOS2_DRAWER_5PIN": @(EPOS2_DRAWER_5PIN),
};
}

Expand Down Expand Up @@ -550,9 +554,8 @@ - (enum Epos2ErrorStatus)handleCommand: (enum PrintingCommands)command params:(N
case COMMAND_ADD_NEW_LINE :
result = [self->printer addFeedLine:[params[0] intValue]];
break;
case COMMAND_ADD_PULSE :
pinNumber = params[0];
result = [self->printer addPulse:pinNumber time:EPOS2_PARAM_DEFAULT];
case COMMAND_ADD_PULSE :
result = [self->printer addPulse:[params[0] intValue] time:EPOS2_PARAM_DEFAULT];
break;
case COMMAND_ADD_TEXT_STYLE :
result = [self->printer addTextStyle:EPOS2_FALSE ul:[params[0] intValue] em:[params[1] intValue] color:EPOS2_COLOR_1];
Expand Down
10 changes: 10 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
EposColor,
EposMode,
EposHalftone,
DrawerKickConnector,
} from './types';

const { EscPosPrinter } = NativeModules;
Expand Down Expand Up @@ -104,6 +105,8 @@ const {
EPOS2_HALFTONE_DITHER,
EPOS2_HALFTONE_ERROR_DIFFUSION,
EPOS2_HALFTONE_THRESHOLD,
EPOS2_DRAWER_2PIN,
EPOS2_DRAWER_5PIN,
} = nativeConstants;

export const PRINTING_COMMANDS = {
Expand Down Expand Up @@ -332,3 +335,10 @@ export const EPOS_HALFTONE: { [key in EposHalftone]: number } = {
EPOS2_HALFTONE_ERROR_DIFFUSION,
EPOS2_HALFTONE_THRESHOLD,
};

export const EPOS_DRAWER_KICK_CONNECTOR: {
[key in DrawerKickConnector]: number;
} = {
EPOS2_DRAWER_2PIN,
EPOS2_DRAWER_5PIN,
};
9 changes: 7 additions & 2 deletions src/printing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
BarcodeParams,
QRCodeParams,
ImagePrintParams,
DrawerKickConnector,
} from './types';
import {
BufferHelper,
Expand Down Expand Up @@ -486,8 +487,12 @@ class Printing {
* @return {object} Return the object, for easy chaining commands
*
*/
addPulse(pinNumber?: string) {
this._queue([PRINTING_COMMANDS.COMMAND_ADD_PULSE, [pinNumber || 'EPOS2_PARAM_DEFAULT']]);
addPulse(drawerKickConnector: DrawerKickConnector = 'EPOS2_DRAWER_2PIN') {
assertNativeCommands([drawerKickConnector], 'addPulse');
this._queue([
PRINTING_COMMANDS.COMMAND_ADD_PULSE,
[getNativeCommand(drawerKickConnector)],
]);

return this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export type EposHalftone =
| 'EPOS2_HALFTONE_ERROR_DIFFUSION'
| 'EPOS2_HALFTONE_THRESHOLD';

export type DrawerKickConnector = 'EPOS2_DRAWER_2PIN' | 'EPOS2_DRAWER_5PIN';

export interface ImagePrintParams {
width: number;
color?: EposColor;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getNativeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nativeConstants } from '../constants';

export function getNativeCommand(command: string) {
export function getNativeCommand(command: string): number {
return nativeConstants[command];
}

0 comments on commit 4a29d6e

Please sign in to comment.