Skip to content

Commit

Permalink
feat(added): add addFeedLine method, add docs (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
tr3v3r authored Jul 30, 2024
1 parent cd3dde5 commit 4eed3b8
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ synchronized public void addFeedLine(String target, int line, Promise promise) {
}
}

@ReactMethod
synchronized public void addLineSpace(String target, int linespc, Promise promise) {
ThePrinter thePrinter = thePrinterManager_.getObject(target);
if (thePrinter == null) {
promise.reject(EposStringHelper.getErrorTextData(ERR_INIT, ""));
} else {
try {
thePrinter.addLineSpace(linespc);
promise.resolve(null);
} catch(Exception e) {
processError(promise, e, "");
}
}
}

@ReactMethod
synchronized public void addCut(String target, int type, Promise promise) {
ThePrinter thePrinter = thePrinterManager_.getObject(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ synchronized public void addFeedLine(int line) throws Epos2Exception {
epos2Printer_.addFeedLine(line);
}

synchronized public void addLineSpace(int linespc) throws Epos2Exception {
if (epos2Printer_ == null) throw new Epos2Exception(Epos2Exception.ERR_MEMORY);

epos2Printer_.addLineSpace(linespc);
}

synchronized public void addCut(int type) throws Epos2Exception {
if (epos2Printer_ == null) throw new Epos2Exception(Epos2Exception.ERR_MEMORY);

Expand Down
11 changes: 11 additions & 0 deletions docs/printer/Printer.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ Adds a paper-feed-by-line command to the command buffer.
await printerInstance.addFeedLine(3);
```

---
### [addLineSpace(`linespc: number`): `Promise<void>`](./addLineSpace.md)

Adds line spacing setting to the command buffer.

#### Example

```typescript
await printerInstance.addLineSpace(50);
```

---
### [sendData(`timeout?: number`): `Promise<PrinterStatusResponse>`](./sendData.md)

Expand Down
32 changes: 32 additions & 0 deletions docs/printer/addLineSpace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## addLineSpace

Adds line spacing setting to the command buffer.

### Parameters

#### linespc

- `number`

Specifies the line spacing (in dots).

| **Value** | **Description** |
| --- | --- |
| 0 to 255 | Line spacing (in dots) |

### Returns

`Promise<void>`

### Errors

| **Error status** | **Description** |
| --- | --- |
| ERR_PARAM | An invalid parameter was passed. |
| ERR_TIMEOUT | Failed to communicate with the devices within the specified time. |
| ERR_MEMORY | Necessary memory could not be allocated. |

### Supplementary explanation

- If the line spacing for a single line is set smaller than the print character size, paper may be fed for a larger quantity than the set amount to ensure proper printing.

4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ PODS:
- React-jsinspector (0.72.6)
- React-logger (0.72.6):
- glog
- react-native-esc-pos-printer (4.0.0):
- react-native-esc-pos-printer (4.0.1):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-image-picker (7.1.0):
Expand Down Expand Up @@ -605,7 +605,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 3bf18ff7cb03cd8dfdce08fbbc0d15058c1d71ae
React-jsinspector: 194e32c6aab382d88713ad3dd0025c5f5c4ee072
React-logger: cebf22b6cf43434e471dc561e5911b40ac01d289
react-native-esc-pos-printer: 7d9eadb4e6a43b01515defe2bc4ad897e1d83145
react-native-esc-pos-printer: 71506d7f9081fe378901ad0e685cd118831eaf6d
react-native-image-picker: 5e076db26cd81660cfb6db5bcf517cfa12054d45
react-native-safe-area-context: 2cd91d532de12acdb0a9cbc8d43ac72a8e4c897c
React-NativeModulesApple: 02e35e9a51e10c6422f04f5e4076a7c02243fff2
Expand Down
22 changes: 22 additions & 0 deletions ios/EscPosPrinter.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ + (BOOL)requiresMainQueueSetup
}
}

RCT_EXPORT_METHOD(addLineSpace: (nonnull NSString*) target
linespc: (int) linespc
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
{
int result = EPOS2_SUCCESS;
@synchronized (self) {
ThePrinter* thePrinter = [objManager_ getObject:target];
if (thePrinter == nil) {
result = [EposStringHelper getInitErrorResultCode];
} else {
result = [thePrinter addLineSpace:linespc];
}

if(result == EPOS2_SUCCESS) {
resolve(nil);
} else {
reject(@"event_failure", [@(result) stringValue], nil);
}
}
}

RCT_EXPORT_METHOD(addCut: (nonnull NSString*) target
type: (int)type
withResolver:(RCTPromiseResolveBlock)resolve
Expand Down
2 changes: 2 additions & 0 deletions ios/ThePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

-(int) addFeedLine: (int)line;

-(int) addLineSpace: (int)linespc;

-(int) addCut: (int)type;

-(int) addCommand: (nonnull NSString* )base64string;
Expand Down
12 changes: 12 additions & 0 deletions ios/ThePrinter.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ -(int) addFeedLine: (int)line;
}
}

-(int) addLineSpace: (int)linespc;
{
@synchronized (self) {
if (epos2Printer_ == nil) {
return EPOS2_ERR_MEMORY;
}

int result = [epos2Printer_ addLineSpace: linespc];
return result;
}
}

-(int) addCommand: (NSString* )base64string;
{
@synchronized (self) {
Expand Down
4 changes: 4 additions & 0 deletions src/printer/Printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export class Printer {
return this.printerWrapper.addFeedLine(line);
};

addLineSpace = (linespc: number) => {
return this.printerWrapper.addLineSpace(linespc);
};

sendData = (timeout?: number) => {
return this.printerWrapper.sendData(timeout);
};
Expand Down
12 changes: 12 additions & 0 deletions src/printer/PrinterWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ export class PrinterWrapper {
}
};

addLineSpace = async (linespc: number) => {
try {
await EscPosPrinter.addLineSpace(this.target, linespc);
} catch (error) {
throwProcessedError({
methodName: 'addLineSpace',
errorCode: error.message,
messagesMapping: CommonOperationErrorMessageMapping,
});
}
};

addCut = async (type: AddCutTypeParam = PrinterConstants.PARAM_DEFAULT) => {
try {
await EscPosPrinter.addCut(this.target, type);
Expand Down

0 comments on commit 4eed3b8

Please sign in to comment.