SmartESL.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * @author Giancarlo Voci
  4. * @date 28/03/2018
  5. * @time 09:09
  6. */
  7. namespace OpenMind\FindBox;
  8. use Generator;
  9. class SmartESL
  10. {
  11. /** @var FindBoxCoreSystem $core */
  12. protected $core;
  13. /** @var array $labels */
  14. protected $labels;
  15. /** @var array $labelProperties */
  16. protected $labelProperties;
  17. public function __construct(FindBoxCoreSystem $coreL, array $LabelID)
  18. {
  19. $this->core = $coreL;
  20. $this->labels = array_map('strtoupper', $LabelID);
  21. }
  22. /**
  23. * Request to label(s) its properties
  24. *
  25. * @param bool $force request directly to ESL
  26. * @return null|array Details
  27. */
  28. public function GetStatus(bool $force = false)
  29. {
  30. $labels = json_encode($this->labels);
  31. //$URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
  32. $forceStr = var_export($force, true);
  33. $URI = "/1.0.0/index.php/smartesl.getstatus/4.0.0/[{$labels},{$forceStr}]";
  34. $ret = $this->core->CallAPI($URI, '');
  35. if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
  36. // Update current properties
  37. $this->labelProperties = $ret['value']['value'];
  38. return $this->labelProperties;
  39. }
  40. return null;
  41. }
  42. /**
  43. * Get label version splitted into the three components major, minor, patch
  44. *
  45. * @return array
  46. */
  47. public function GetVersion()
  48. {
  49. $softVersion = $this->labelProperties[array_keys($this->labelProperties)[0]]['status'];
  50. return array_values(array_filter_keys($softVersion, ['soft_major', 'soft_minor', 'soft_patch']));
  51. }
  52. public function AsyncBlinkOff(): Generator
  53. {
  54. global $f3;
  55. return $this->AsyncBlinkSpecial(2, 1, 1000, 1, $f3->BLINKOFF_COLOR);
  56. }
  57. /**
  58. * Blink the label with parameters.
  59. *
  60. * @param int $pattern
  61. * @param int $repeat
  62. * @param int $iter_time
  63. * @param int $iterations
  64. * @param int|0 $ledColor
  65. * @return Generator
  66. */
  67. public function AsyncBlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = 0): Generator
  68. {
  69. $uriParams = json_encode(array_merge(
  70. array($this->labels),
  71. array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)
  72. ));
  73. $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
  74. return $this->core->AsyncCallAPI($URI, $uriParams);
  75. }
  76. public function getData()
  77. {
  78. return $this->labelProperties[$this->labels[0]]['data'];
  79. }
  80. /**
  81. * Turn off led(s)
  82. */
  83. public function BlinkOff()
  84. {
  85. global $f3;
  86. return $this->BlinkSpecial(2, 1, 1000, 1, $f3->BLINKOFF_COLOR);
  87. }
  88. /**
  89. * Blink the label with parameters.
  90. *
  91. * @param int $pattern
  92. * @param int $repeat
  93. * @param int $iter_time
  94. * @param int $iterations
  95. * @param int|0 $ledColor
  96. * @return array
  97. */
  98. public function BlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = 0)
  99. {
  100. $uriParams = json_encode(array_merge(
  101. array($this->labels),
  102. array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)
  103. ));
  104. $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
  105. return $this->core->CallAPI($URI, $uriParams);
  106. }
  107. public function Display(string $templateId, string $barcode)
  108. {
  109. $URI = "/1.0.0/index.php/smartesl.display/2.3.0/";
  110. $params = json_encode(array(
  111. $this->labels[0],
  112. $barcode,
  113. [],
  114. $templateId,
  115. 1, 1
  116. ));
  117. return $this->core->CallAPI($URI, $params);
  118. }
  119. /**
  120. * Set ESL display using displayimage CORE API
  121. *
  122. * @param string $binaryImage
  123. * @param int $pageNum
  124. * @return array
  125. */
  126. public function SetPageImage(string $binaryImage, int $pageNum = 1)
  127. {
  128. $imageb64 = base64_encode($binaryImage);
  129. $URI = "/1.0.0/index.php/smartesl.displayimage/1.1.1/";
  130. $params = json_encode([array_map(function ($label) use ($pageNum, $imageb64) {
  131. return [
  132. 'label_id' => $label,
  133. 'image' => $imageb64,
  134. 'page' => $pageNum
  135. ];
  136. }, $this->labels)]);
  137. return $this->core->CallAPI($URI, $params);
  138. }
  139. /**
  140. * Switch to ESL page $pageNum
  141. *
  142. * @param int $pageNum
  143. * @return array
  144. */
  145. public function SwitchPage(int $pageNum = 1)
  146. {
  147. $URI = "/1.0.0/index.php/smartesl.switchpage/1.1.0/";
  148. $params = json_encode([array_map(function ($label) use ($pageNum) {
  149. return [
  150. 'label_id' => $label,
  151. 'page' => $pageNum
  152. ];
  153. }, $this->labels)]);
  154. return $this->core->CallAPI($URI, $params);
  155. }
  156. public function GetLabelMatch()
  157. {
  158. $URI = "/1.0.0/index.php/smartesl.getlabelmatch/1.2.0/";
  159. return $this->core->CallAPI($URI, json_encode(array($this->labels)));
  160. }
  161. }