|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author Giancarlo Voci
|
|
* @author Giancarlo Voci
|
|
|
* @date 28/03/2018
|
|
* @date 28/03/2018
|
|
@@ -11,173 +12,176 @@ use Generator;
|
|
|
|
|
|
|
|
class SmartESL
|
|
class SmartESL
|
|
|
{
|
|
{
|
|
|
- /** @var FindBoxCoreSystem $core */
|
|
|
|
|
- protected $core;
|
|
|
|
|
-
|
|
|
|
|
- /** @var array $labels */
|
|
|
|
|
- protected $labels;
|
|
|
|
|
-
|
|
|
|
|
- /** @var array $labelProperties */
|
|
|
|
|
- protected $labelProperties;
|
|
|
|
|
-
|
|
|
|
|
- public function __construct(FindBoxCoreSystem $coreL, array $LabelID)
|
|
|
|
|
- {
|
|
|
|
|
- $this->core = $coreL;
|
|
|
|
|
- $this->labels = array_map('strtoupper', $LabelID);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Request to label(s) its properties
|
|
|
|
|
- *
|
|
|
|
|
- * @param bool $force request directly to ESL
|
|
|
|
|
- * @return null|object Details
|
|
|
|
|
- */
|
|
|
|
|
- public function GetStatus(bool $force = false)
|
|
|
|
|
- {
|
|
|
|
|
- $labels = json_encode($this->labels);
|
|
|
|
|
- //$URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
|
|
|
|
|
- $forceStr = var_export($force, true);
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.getstatus/4.0.0/[{$labels},{$forceStr}]";
|
|
|
|
|
- $ret = $this->core->CallAPI($URI, '');
|
|
|
|
|
- if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
|
|
|
|
|
- // Update current properties
|
|
|
|
|
- $this->labelProperties = $ret['value']['value'];
|
|
|
|
|
- return $this->labelProperties;
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Get label version splitted into the three components major, minor, patch
|
|
|
|
|
- *
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function GetVersion()
|
|
|
|
|
- {
|
|
|
|
|
- $softVersion = $this->labelProperties[array_keys($this->labelProperties)[0]]['status'];
|
|
|
|
|
- return array_values(array_filter_keys($softVersion, ['soft_major', 'soft_minor', 'soft_patch']));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function AsyncBlinkOff(): Generator
|
|
|
|
|
- {
|
|
|
|
|
- global $f3;
|
|
|
|
|
- return $this->AsyncBlinkSpecial(2, 1, 1000, 1, $f3->BLINKOFF_COLOR);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Blink the label with parameters.
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $pattern
|
|
|
|
|
- * @param int $repeat
|
|
|
|
|
- * @param int $iter_time
|
|
|
|
|
- * @param int $iterations
|
|
|
|
|
- * @param int|0 $ledColor
|
|
|
|
|
- * @return Generator
|
|
|
|
|
- */
|
|
|
|
|
- public function AsyncBlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = 0): Generator
|
|
|
|
|
- {
|
|
|
|
|
- $uriParams = json_encode(array_merge(
|
|
|
|
|
- array($this->labels),
|
|
|
|
|
- array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)));
|
|
|
|
|
-
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
|
|
|
|
|
- return $this->core->AsyncCallAPI($URI, $uriParams);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function getData()
|
|
|
|
|
- {
|
|
|
|
|
- return $this->labelProperties[$this->labels[0]]['data'];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Turn off led(s)
|
|
|
|
|
- */
|
|
|
|
|
- public function BlinkOff()
|
|
|
|
|
- {
|
|
|
|
|
- global $f3;
|
|
|
|
|
- return $this->BlinkSpecial(2, 1, 1000, 1, $f3->BLINKOFF_COLOR);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Blink the label with parameters.
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $pattern
|
|
|
|
|
- * @param int $repeat
|
|
|
|
|
- * @param int $iter_time
|
|
|
|
|
- * @param int $iterations
|
|
|
|
|
- * @param int|0 $ledColor
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function BlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = 0)
|
|
|
|
|
- {
|
|
|
|
|
- $uriParams = json_encode(array_merge(
|
|
|
|
|
- array($this->labels),
|
|
|
|
|
- array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)));
|
|
|
|
|
-
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
|
|
|
|
|
- return $this->core->CallAPI($URI, $uriParams);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function Display(string $templateId, string $barcode)
|
|
|
|
|
- {
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.display/2.3.0/";
|
|
|
|
|
- $params = json_encode(array(
|
|
|
|
|
- $this->labels[0],
|
|
|
|
|
- $barcode,
|
|
|
|
|
- [],
|
|
|
|
|
- $templateId,
|
|
|
|
|
- 1, 1));
|
|
|
|
|
-
|
|
|
|
|
- return $this->core->CallAPI($URI, $params);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Set ESL display using displayimage CORE API
|
|
|
|
|
- *
|
|
|
|
|
- * @param string $binaryImage
|
|
|
|
|
- * @param int $pageNum
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function SetPageImage(string $binaryImage, int $pageNum = 1)
|
|
|
|
|
- {
|
|
|
|
|
- $imageb64 = base64_encode($binaryImage);
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.displayimage/1.1.1/";
|
|
|
|
|
-
|
|
|
|
|
- $params = json_encode([array_map(function ($label) use ($pageNum, $imageb64) {
|
|
|
|
|
- return [
|
|
|
|
|
- 'label_id' => $label,
|
|
|
|
|
- 'image' => $imageb64,
|
|
|
|
|
- 'page' => $pageNum
|
|
|
|
|
- ];
|
|
|
|
|
- }, $this->labels)]);
|
|
|
|
|
-
|
|
|
|
|
- return $this->core->CallAPI($URI, $params);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Switch to ESL page $pageNum
|
|
|
|
|
- *
|
|
|
|
|
- * @param int $pageNum
|
|
|
|
|
- * @return array
|
|
|
|
|
- */
|
|
|
|
|
- public function SwitchPage(int $pageNum = 1)
|
|
|
|
|
- {
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.switchpage/1.1.0/";
|
|
|
|
|
-
|
|
|
|
|
- $params = json_encode([array_map(function ($label) use ($pageNum) {
|
|
|
|
|
- return [
|
|
|
|
|
- 'label_id' => $label,
|
|
|
|
|
- 'page' => $pageNum
|
|
|
|
|
- ];
|
|
|
|
|
- }, $this->labels)]);
|
|
|
|
|
-
|
|
|
|
|
- return $this->core->CallAPI($URI, $params);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function GetLabelMatch()
|
|
|
|
|
- {
|
|
|
|
|
- $URI = "/1.0.0/index.php/smartesl.getlabelmatch/1.2.0/";
|
|
|
|
|
- return $this->core->CallAPI($URI, json_encode(array($this->labels)));
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ /** @var FindBoxCoreSystem $core */
|
|
|
|
|
+ protected $core;
|
|
|
|
|
+
|
|
|
|
|
+ /** @var array $labels */
|
|
|
|
|
+ protected $labels;
|
|
|
|
|
+
|
|
|
|
|
+ /** @var array $labelProperties */
|
|
|
|
|
+ protected $labelProperties;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct(FindBoxCoreSystem $coreL, array $LabelID)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->core = $coreL;
|
|
|
|
|
+ $this->labels = array_map('strtoupper', $LabelID);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Request to label(s) its properties
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bool $force request directly to ESL
|
|
|
|
|
+ * @return null|array Details
|
|
|
|
|
+ */
|
|
|
|
|
+ public function GetStatus(bool $force = false)
|
|
|
|
|
+ {
|
|
|
|
|
+ $labels = json_encode($this->labels);
|
|
|
|
|
+ //$URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
|
|
|
|
|
+ $forceStr = var_export($force, true);
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.getstatus/4.0.0/[{$labels},{$forceStr}]";
|
|
|
|
|
+ $ret = $this->core->CallAPI($URI, '');
|
|
|
|
|
+ if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
|
|
|
|
|
+ // Update current properties
|
|
|
|
|
+ $this->labelProperties = $ret['value']['value'];
|
|
|
|
|
+ return $this->labelProperties;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Get label version splitted into the three components major, minor, patch
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function GetVersion()
|
|
|
|
|
+ {
|
|
|
|
|
+ $softVersion = $this->labelProperties[array_keys($this->labelProperties)[0]]['status'];
|
|
|
|
|
+ return array_values(array_filter_keys($softVersion, ['soft_major', 'soft_minor', 'soft_patch']));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function AsyncBlinkOff(): Generator
|
|
|
|
|
+ {
|
|
|
|
|
+ global $f3;
|
|
|
|
|
+ return $this->AsyncBlinkSpecial(2, 1, 1000, 1, $f3->BLINKOFF_COLOR);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Blink the label with parameters.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $pattern
|
|
|
|
|
+ * @param int $repeat
|
|
|
|
|
+ * @param int $iter_time
|
|
|
|
|
+ * @param int $iterations
|
|
|
|
|
+ * @param int|0 $ledColor
|
|
|
|
|
+ * @return Generator
|
|
|
|
|
+ */
|
|
|
|
|
+ public function AsyncBlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = 0): Generator
|
|
|
|
|
+ {
|
|
|
|
|
+ $uriParams = json_encode(array_merge(
|
|
|
|
|
+ array($this->labels),
|
|
|
|
|
+ array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
|
|
|
|
|
+ return $this->core->AsyncCallAPI($URI, $uriParams);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getData()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->labelProperties[$this->labels[0]]['data'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Turn off led(s)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function BlinkOff()
|
|
|
|
|
+ {
|
|
|
|
|
+ global $f3;
|
|
|
|
|
+ return $this->BlinkSpecial(2, 1, 1000, 1, $f3->BLINKOFF_COLOR);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Blink the label with parameters.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $pattern
|
|
|
|
|
+ * @param int $repeat
|
|
|
|
|
+ * @param int $iter_time
|
|
|
|
|
+ * @param int $iterations
|
|
|
|
|
+ * @param int|0 $ledColor
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function BlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ $uriParams = json_encode(array_merge(
|
|
|
|
|
+ array($this->labels),
|
|
|
|
|
+ array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
|
|
|
|
|
+ return $this->core->CallAPI($URI, $uriParams);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function Display(string $templateId, string $barcode)
|
|
|
|
|
+ {
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.display/2.3.0/";
|
|
|
|
|
+ $params = json_encode(array(
|
|
|
|
|
+ $this->labels[0],
|
|
|
|
|
+ $barcode,
|
|
|
|
|
+ [],
|
|
|
|
|
+ $templateId,
|
|
|
|
|
+ 1, 1
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ return $this->core->CallAPI($URI, $params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Set ESL display using displayimage CORE API
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $binaryImage
|
|
|
|
|
+ * @param int $pageNum
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function SetPageImage(string $binaryImage, int $pageNum = 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ $imageb64 = base64_encode($binaryImage);
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.displayimage/1.1.1/";
|
|
|
|
|
+
|
|
|
|
|
+ $params = json_encode([array_map(function ($label) use ($pageNum, $imageb64) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'label_id' => $label,
|
|
|
|
|
+ 'image' => $imageb64,
|
|
|
|
|
+ 'page' => $pageNum
|
|
|
|
|
+ ];
|
|
|
|
|
+ }, $this->labels)]);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->core->CallAPI($URI, $params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Switch to ESL page $pageNum
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $pageNum
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function SwitchPage(int $pageNum = 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.switchpage/1.1.0/";
|
|
|
|
|
+
|
|
|
|
|
+ $params = json_encode([array_map(function ($label) use ($pageNum) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'label_id' => $label,
|
|
|
|
|
+ 'page' => $pageNum
|
|
|
|
|
+ ];
|
|
|
|
|
+ }, $this->labels)]);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->core->CallAPI($URI, $params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function GetLabelMatch()
|
|
|
|
|
+ {
|
|
|
|
|
+ $URI = "/1.0.0/index.php/smartesl.getlabelmatch/1.2.0/";
|
|
|
|
|
+ return $this->core->CallAPI($URI, json_encode(array($this->labels)));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|