clock.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. #include "clock.h"
  2. /* type defs */
  3. typedef struct t_btn {
  4. uint8_t time;
  5. es_event_t pressed;
  6. es_event_t holded;
  7. uint32_t pin;
  8. //(GPIO_TypeDef *) GPIOA; // ?->IDR
  9. } btn_t;
  10. /* variables */
  11. rtc_t Clock;
  12. static rtc_t setClock;
  13. static btn_t Button[BTN_NUM] = {
  14. {0, evBTN1Pressed, evBTN1Holded, BTN1_PIN},
  15. {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
  16. {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
  17. {0, evBTN4Pressed, evBTN4Holded, BTN4_PIN}
  18. };
  19. //convert linear bright level to logariphmic
  20. const uint8_t cie[8] = { 0, 5, 14, 33, 64, 109, 172, 255 };
  21. volatile static uint8_t dispWDT = 0;
  22. static in15_pin_t symToFade = 0;
  23. static brigh_level_t BrightLevel;
  24. /* function prototypes */
  25. static void check_DayNight(void);
  26. static void MinusFadeIn(void);
  27. static void MinusFadeOut(void);
  28. static void PlusFadeIn(void);
  29. static void PercentFadeIn(void);
  30. static void PressureFadeIn(void);
  31. static void IN15_FadeIn(void);
  32. static void IN15_FadeOut(void);
  33. static void valIncrease(uint8_t * val, uint8_t max);
  34. static void valDecrease(uint8_t * val, uint8_t max);
  35. static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val);
  36. /* funcions */
  37. void Clock_Init(void) {
  38. RTC_ReadAll(&Clock);
  39. showTime();
  40. check_DayNight();
  41. }
  42. static void check_DayNight(void) {
  43. if ((Clock.Hr >= MORNING_HOUR) && (Clock.Hr < EVENING_HOUR)) {
  44. Flag.Now_Day = 1;
  45. BrightLevel = cie[DAY_BR_LVL];
  46. } else {
  47. Flag.Now_Day = 0;
  48. BrightLevel = cie[NIGHT_BR_LVL];
  49. }
  50. tube_BrightLevel(Tube_All, BrightLevel);
  51. //TUBES_BRIGHT(BrightLevel);
  52. }
  53. /**
  54. * @brief Обработка кнопок.
  55. * @param : None
  56. * @retval : None
  57. */
  58. void btnProcess(void) {
  59. /* get pin state */
  60. uint32_t pins = BTNS_STATE;
  61. int i;
  62. for (i=0; i<BTN_NUM; i++) {
  63. if ((pins & Button[i].pin) == 0) {
  64. /* button pressed */
  65. Button[i].time ++;
  66. if (Button[i].time >= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) {
  67. Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD);
  68. if (Button[i].holded == Button[i].pressed) {
  69. /* if pressed and holded - same function, then button pressed auto repeat */
  70. ES_PlaceEvent(Button[i].pressed);
  71. }
  72. }
  73. } else if (Button[i].time != 0) {
  74. /* button released */
  75. if (Button[i].time >= ((BTN_TIME_HOLDED - BTN_TIME_REPEATED)/BTN_SCAN_PERIOD)) {
  76. /* process long press */
  77. ES_PlaceEvent(Button[i].holded);
  78. } else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) {
  79. /* process short press */
  80. ES_PlaceEvent(Button[i].pressed);
  81. }
  82. Button[i].time = 0;
  83. RTOS_SetTask(btnProcess, BTN_SCAN_PAUSE, BTN_SCAN_PERIOD);
  84. }
  85. } /* end FOR */
  86. }
  87. void new_Second(void) {
  88. RTC_ReadAll(&Clock);
  89. // new hour
  90. if (Clock.Min == 0 && Clock.Sec == 0) {
  91. check_DayNight();
  92. }
  93. // check display watch dog timer
  94. if (dispWDT != 0) {
  95. dispWDT--;
  96. if (dispWDT == 0) {
  97. Blink_Stop();
  98. ES_PlaceEvent(evDisplayWDT);
  99. }
  100. }
  101. }
  102. /**
  103. * On/off symbols on IN-15 tube.
  104. */
  105. void in15Off(void) {
  106. IN15_OFF;
  107. TUBE_C_OFF;
  108. }
  109. void in15Minus(void) {
  110. IN15_OFF;
  111. IN15_Minus;
  112. TUBE_C_ON;
  113. }
  114. void in15Plus(void) {
  115. IN15_OFF;
  116. IN15_Plus;
  117. TUBE_C_ON;
  118. }
  119. void in15Percent(void) {
  120. IN15_OFF;
  121. IN15_Percent;
  122. TUBE_C_ON;
  123. }
  124. void in15P(void) {
  125. IN15_OFF;
  126. IN15_P;
  127. TUBE_C_ON;
  128. }
  129. /** 'Faded' funcions */
  130. static void MinusFadeIn(void) {
  131. static uint8_t on = FADE_START;
  132. static uint8_t off = FADE_STOP;
  133. static uint8_t st = 0;
  134. if (st == 0) {
  135. st = 1;
  136. IN15_Minus;
  137. on += FADE_STEP;
  138. if (on < FADE_STOP) {
  139. RTOS_SetTask(MinusFadeIn, on, 0);
  140. } else {
  141. on = FADE_START; off = FADE_STOP; st = 0;
  142. }
  143. } else {
  144. st = 0;
  145. IN15_OFF;
  146. off -= FADE_STEP;
  147. RTOS_SetTask(MinusFadeIn, off, 0);
  148. }
  149. }
  150. static void MinusFadeOut(void) {
  151. static uint8_t off = FADE_START;
  152. static uint8_t on = FADE_STOP;
  153. static uint8_t st = 0;
  154. if (st == 0) {
  155. st = 1;
  156. IN15_OFF;
  157. off += FADE_STEP;
  158. if (off < FADE_STOP) {
  159. RTOS_SetTask(MinusFadeOut, off, 0);
  160. } else {
  161. off = FADE_START; on = FADE_STOP; st = 0;
  162. }
  163. } else {
  164. st = 0;
  165. IN15_Minus;
  166. on -= FADE_STEP;
  167. RTOS_SetTask(MinusFadeOut, on, 0);
  168. }
  169. }
  170. static void PlusFadeIn(void) {
  171. static uint8_t on = FADE_START;
  172. static uint8_t off = FADE_STOP;
  173. static uint8_t st = 0;
  174. if (st == 0) {
  175. st = 1;
  176. IN15_Plus;
  177. on += FADE_STEP;
  178. if (on < FADE_STOP) {
  179. RTOS_SetTask(PlusFadeIn, on, 0);
  180. } else {
  181. on = FADE_START; off = FADE_STOP; st = 0;
  182. }
  183. } else {
  184. st = 0;
  185. IN15_OFF;
  186. off -= FADE_STEP;
  187. RTOS_SetTask(PlusFadeIn, off, 0);
  188. }
  189. }
  190. static void PercentFadeIn(void) {
  191. static uint8_t on = FADE_START;
  192. static uint8_t off = FADE_STOP;
  193. static uint8_t st = 0;
  194. if (st == 0) {
  195. st = 1;
  196. IN15_Percent;
  197. on += FADE_STEP;
  198. if (on < FADE_STOP) {
  199. RTOS_SetTask(PercentFadeIn, on, 0);
  200. } else {
  201. on = FADE_START; off = FADE_STOP; st = 0;
  202. }
  203. } else {
  204. st = 0;
  205. IN15_OFF;
  206. off -= FADE_STEP;
  207. RTOS_SetTask(PercentFadeIn, off, 0);
  208. }
  209. }
  210. static void PressureFadeIn(void) {
  211. static uint8_t on = FADE_START;
  212. static uint8_t off = FADE_STOP;
  213. static uint8_t st = 0;
  214. if (st == 0) {
  215. st = 1;
  216. IN15_P;
  217. on += FADE_STEP;
  218. if (on < FADE_STOP) {
  219. RTOS_SetTask(PressureFadeIn, on, 0);
  220. } else {
  221. on = FADE_START; off = FADE_STOP; st = 0;
  222. }
  223. } else {
  224. st = 0;
  225. IN15_OFF;
  226. off -= FADE_STEP;
  227. RTOS_SetTask(PressureFadeIn, off, 0);
  228. }
  229. }
  230. static void IN15_FadeIn(void) {
  231. static uint8_t on = FADE_START;
  232. static uint8_t off = FADE_STOP;
  233. static uint8_t st = 0;
  234. if (symToFade != 0) {
  235. if (st == 0) {
  236. st = 1;
  237. GPIOA->BSRR = symToFade;
  238. on += FADE_STEP;
  239. if (on < FADE_STOP) {
  240. RTOS_SetTask(IN15_FadeIn, on, 0);
  241. } else {
  242. on = FADE_START; off = FADE_STOP; st = 0; symToFade = 0;
  243. }
  244. } else {
  245. st = 0;
  246. IN15_OFF;
  247. off -= FADE_STEP;
  248. RTOS_SetTask(IN15_FadeIn, off, 0);
  249. }
  250. }
  251. }
  252. static void IN15_FadeOut(void) {
  253. static uint8_t off = FADE_START;
  254. static uint8_t on = FADE_STOP;
  255. static uint8_t st = 0;
  256. if (symToFade != 0) {
  257. if (st == 0) {
  258. st = 1;
  259. IN15_OFF;
  260. off += FADE_STEP;
  261. if (off < FADE_STOP) {
  262. RTOS_SetTask(IN15_FadeOut, off, 0);
  263. } else {
  264. off = FADE_START; on = FADE_STOP; st = 0; symToFade = 0;
  265. }
  266. } else {
  267. st = 0;
  268. GPIOA->BSRR = symToFade;
  269. on -= FADE_STEP;
  270. RTOS_SetTask(IN15_FadeOut, on, 0);
  271. }
  272. }
  273. }
  274. /**
  275. * @brief HSV to RGB convertion
  276. * @param hue: 0-(6*256)-1 /59/, sat: 0-255, val (lightness): 0-255
  277. * @return none. RGB value output direct to LED.
  278. */
  279. static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val) {
  280. int base;
  281. uint32_t r=0, g=0, b=0;
  282. if (sat == 0)
  283. { // Achromatic color (gray).
  284. r = val;
  285. g = val;
  286. b = val;
  287. } else {
  288. base = ((255 - sat) * val) >> 8;
  289. switch (hue / 10) {
  290. case 0:
  291. r = val;
  292. g = (((val - base) * hue) / 10) + base;
  293. b = base;
  294. break;
  295. case 1:
  296. r = (((val - base) * (10 - (hue % 10))) / 10) + base;
  297. g = val;
  298. b = base;
  299. break;
  300. case 2:
  301. r = base;
  302. g = val;
  303. b = (((val - base) * (hue % 10)) / 10) + base;
  304. break;
  305. case 3:
  306. r = base;
  307. g = (((val - base) * (10 - (hue % 10))) / 10) + base;
  308. b = val;
  309. break;
  310. case 4:
  311. r = (((val - base) * (hue % 10)) / 10) + base;
  312. g = base;
  313. b = val;
  314. break;
  315. case 5:
  316. r = val;
  317. g = base;
  318. b = (((val - base) * (10 - (hue % 10))) / 10) + base;
  319. break;
  320. }
  321. }
  322. COLOR_R((uint8_t)r);
  323. COLOR_G((uint8_t)g);
  324. COLOR_B((uint8_t)b);
  325. }
  326. /**
  327. * Show info on tubes.
  328. */
  329. void showTime(void) {
  330. MinusFadeIn();
  331. RTOS_SetTask(MinusFadeOut, 500, 0);
  332. if (Flag.Now_Day != 0) {
  333. // new hsv2led
  334. //uint16_t hue = (uint16_t)(bcd2bin(Clock.Sec) * 256) / 10;
  335. uint8_t hue = bcd2bin(Clock.Sec);
  336. HSV2LED(hue, 255, BrightLevel);
  337. } else {
  338. HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
  339. }
  340. tube4_t buf;
  341. buf.s8.tA = Clock.Hr >> 4;
  342. buf.s8.tB = Clock.Hr & 0xf;
  343. buf.s8.tD = Clock.Min >> 4;
  344. buf.s8.tE = Clock.Min & 0xf;
  345. showDigits(buf);
  346. }
  347. void showMMSS(void) {
  348. RTOS_DeleteTask(MinusFadeOut);
  349. IN15_Minus;
  350. uint8_t hue = bcd2bin(Clock.Sec);
  351. HSV2LED(hue, 255, BrightLevel);
  352. tube4_t buf;
  353. buf.s8.tA = Clock.Min >> 4;
  354. buf.s8.tB = Clock.Min & 0xf;
  355. buf.s8.tD = Clock.Sec >> 4;
  356. buf.s8.tE = Clock.Sec & 0xf;
  357. showDigits(buf);
  358. }
  359. void showWD(void) {
  360. dispWDT = DISP_WDT_TIME;
  361. IN15_OFF;
  362. tube4_t buf;
  363. buf.s8.tA = 0xf;
  364. buf.s8.tB = Clock.WD & 0xf;
  365. buf.s8.tD = 0xf;
  366. buf.s8.tE = 0xf;
  367. showDigits(buf);
  368. }
  369. void showDayMon(void) {
  370. dispWDT = DISP_WDT_TIME;
  371. IN15_OFF;
  372. tube4_t buf;
  373. buf.s8.tA = Clock.Day >> 4;
  374. buf.s8.tB = Clock.Day & 0xf;
  375. buf.s8.tD = Clock.Mon >> 4;
  376. buf.s8.tE = Clock.Mon & 0xf;
  377. showDigits(buf);
  378. }
  379. void showYear(void) {
  380. dispWDT = DISP_WDT_TIME;
  381. IN15_OFF;
  382. tube4_t buf;
  383. buf.s8.tA = 2;
  384. buf.s8.tB = 0;
  385. buf.s8.tD = Clock.Year >> 4;
  386. buf.s8.tE = Clock.Year & 0xf;
  387. showDigits(buf);
  388. }
  389. void showHumidity(void) {
  390. dispWDT = DISP_WDT_TIME;
  391. HSV2LED(COLOUR_BLUE, 255, BrightLevel);
  392. //in15Percent();
  393. symToFade = sym_Percent;
  394. IN15_FadeIn();
  395. //PercentFadeIn();
  396. tube4_t buf;
  397. buf.s8.tA = Humidity / 10;
  398. buf.s8.tB = Humidity % 10;
  399. buf.s8.tD = 0xf;
  400. buf.s8.tE = 0xf;
  401. showDigits(buf);
  402. }
  403. void showTemperature(void) {
  404. dispWDT = DISP_WDT_TIME;
  405. HSV2LED(COLOUR_RED, 255, BrightLevel);
  406. //in15Plus();
  407. symToFade = sym_Plus;
  408. IN15_FadeIn();
  409. //PlusFadeIn();
  410. tube4_t buf;
  411. buf.s8.tA = 0xf;
  412. buf.s8.tB = 0xf;
  413. buf.s8.tD = Temperature / 10;
  414. buf.s8.tE = Temperature % 10;
  415. showDigits(buf);
  416. }
  417. void showPressure(void) {
  418. dispWDT = DISP_WDT_TIME;
  419. HSV2LED(COLOUR_GREEN, 255, cie[Lvl_Mdl]); // GREEN
  420. //in15P();
  421. symToFade = sym_Pressure;
  422. IN15_FadeIn();
  423. //PressureFadeIn();
  424. tube4_t buf;
  425. int tmp;
  426. buf.s8.tA = 0xf;
  427. buf.s8.tB = Pressure / 100;
  428. tmp = Pressure % 100;
  429. buf.s8.tD = tmp / 10;
  430. buf.s8.tE = tmp % 10;
  431. showDigits(buf);
  432. }
  433. /* Simple function for cyclic show all sensor data */
  434. void showSensorData(void) {
  435. RTOS_DeleteTask(MinusFadeOut);
  436. showTemperature();
  437. tdelay_ms(3000);
  438. showHumidity();
  439. tdelay_ms(3000);
  440. showPressure();
  441. tdelay_ms(2700);
  442. ES_SetState(stShowTime);
  443. // showTime();
  444. }
  445. void setTimeShow(void) {
  446. dispWDT = DISP_WDT_TIME;
  447. tube4_t buf;
  448. buf.s8.tA = setClock.Hr >> 4;
  449. buf.s8.tB = setClock.Hr & 0xf;
  450. buf.s8.tD = setClock.Min >> 4;
  451. buf.s8.tE = setClock.Min & 0xf;
  452. showDigits(buf);
  453. }
  454. void setTimeBegin(void) {
  455. RTOS_DeleteTask(MinusFadeOut);
  456. in15Minus();
  457. HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
  458. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  459. RTC_ReadAll(&setClock);
  460. }
  461. void setHHBegin(void) {
  462. Flag.Blink_1 = 1;
  463. Flag.Blink_2 = 1;
  464. Flag.Blink_4 = 0;
  465. Flag.Blink_5 = 0;
  466. Blink_Start();
  467. setTimeShow();
  468. }
  469. void setHHInc(void) {
  470. valIncrease(&setClock.Hr, 23);
  471. }
  472. void setHHDec(void) {
  473. valDecrease(&setClock.Hr, 23);
  474. }
  475. void setMMBegin(void) {
  476. Flag.Blink_1 = 0;
  477. Flag.Blink_2 = 0;
  478. Flag.Blink_4 = 1;
  479. Flag.Blink_5 = 1;
  480. Blink_Start();
  481. setTimeShow();
  482. }
  483. void setMMInc(void) {
  484. valIncrease(&setClock.Min, 59);
  485. }
  486. void setMMDec(void) {
  487. valDecrease(&setClock.Min, 59);
  488. }
  489. void setTimeEnd(void) {
  490. dispWDT = 0;
  491. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  492. setClock.Sec = 0;
  493. RTC_WriteTime(&setClock);
  494. Blink_Stop();
  495. RTC_ReadAll(&Clock);
  496. }
  497. void setDateBegin(void) {
  498. IN15_OFF;
  499. HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
  500. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  501. RTC_ReadAll(&setClock);
  502. }
  503. void setDateEnd(void) {
  504. dispWDT = 0;
  505. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  506. RTC_WriteCalendar(&setClock);
  507. Blink_Stop();
  508. RTC_ReadAll(&Clock);
  509. }
  510. void setWDBegin(void) {
  511. Flag.Blink_1 = 0;
  512. Flag.Blink_2 = 1;
  513. Flag.Blink_4 = 0;
  514. Flag.Blink_5 = 0;
  515. Blink_Start();
  516. setWDShow();
  517. }
  518. void setWDShow(void) {
  519. dispWDT = DISP_WDT_TIME;
  520. tube4_t buf;
  521. buf.s8.tA = 0xf;
  522. buf.s8.tB = setClock.WD & 0xf;
  523. buf.s8.tD = 0xf;
  524. buf.s8.tE = 0xf;
  525. showDigits(buf);
  526. }
  527. void setDMShow(void) {
  528. dispWDT = DISP_WDT_TIME;
  529. tube4_t buf;
  530. buf.s8.tA = setClock.Day >> 4;
  531. buf.s8.tB = setClock.Day & 0xf;
  532. buf.s8.tD = setClock.Mon >> 4;
  533. buf.s8.tE = setClock.Mon & 0xf;
  534. showDigits(buf);
  535. }
  536. void setYearShow(void) {
  537. dispWDT = DISP_WDT_TIME;
  538. tube4_t buf;
  539. buf.s8.tA = 2;
  540. buf.s8.tB = 0;
  541. buf.s8.tD = setClock.Year >> 4;
  542. buf.s8.tE = setClock.Year & 0xf;
  543. showDigits(buf);
  544. }
  545. void setMDBegin(void) {
  546. Flag.Blink_1 = 1;
  547. Flag.Blink_2 = 1;
  548. Flag.Blink_4 = 0;
  549. Flag.Blink_5 = 0;
  550. Blink_Start();
  551. setDMShow();
  552. }
  553. void setMonthBegin(void) {
  554. Flag.Blink_1 = 0;
  555. Flag.Blink_2 = 0;
  556. Flag.Blink_4 = 1;
  557. Flag.Blink_5 = 1;
  558. Blink_Start();
  559. setDMShow();
  560. }
  561. void setYearBegin(void) {
  562. Flag.Blink_1 = 0;
  563. Flag.Blink_2 = 0;
  564. Flag.Blink_4 = 1;
  565. Flag.Blink_5 = 1;
  566. Blink_Start();
  567. setYearShow();
  568. }
  569. void setIncWDay(void) {
  570. valIncrease(&setClock.WD, 7);
  571. }
  572. void setIncMDay(void) {
  573. valIncrease(&setClock.Day, 31);
  574. }
  575. void setIncMonth(void) {
  576. valIncrease(&setClock.Mon, 12);
  577. }
  578. void setIncYear(void) {
  579. valIncrease(&setClock.Year, 99);
  580. }
  581. void setDecWDay(void) {
  582. valDecrease(&setClock.WD, 7);
  583. }
  584. void setDecMDay(void) {
  585. valDecrease(&setClock.Day, 31);
  586. }
  587. void setDecMonth(void) {
  588. valDecrease(&setClock.Mon, 12);
  589. }
  590. void setDecYear(void) {
  591. valDecrease(&setClock.Year, 99);
  592. }
  593. /**
  594. * @brief Increase BCD value.
  595. * @param : val, max
  596. * @retval : None
  597. */
  598. static void valIncrease(uint8_t * val, uint8_t max) {
  599. uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
  600. if (bin < max) {
  601. bin ++;
  602. } else {
  603. bin = 0;
  604. }
  605. *val = ((bin / 10 ) << 4) | (bin % 10);
  606. }
  607. /**
  608. * @brief Decrease BCD value.
  609. * @param : value, max
  610. * @retval : None
  611. */
  612. static void valDecrease(uint8_t * val, uint8_t max) {
  613. uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
  614. if (bin > 0) {
  615. bin --;
  616. } else {
  617. bin = max;
  618. }
  619. *val = ((bin / 10 ) << 4) | (bin % 10);
  620. }