| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- /**
- * @author Giancarlo Voci
- * @date 28/03/2018
- * @time 09:09
- */
- namespace OpenMind\FindBox;
- use Generator;
- 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|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)));
- }
- }
|