SmartESL.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 28/03/2018
  5. * @time 09:09
  6. */
  7. namespace OpenMind\FindBox;
  8. class SmartESL
  9. {
  10. private $core;
  11. private $labels;
  12. private $labelProperties;
  13. public function __construct(FindBoxCoreSystem $coreL, array $LabelID)
  14. {
  15. $this->core = $coreL;
  16. $this->labels = array_map('strtoupper', $LabelID);
  17. // TODO utilizzare la $Cache di F3 per velocizzare le operazioni
  18. $this->labelProperties = $this->GetStatus();
  19. }
  20. /**
  21. * Request to label(s) its properties
  22. * @return null|object Details
  23. */
  24. public function GetStatus()
  25. {
  26. $labels = json_encode(array($this->labels));
  27. $URI = "/1.0.0/index.php/smartesl.getstatus/3.1.0/";
  28. $ret = $this->core->CallAPI($URI, $labels);
  29. if ($ret['err'] == 0 && $ret['value']['code'] == 0) {
  30. // Update current properties
  31. $this->labelProperties = $ret['value']['value'];
  32. return $this->labelProperties;
  33. }
  34. return null;
  35. }
  36. /**
  37. * Retrieve cached label properties
  38. *
  39. * @return null|object
  40. */
  41. public function getDetails()
  42. {
  43. return $this->labelProperties;
  44. }
  45. /**
  46. * Get label version splitted into the three components major, minor, patch
  47. *
  48. * @return array
  49. */
  50. public function GetVersion()
  51. {
  52. $softVersion = $this->labelProperties[array_keys($this->labelProperties)[0]]['status'];
  53. return array_values(array_filter_keys($softVersion, ['soft_major', 'soft_minor', 'soft_patch']));
  54. }
  55. /**
  56. * Blink the label with parameters. BlinkSpecial make use of getData() and check how many leds has to auto select the firmware version.
  57. *
  58. * @param int $pattern
  59. * @param int $repeat
  60. * @param int $iter_time
  61. * @param int $iterations
  62. * @param int|null $ledColor
  63. * @return array
  64. */
  65. public function BlinkSpecial(int $pattern, int $repeat, int $iter_time, int $iterations, int $ledColor = null)
  66. {
  67. $numLeds = $this->getData()['led'];
  68. switch ($numLeds) {
  69. case 2:
  70. $version = 4;
  71. break;
  72. case 4:
  73. $version = 6;
  74. break;
  75. default:
  76. $version = 3;
  77. break;
  78. }
  79. $firmwareStringVersion = array(
  80. '3' => '1.0.0',
  81. '4' => '1.1.0',
  82. '6' => '2.0.0'
  83. );
  84. $params = array(
  85. '3' => array($pattern, $repeat, $iter_time, $iterations, 1),
  86. '4' => array($pattern, $repeat, $iter_time, $iterations, 1),
  87. '6' => array($pattern, $ledColor, $repeat, $iter_time, $iterations, 1)
  88. );
  89. // TODO #NODISPLAY da sistemare
  90. $strFWVer = $firmwareStringVersion[$version];
  91. $uriParams = json_encode(array_merge(
  92. array($this->labels),
  93. $params[$version]));
  94. $URI = "/1.0.0/index.php/smartesl.blink_special/{$strFWVer}/";
  95. return $this->core->CallAPI($URI, $uriParams);
  96. }
  97. public function getData()
  98. {
  99. return $this->labelProperties[$this->labels[0]]['data'];
  100. }
  101. /**
  102. * Turn off led(s)
  103. */
  104. public function BlinkOff()
  105. {
  106. $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
  107. return $this->core->CallAPI($URI, "[[\"{$this->labels[0]}\"],0,0,0,0,0,1]");
  108. }
  109. public function Display(string $templateId, string $barcode)
  110. {
  111. $URI = "/1.0.0/index.php/smartesl.display/2.3.0/";
  112. $params = json_encode(array(
  113. $this->labels[0],
  114. $barcode,
  115. [],
  116. $templateId,
  117. 1, 1));
  118. return $this->core->CallAPI($URI, $params);
  119. }
  120. public function GetLabelMatch()
  121. {
  122. $URI = "/1.0.0/index.php/smartesl.getlabelmatch/1.2.0/";
  123. return $this->core->CallAPI($URI, json_encode(array($this->labels)));
  124. }
  125. }