boards.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /**
  2. * @license Licensed under the Apache License, Version 2.0 (the "License"):
  3. * http://www.apache.org/licenses/LICENSE-2.0
  4. */
  5. /**
  6. * @fileoverview Implements the required data for functions for selecting
  7. * amongst different Arduino boards.
  8. */
  9. 'use strict';
  10. goog.provide('Blockly.Python.Boards');
  11. goog.require('Blockly.Python');
  12. /**
  13. * Helper function to generate an array of pins (each an array of length 2) for
  14. * the digital IO.
  15. * @param {!integer} pinStart Start number for the IOs pin list to generate.
  16. * @param {!integer} pinEnd Last inclusive number for the list to generate.
  17. * @return {!array} Two dimensional array with the name and value for the
  18. * digital IO pins.
  19. */
  20. Blockly.Python.Boards.generateDigitalIo = function(pinStart, pinEnd) {
  21. var digitalIo = [];
  22. for (var i = pinStart; i < (pinEnd + 1); i++) {
  23. digitalIo.push([i.toString(), i.toString()]);
  24. }
  25. return digitalIo;
  26. };
  27. /**
  28. * Helper function to generate an array of pins (each an array of length 2) for
  29. * the analogue IO.
  30. * @param {!integer} pinStart Start number for the IOs pin list to generate.
  31. * @param {!integer} pinEnd Last inclusive number for the list to generate.
  32. * @return {!array} Two dimensional array with the name and value for the
  33. * analogue IO pins.
  34. */
  35. Blockly.Python.Boards.generateAnalogIo = function(pinStart, pinEnd) {
  36. var analogIo = [];
  37. for (var i = pinStart; i < (pinEnd + 1); i++) {
  38. analogIo.push(['A' + i.toString(), 'A' + i.toString()]);
  39. }
  40. return analogIo;
  41. };
  42. /**
  43. * Creates a new Board Profile copying all the attributes from an existing
  44. * profile, with the exception of the name, and optionally the description and
  45. * compiler flag.
  46. * @param {!string} name_ Mandatory new name of the new board profile.
  47. * @param {string=} description Optional new description of the new profile.
  48. * @param {string=} compilerFlag Optional new description of the new profile.
  49. * @return {!Object} Duplicated object with the different argument data.
  50. */
  51. Blockly.Python.Boards.duplicateBoardProfile =
  52. function(originalBoard, name_, description, compilerFlag) {
  53. return {
  54. name: name_,
  55. description: description || originalBoard.description,
  56. compilerFlag: compilerFlag || originalBoard.compilerFlag,
  57. analogPins: originalBoard.analogPins,
  58. digitalPins: originalBoard.digitalPins,
  59. pwmPins: originalBoard.pwmPins,
  60. serial: originalBoard.serial,
  61. serialPins: originalBoard.serialPins,
  62. serialSpeed: originalBoard.serialSpeed,
  63. spi: originalBoard.spi,
  64. spiPins: originalBoard.spiPins,
  65. spiClockDivide: originalBoard.spiClockDivide,
  66. i2c: originalBoard.i2c,
  67. i2cPins: originalBoard.i2cPins,
  68. i2cSpeed: originalBoard.i2cSpeed,
  69. builtinLed: originalBoard.builtinLed,
  70. interrupt: originalBoard.interrupt
  71. }
  72. };
  73. /** Object to contain all Arduino board profiles. */
  74. Blockly.Python.Boards.profiles = new Object();
  75. /** Arduino Uno board profile. */
  76. Blockly.Python.Boards.profiles.uno = {
  77. name: 'Arduino Uno',
  78. description: 'Arduino Uno standard compatible board',
  79. compilerFlag: 'arduino:avr:uno',
  80. analogPins: Blockly.Python.Boards.generateAnalogIo(0, 5),
  81. digitalPins: Blockly.Python.Boards.generateDigitalIo(0, 13).concat(
  82. Blockly.Python.Boards.generateAnalogIo(0, 5)),
  83. pwmPins: [
  84. ['3', '3'],
  85. ['5', '5'],
  86. ['6', '6'],
  87. ['9', '9'],
  88. ['10', '10'],
  89. ['11', '11'],
  90. ['13', '13']
  91. ],
  92. serial: [
  93. ['serial', 'Serial'],
  94. ],
  95. serialPins: {
  96. Serial: [
  97. ['RX', '0'],
  98. ['TX', '1']
  99. ]
  100. },
  101. serialSpeed: [
  102. ['300', '300'],
  103. ['600', '600'],
  104. ['1200', '1200'],
  105. ['2400', '2400'],
  106. ['4800', '4800'],
  107. ['9600', '9600'],
  108. ['14400', '14400'],
  109. ['19200', '19200'],
  110. ['28800', '28800'],
  111. ['31250', '31250'],
  112. ['38400', '38400'],
  113. ['57600', '57600'],
  114. ['115200', '115200']
  115. ],
  116. spi: [
  117. ['SPI', 'SPI']
  118. ],
  119. spiPins: {
  120. SPI: [
  121. ['MOSI', '11'],
  122. ['MISO', '12'],
  123. ['SCK', '13']
  124. ]
  125. },
  126. spiClockDivide: [
  127. ['2 (8MHz)', 'SPI_CLOCK_DIV2'],
  128. ['4 (4MHz)', 'SPI_CLOCK_DIV4'],
  129. ['8 (2MHz)', 'SPI_CLOCK_DIV8'],
  130. ['16 (1MHz)', 'SPI_CLOCK_DIV16'],
  131. ['32 (500KHz)', 'SPI_CLOCK_DIV32'],
  132. ['64 (250KHz)', 'SPI_CLOCK_DIV64'],
  133. ['128 (125KHz)', 'SPI_CLOCK_DIV128']
  134. ],
  135. i2c: [
  136. ['I2C', 'Wire']
  137. ],
  138. i2cPins: {
  139. Wire: [
  140. ['SDA', 'A4'],
  141. ['SCL', 'A5']
  142. ]
  143. },
  144. i2cSpeed: [
  145. ['100kHz', '100000L'],
  146. ['400kHz', '400000L']
  147. ],
  148. builtinLed: [
  149. ['BUILTIN_1', '13']
  150. ],
  151. interrupt: [
  152. ['interrupt0', '2'],
  153. ['interrupt1', '3']
  154. ]
  155. };
  156. /** Arduino Nano board profile (ATmega328p). */
  157. Blockly.Python.Boards.profiles.nano_328 = {
  158. name: 'Arduino Nano 328',
  159. description: 'Arduino Nano with ATmega328 board',
  160. compilerFlag: 'arduino:avr:nano:cpu=atmega328',
  161. analogPins: Blockly.Python.Boards.generateAnalogIo(0, 7),
  162. digitalPins: Blockly.Python.Boards.generateDigitalIo(0, 13).concat(
  163. Blockly.Python.Boards.generateAnalogIo(0, 7)),
  164. pwmPins: Blockly.Python.Boards.profiles.uno.pwmPins,
  165. serial: Blockly.Python.Boards.profiles.uno.serial,
  166. serialPins: Blockly.Python.Boards.profiles.uno.serialPins,
  167. serialSpeed: Blockly.Python.Boards.profiles.uno.serialSpeed,
  168. spi: Blockly.Python.Boards.profiles.uno.spi,
  169. spiPins: Blockly.Python.Boards.profiles.uno.spiPins,
  170. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  171. i2c: Blockly.Python.Boards.profiles.uno.i2c,
  172. i2cPins: Blockly.Python.Boards.profiles.uno.i2cPins,
  173. i2cSpeed: Blockly.Python.Boards.profiles.uno.i2cSpeed,
  174. builtinLed: Blockly.Python.Boards.profiles.uno.builtinLed,
  175. interrupt: Blockly.Python.Boards.profiles.uno.interrupt
  176. };
  177. Blockly.Python.Boards.profiles.nano_168 =
  178. Blockly.Python.Boards.duplicateBoardProfile(
  179. Blockly.Python.Boards.profiles.nano_328,
  180. 'Arduino Nano 168',
  181. 'Arduino Nano with ATmega168 compatible board',
  182. 'arduino:avr:nano:cpu=atmega168');
  183. /** Arduino Duemilanove boards profile (ATmega168p, ATmega328p). */
  184. Blockly.Python.Boards.profiles.duemilanove_168p = {
  185. name: 'Arduino Nano 168p',
  186. description: 'Arduino Duemilanove with ATmega168p compatible board',
  187. compilerFlag: 'arduino:avr:diecimila:cpu=atmega168',
  188. analogPins: Blockly.Python.Boards.profiles.uno.analogPins,
  189. digitalPins: Blockly.Python.Boards.profiles.uno.digitalPins,
  190. pwmPins: Blockly.Python.Boards.profiles.uno.pwmPins,
  191. serial: Blockly.Python.Boards.profiles.uno.serial,
  192. serialPins: Blockly.Python.Boards.profiles.uno.serialPins,
  193. serialSpeed: Blockly.Python.Boards.profiles.uno.serialSpeed,
  194. spi: Blockly.Python.Boards.profiles.uno.spi,
  195. spiPins: Blockly.Python.Boards.profiles.uno.spiPins,
  196. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  197. i2c: Blockly.Python.Boards.profiles.uno.i2c,
  198. i2cPins: Blockly.Python.Boards.profiles.uno.i2cPins,
  199. i2cSpeed: Blockly.Python.Boards.profiles.uno.i2cSpeed,
  200. builtinLed: Blockly.Python.Boards.profiles.uno.builtinLed,
  201. interrupt: Blockly.Python.Boards.profiles.uno.interrupt
  202. };
  203. Blockly.Python.Boards.profiles.duemilanove_328p =
  204. Blockly.Python.Boards.duplicateBoardProfile(
  205. Blockly.Python.Boards.profiles.duemilanove_168p,
  206. 'Arduino Duemilanove 328p',
  207. 'Arduino Duemilanove with ATmega328p compatible board',
  208. 'arduino:avr:diecimila');
  209. /** Arduino Mega board profile. */
  210. Blockly.Python.Boards.profiles.mega = {
  211. name: 'Arduino Mega',
  212. description: 'Arduino Mega-compatible board',
  213. compilerFlag: 'arduino:avr:mega',
  214. analogPins: Blockly.Python.Boards.generateAnalogIo(0, 15),
  215. //TODO: Check if the Mega can use analogue pins as digital, it would be
  216. // logical but it is not clear on the arduino.cc website
  217. digitalPins: Blockly.Python.Boards.generateDigitalIo(0, 53),
  218. pwmPins: Blockly.Python.Boards.generateDigitalIo(2, 13).concat(
  219. Blockly.Python.Boards.generateDigitalIo(44, 46)),
  220. serial: [
  221. ['serial', 'Serial'],
  222. ['serial_1', 'Serial1'],
  223. ['serial_2', 'Serial2'],
  224. ['serial_3', 'Serial3']
  225. ],
  226. serialPins: {
  227. Serial: [
  228. ['TX', '0'],
  229. ['RX', '1']
  230. ],
  231. Serial1: [
  232. ['TX', '18'],
  233. ['TX', '19']
  234. ],
  235. Serial2: [
  236. ['TX', '16'],
  237. ['TX', '17']
  238. ],
  239. Serial3: [
  240. ['TX', '14'],
  241. ['TX', '15']
  242. ]
  243. },
  244. serialSpeed: Blockly.Python.Boards.profiles.uno.serialSpeed,
  245. spi: [
  246. ['SPI', 'SPI']
  247. ],
  248. spiPins: {
  249. SPI: [
  250. ['MOSI', '51'],
  251. ['MISO', '50'],
  252. ['SCK', '52']
  253. ]
  254. },
  255. //TODO: confirm the clock divides are the same for the DUE and UNO
  256. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  257. i2c: [
  258. ['I2C', 'Wire']
  259. ],
  260. i2cPins: {
  261. Wire: [
  262. ['SDA', '20'],
  263. ['SCL', '21']
  264. ]
  265. },
  266. i2cSpeed: [
  267. ['100kHz', '100000L'],
  268. ['400kHz', '400000L']
  269. ],
  270. builtinLed: Blockly.Python.Boards.profiles.uno.builtinLed,
  271. interrupt: [
  272. ['interrupt0', '2'],
  273. ['interrupt1', '3'],
  274. ['interrupt2', '21'],
  275. ['interrupt3', '20'],
  276. ['interrupt4', '19'],
  277. ['interrupt5', '18']
  278. ]
  279. };
  280. /** Arduino Leonardo board profile. */
  281. Blockly.Python.Boards.profiles.leonardo = {
  282. name: 'Arduino Leonardo',
  283. description: 'Arduino Leonardo-compatible board',
  284. compilerFlag: 'arduino:avr:leonardo',
  285. analogPins: Blockly.Python.Boards.generateAnalogIo(0, 7),
  286. digitalPins: Blockly.Python.Boards.generateDigitalIo(0, 13),
  287. pwmPins: Blockly.Python.Boards.profiles.uno.pwmPins,
  288. serial: Blockly.Python.Boards.profiles.uno.serial,
  289. serialPins: Blockly.Python.Boards.profiles.uno.serialPins,
  290. serialSpeed: Blockly.Python.Boards.profiles.uno.serialSpeed,
  291. spi: [
  292. ['SPI', 'SPI']
  293. ],
  294. spiPins: {
  295. SPI: [
  296. ['MOSI', 'ICSP-4'],
  297. ['MISO', 'ICSP-1'],
  298. ['SCK', 'ICSP-3']
  299. ]
  300. },
  301. //TODO: confirm the clock divides are the same for the Leonardo and UNO
  302. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  303. i2c: [
  304. ['I2C', 'Wire']
  305. ],
  306. i2cPins: {
  307. Wire: [
  308. ['SDA', '2'],
  309. ['SCL', '3']
  310. ]
  311. },
  312. i2cSpeed: Blockly.Python.Boards.profiles.uno.i2cSpeed,
  313. builtinLed: Blockly.Python.Boards.profiles.uno.builtinLed,
  314. interrupt: [
  315. ['interrupt0', '3'],
  316. ['interrupt1', '2'],
  317. ['interrupt2', '0'],
  318. ['interrupt3', '1'],
  319. ['interrupt4', '17']
  320. ]
  321. };
  322. /** Arduino Yun board processor and profile is identical to Leonardo. */
  323. Blockly.Python.Boards.profiles.yun =
  324. Blockly.Python.Boards.duplicateBoardProfile(
  325. Blockly.Python.Boards.profiles.leonardo,
  326. 'Arduino Yun',
  327. 'Arduino Yun compatible board');
  328. /** Atmel Xplained mini boards profile (atmega328p, atmega328pb, atmega168pb).*/
  329. Blockly.Python.Boards.profiles.atmel_atmega328p_xplained_mini = {
  330. name: 'Atmel atmega328p Xplained mini',
  331. description: 'Atmel Xplained mini board with atmega328p (Uno compatible)',
  332. compilerFlag: 'atmel:avr:atmega328p_xplained_mini',
  333. analogPins: Blockly.Python.Boards.profiles.uno.analogPins,
  334. digitalPins: Blockly.Python.Boards.profiles.uno.digitalPins.concat(
  335. [
  336. ['20', '20']
  337. ]),
  338. pwmPins: Blockly.Python.Boards.profiles.uno.pwmPins,
  339. serial: Blockly.Python.Boards.profiles.uno.serial,
  340. serialPins: Blockly.Python.Boards.profiles.uno.serialPins,
  341. serialSpeed: Blockly.Python.Boards.profiles.uno.serialSpeed,
  342. spi: Blockly.Python.Boards.profiles.uno.spi,
  343. spiPins: Blockly.Python.Boards.profiles.uno.spiPins,
  344. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  345. i2c: Blockly.Python.Boards.profiles.uno.i2c,
  346. i2cPins: Blockly.Python.Boards.profiles.uno.i2cPins,
  347. i2cSpeed: Blockly.Python.Boards.profiles.uno.i2cSpeed,
  348. builtinLed: [
  349. ['BUILTIN_LED', '13']
  350. ],
  351. interrupt: Blockly.Python.Boards.profiles.uno.interrupt,
  352. builtinButton: [
  353. ['BUILTIN_BUTTON', '20']
  354. ]
  355. };
  356. Blockly.Python.Boards.profiles.atmel_atmega328pb_xplained_mini =
  357. Blockly.Python.Boards.duplicateBoardProfile(
  358. Blockly.Python.Boards.profiles.atmel_atmega328p_xplained_mini,
  359. 'Atmel atmega328pb Xplained mini',
  360. 'Atmel Xplained mini board with atmega328pb (Arduino Uno compatible)',
  361. 'atmel:avr:atmega328pb_xplained_mini');
  362. Blockly.Python.Boards.profiles.atmel_atmega168pb_xplained_mini =
  363. Blockly.Python.Boards.duplicateBoardProfile(
  364. Blockly.Python.Boards.profiles.atmel_atmega328p_xplained_mini,
  365. 'Atmel atmega168pb Xplained mini',
  366. 'Atmel Xplained mini board with atmega168pb (Arduino Uno compatible)',
  367. 'atmel:avr:atmega168pb_xplained_mini');
  368. /** ESP8266 for the Adafruit Huzzah. */
  369. Blockly.Python.Boards.profiles.esp8266_huzzah = {
  370. name: 'Adafruit Feather HUZZAH',
  371. description: 'Adafruit HUZZAH ESP8266 compatible board',
  372. compilerFlag: 'esp8266:esp8266:generic',
  373. analogPins: [
  374. ['A0', 'A0']
  375. ],
  376. digitalPins: [
  377. ['0', '0'],
  378. ['2', '2'],
  379. ['4', '4'],
  380. ['5', '5'],
  381. ['12', '12'],
  382. ['13', '13'],
  383. ['14', '14'],
  384. ['15', '15'],
  385. ['16', '16']
  386. ],
  387. pwmPins: [
  388. ['2', '2']
  389. ],
  390. serial: [
  391. ['serial', 'Serial']
  392. ],
  393. serialPins: {
  394. Serial: [
  395. ['RX', 'RX'],
  396. ['TX', 'TX']
  397. ]
  398. },
  399. serialSpeed: Blockly.Python.Boards.profiles.uno.serial,
  400. spi: [
  401. ['SPI', 'SPI']
  402. ],
  403. spiPins: {
  404. SPI: [
  405. ['MOSI', '13'],
  406. ['MISO', '12'],
  407. ['SCK', '14']
  408. ]
  409. },
  410. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  411. i2c: [
  412. ['I2C', 'Wire']
  413. ],
  414. i2cPins: {
  415. Wire: [
  416. ['SDA', '4'],
  417. ['SCL', '5']
  418. ]
  419. },
  420. i2cSpeed: Blockly.Python.Boards.profiles.uno.i2cSpeed,
  421. builtinLed: [
  422. ['BUILTIN_1', '0']
  423. ],
  424. interrupt: [
  425. ['interrupt0', '2'],
  426. ['interrupt1', '3']
  427. ]
  428. };
  429. /** ESP8266 for the Wemos D1 R2. */
  430. Blockly.Python.Boards.profiles.esp8266_wemos_d1 = {
  431. name: 'Wemos D1',
  432. description: 'Wemos D1 R2 compatible board',
  433. compilerFlag: 'esp8266:esp8266:generic',
  434. analogPins: [
  435. ['A0', 'A0']
  436. ],
  437. digitalPins: [
  438. ['D0', 'D0'],
  439. ['D1', 'D1'],
  440. ['D2', 'D2'],
  441. ['D3', 'D3'],
  442. ['D4', 'D4'],
  443. ['D5', 'D5'],
  444. ['D6', 'D7'],
  445. ['D8', 'D8']
  446. ],
  447. pwmPins: [
  448. ['D1', 'D1'],
  449. ['D2', 'D2'],
  450. ['D3', 'D3'],
  451. ['D4', 'D4'],
  452. ['D5', 'D5'],
  453. ['D6', 'D7'],
  454. ['D8', 'D8']
  455. ],
  456. serial: [
  457. ['serial', 'Serial']
  458. ],
  459. serialPins: {
  460. Serial: [
  461. ['RX', 'RX'],
  462. ['TX', 'TX']
  463. ]
  464. },
  465. serialSpeed: Blockly.Python.Boards.profiles.uno.serialSpeed,
  466. spi: [
  467. ['SPI', 'SPI']
  468. ],
  469. spiPins: {
  470. SPI: [
  471. ['MOSI', 'D7'],
  472. ['MISO', 'D6'],
  473. ['SCK', 'D5']
  474. ]
  475. },
  476. spiClockDivide: Blockly.Python.Boards.profiles.uno.spiClockDivide,
  477. i2c: [
  478. ['I2C', 'Wire']
  479. ],
  480. i2cPins: {
  481. Wire: [
  482. ['SDA', 'D2'],
  483. ['SCL', 'D1']
  484. ]
  485. },
  486. i2cSpeed: Blockly.Python.Boards.profiles.uno.i2cSpeed,
  487. builtinLed: [
  488. ['BUILTIN_1', 'D4']
  489. ],
  490. interrupt: [
  491. ['D0', 'D0'],
  492. ['D1', 'D1'],
  493. ['D2', 'D2'],
  494. ['D3', 'D3'],
  495. ['D4', 'D4'],
  496. ['D5', 'D5'],
  497. ['D6', 'D7'],
  498. ['D8', 'D8']
  499. ]
  500. };
  501. /** Set default profile to Arduino standard-compatible board */
  502. Blockly.Python.Boards.selected = Blockly.Python.Boards.profiles.leonardo;
  503. /**
  504. * Changes the Arduino board profile selected, which trigger a refresh of the
  505. * blocks that use the profile.
  506. * @param {Blockly.Workspace} workspace Workspace to trigger the board change.
  507. * @param {string} newBoard Name of the new profile to set.
  508. */
  509. Blockly.Python.Boards.changeBoard = function(workspace, newBoard) {
  510. if (Blockly.Python.Boards.profiles[newBoard] === undefined) {
  511. console.log('Tried to set non-existing Arduino board: ' + newBoard);
  512. return;
  513. }
  514. Blockly.Python.Boards.selected = Blockly.Python.Boards.profiles[newBoard];
  515. // Update the pin out of all the blocks that uses them
  516. var blocks = workspace.getAllBlocks();
  517. for (var i = 0; i < blocks.length; i++) {
  518. var updateFields = blocks[i].updateFields;
  519. if (updateFields) {
  520. updateFields.call(blocks[i]);
  521. }
  522. }
  523. };
  524. /**
  525. * Refreshes the contents of a block Field Dropdown.
  526. * This is use to refresh the blocks after the board profile has been changed.
  527. * @param {!Blockly.Block} block Generated code.
  528. * @param {!string} fieldName Name of the block FieldDropdown to refresh.
  529. * @param {!string} boardKey Name of the board profile property to fetch.
  530. */
  531. Blockly.Python.Boards.refreshBlockFieldDropdown =
  532. function(block, fieldName, boardKey) {
  533. var field = block.getField(fieldName);
  534. var fieldValue = field.getValue();
  535. var dataArray = Blockly.Python.Boards.selected[boardKey];
  536. field.menuGenerator_ = dataArray;
  537. var currentValuePresent = false;
  538. for (var i = 0; i < dataArray.length; i++) {
  539. if (fieldValue == dataArray[i][1]) {
  540. currentValuePresent = true;
  541. }
  542. }
  543. // If the old value is not present any more, add a warning to the block.
  544. if (!currentValuePresent) {
  545. block.setWarningText(
  546. 'The old pin value ' + fieldValue + ' is no longer available.', 'bPin');
  547. } else {
  548. block.setWarningText(null, 'bPin');
  549. }
  550. };