General_view.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /*
  2. Unitemp - Universal temperature reader
  3. Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "UnitempViews.h"
  16. #include "unitemp_icons.h"
  17. #include <assets_icons.h>
  18. static View* view;
  19. typedef enum general_views {
  20. G_NO_SENSORS_VIEW, //Нет датчиков
  21. G_LIST_VIEW, //Вид в ввиде списка
  22. G_CAROUSEL_VIEW, //Карусель
  23. } general_view;
  24. typedef enum carousel_info {
  25. CAROUSEL_VALUES, //Отображение значений датчиков
  26. CAROUSEL_INFO, //Отображение информации о датчике
  27. } carousel_info;
  28. static general_view current_view;
  29. carousel_info carousel_info_selector = CAROUSEL_VALUES;
  30. uint8_t generalview_sensor_index = 0;
  31. static void _draw_temperature(Canvas* canvas, Sensor* sensor, uint8_t x, uint8_t y, Color color) {
  32. //Рисование рамки
  33. canvas_draw_rframe(canvas, x, y, 54, 20, 3);
  34. if(color == ColorBlack) {
  35. canvas_draw_rbox(canvas, x, y, 54, 19, 3);
  36. canvas_invert_color(canvas);
  37. } else {
  38. canvas_draw_rframe(canvas, x, y, 54, 19, 3);
  39. }
  40. int16_t temp_int = sensor->temp;
  41. int8_t temp_dec = abs((int16_t)(sensor->temp * 10) % 10);
  42. //Рисование иконки
  43. canvas_draw_icon(
  44. canvas, x + 3, y + 3, (app->settings.unit == CELSIUS ? &I_temp_C_11x14 : &I_temp_F_11x14));
  45. if((int16_t)sensor->temp == -128 || sensor->status == UT_SENSORSTATUS_TIMEOUT) {
  46. snprintf(app->buff, BUFF_SIZE, "--");
  47. canvas_set_font(canvas, FontBigNumbers);
  48. canvas_draw_str_aligned(canvas, x + 27, y + 10, AlignCenter, AlignCenter, app->buff);
  49. snprintf(app->buff, BUFF_SIZE, ". -");
  50. canvas_set_font(canvas, FontPrimary);
  51. canvas_draw_str_aligned(canvas, x + 50, y + 10 + 3, AlignRight, AlignCenter, app->buff);
  52. if(color == ColorBlack) canvas_invert_color(canvas);
  53. return;
  54. }
  55. //Целая часть температуры
  56. snprintf(app->buff, BUFF_SIZE, "%d", temp_int);
  57. canvas_set_font(canvas, FontBigNumbers);
  58. canvas_draw_str_aligned(
  59. canvas,
  60. x + 27 + ((temp_int <= -10 || temp_int > 99) ? 5 : 0),
  61. y + 10,
  62. AlignCenter,
  63. AlignCenter,
  64. app->buff);
  65. //Печать дробной части температуры в диапазоне от -9 до 99 (когда два знака в числе)
  66. if(temp_int > -10 && temp_int <= 99) {
  67. uint8_t int_len = canvas_string_width(canvas, app->buff);
  68. snprintf(app->buff, BUFF_SIZE, ".%d", temp_dec);
  69. canvas_set_font(canvas, FontPrimary);
  70. canvas_draw_str(canvas, x + 27 + int_len / 2 + 2, y + 10 + 7, app->buff);
  71. }
  72. if(color == ColorBlack) canvas_invert_color(canvas);
  73. }
  74. static void _draw_humidity(Canvas* canvas, Sensor* sensor, const uint8_t pos[2]) {
  75. //Рисование рамки
  76. canvas_draw_rframe(canvas, pos[0], pos[1], 54, 20, 3);
  77. canvas_draw_rframe(canvas, pos[0], pos[1], 54, 19, 3);
  78. //Рисование иконки
  79. canvas_draw_icon(canvas, pos[0] + 3, pos[1] + 2, &I_hum_9x15);
  80. if((int8_t)sensor->hum == -128 || sensor->status == UT_SENSORSTATUS_TIMEOUT) {
  81. snprintf(app->buff, BUFF_SIZE, "--");
  82. canvas_set_font(canvas, FontBigNumbers);
  83. canvas_draw_str_aligned(
  84. canvas, pos[0] + 27, pos[1] + 10, AlignCenter, AlignCenter, app->buff);
  85. snprintf(app->buff, BUFF_SIZE, ". -");
  86. canvas_set_font(canvas, FontPrimary);
  87. canvas_draw_str_aligned(
  88. canvas, pos[0] + 50, pos[1] + 10 + 3, AlignRight, AlignCenter, app->buff);
  89. return;
  90. }
  91. //Целая часть влажности
  92. snprintf(app->buff, BUFF_SIZE, "%d", (uint8_t)sensor->hum);
  93. canvas_set_font(canvas, FontBigNumbers);
  94. canvas_draw_str_aligned(canvas, pos[0] + 27, pos[1] + 10, AlignCenter, AlignCenter, app->buff);
  95. uint8_t int_len = canvas_string_width(canvas, app->buff);
  96. //Единица измерения
  97. canvas_set_font(canvas, FontPrimary);
  98. canvas_draw_str(canvas, pos[0] + 27 + int_len / 2 + 4, pos[1] + 10 + 7, "%");
  99. }
  100. static void _draw_pressure(Canvas* canvas, Sensor* sensor) {
  101. const uint8_t x = 29, y = 39;
  102. //Рисование рамки
  103. canvas_draw_rframe(canvas, x, y, 69, 20, 3);
  104. canvas_draw_rframe(canvas, x, y, 69, 19, 3);
  105. //Рисование иконки
  106. canvas_draw_icon(canvas, x + 3, y + 4, &I_pressure_7x13);
  107. //Давление
  108. snprintf(app->buff, BUFF_SIZE, "%d", (uint16_t)sensor->pressure);
  109. canvas_set_font(canvas, FontBigNumbers);
  110. canvas_draw_str_aligned(canvas, x + 30, y + 10, AlignCenter, AlignCenter, app->buff);
  111. //Единица измерения
  112. canvas_draw_icon(canvas, x + 50, y + 3, &I_mm_hg_17x15);
  113. }
  114. static void _draw_singleSensor(Canvas* canvas, Sensor* sensor, const uint8_t pos[2], Color color) {
  115. canvas_set_font(canvas, FontPrimary);
  116. const uint8_t max_width = 61;
  117. char sensor_name[12] = {0};
  118. memcpy(sensor_name, sensor->name, 10);
  119. if(canvas_string_width(canvas, sensor_name) > max_width) {
  120. uint8_t i = 10;
  121. while((canvas_string_width(canvas, sensor_name) > max_width - 6) && (i != 0)) {
  122. sensor_name[i--] = '\0';
  123. }
  124. sensor_name[++i] = '.';
  125. sensor_name[++i] = '.';
  126. }
  127. canvas_draw_str_aligned(
  128. canvas, pos[0] + 27, pos[1] + 3, AlignCenter, AlignCenter, sensor_name);
  129. _draw_temperature(canvas, sensor, pos[0], pos[1] + 8, color);
  130. }
  131. static void _draw_view_noSensors(Canvas* canvas) {
  132. canvas_draw_icon(canvas, 7, 17, &I_sherlok_53x45);
  133. //Рисование рамки
  134. canvas_draw_rframe(canvas, 0, 0, 128, 63, 7);
  135. canvas_draw_rframe(canvas, 0, 0, 128, 64, 7);
  136. canvas_set_font(canvas, FontPrimary);
  137. canvas_draw_str_aligned(canvas, 63, 10, AlignCenter, AlignCenter, "No sensors found");
  138. canvas_set_font(canvas, FontSecondary);
  139. const uint8_t x = 65, y = 32;
  140. canvas_draw_rframe(canvas, x - 4, y - 11, 54, 33, 3);
  141. canvas_draw_rframe(canvas, x - 4, y - 11, 54, 34, 3);
  142. canvas_draw_str(canvas, x, y, "To add the");
  143. canvas_draw_str(canvas, x, y + 9, "new sensor");
  144. canvas_draw_str(canvas, x, y + 18, "press OK");
  145. canvas_draw_icon(canvas, x + 37, y + 10, &I_Ok_btn_9x9);
  146. }
  147. static void _draw_view_sensorsList(Canvas* canvas) {
  148. //Текущая страница
  149. uint8_t page = generalview_sensor_index / 4;
  150. //Количество датчиков, которые будут отображаться на странице
  151. uint8_t page_sensors_count;
  152. if((unitemp_sensors_getActiveCount() - page * 4) / 4) {
  153. page_sensors_count = 4;
  154. } else {
  155. page_sensors_count = (unitemp_sensors_getActiveCount() - page * 4) % 4;
  156. }
  157. //Количество страниц
  158. uint8_t pages =
  159. unitemp_sensors_getActiveCount() / 4 + (unitemp_sensors_getActiveCount() % 4 ? 1 : 0);
  160. //Стрелка влево
  161. if(page > 0) {
  162. canvas_draw_icon(canvas, 2, 32, &I_ButtonLeft_4x7);
  163. }
  164. //Стрелка вправо
  165. if(pages > 0 && page < pages - 1) {
  166. canvas_draw_icon(canvas, 122, 32, &I_ButtonRight_4x7);
  167. }
  168. const uint8_t value_positions[][4][2] = {
  169. {{36, 18}}, //1 датчик
  170. {{7, 18}, {67, 18}}, //2 датчика
  171. {{7, 3}, {67, 3}, {37, 33}}, //3 датчика
  172. {{7, 3}, {67, 3}, {7, 33}, {67, 33}}}; //4 датчика
  173. //Рисование рамки
  174. canvas_draw_rframe(canvas, 0, 0, 128, 63, 7);
  175. canvas_draw_rframe(canvas, 0, 0, 128, 64, 7);
  176. for(uint8_t i = 0; i < page_sensors_count; i++) {
  177. _draw_singleSensor(
  178. canvas,
  179. unitemp_sensor_getActive(page * 4 + i),
  180. value_positions[page_sensors_count - 1][i],
  181. ColorWhite);
  182. }
  183. }
  184. static void _draw_carousel_values(Canvas* canvas) {
  185. UnitempStatus sensor_status = unitemp_sensor_getActive(generalview_sensor_index)->status;
  186. if(sensor_status == UT_SENSORSTATUS_ERROR || sensor_status == UT_SENSORSTATUS_TIMEOUT) {
  187. const Icon* frames[] = {
  188. &I_flipper_happy_60x38, &I_flipper_happy_2_60x38, &I_flipper_sad_60x38};
  189. canvas_draw_icon(canvas, 34, 23, frames[furi_get_tick() % 2250 / 750]);
  190. canvas_set_font(canvas, FontSecondary);
  191. if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &SINGLE_WIRE) {
  192. snprintf(
  193. app->buff,
  194. BUFF_SIZE,
  195. "Waiting for module on pin %d",
  196. ((SingleWireSensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance)
  197. ->gpio->num);
  198. }
  199. if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &ONE_WIRE) {
  200. snprintf(
  201. app->buff,
  202. BUFF_SIZE,
  203. "Waiting for module on pin %d",
  204. ((OneWireSensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance)
  205. ->bus->gpio->num);
  206. }
  207. if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &I2C) {
  208. snprintf(app->buff, BUFF_SIZE, "Waiting for module on I2C pins");
  209. }
  210. canvas_draw_str_aligned(canvas, 64, 19, AlignCenter, AlignCenter, app->buff);
  211. return;
  212. }
  213. static const uint8_t temp_positions[3][2] = {{37, 23}, {37, 16}, {9, 16}};
  214. static const uint8_t hum_positions[2][2] = {{37, 38}, {65, 16}};
  215. //Селектор значений для отображения
  216. switch(unitemp_sensor_getActive(generalview_sensor_index)->type->datatype) {
  217. case UT_DATA_TYPE_TEMP:
  218. _draw_temperature(
  219. canvas,
  220. unitemp_sensor_getActive(generalview_sensor_index),
  221. temp_positions[0][0],
  222. temp_positions[0][1],
  223. ColorWhite);
  224. break;
  225. case UT_DATA_TYPE_TEMP_HUM:
  226. _draw_temperature(
  227. canvas,
  228. unitemp_sensor_getActive(generalview_sensor_index),
  229. temp_positions[1][0],
  230. temp_positions[1][1],
  231. ColorWhite);
  232. _draw_humidity(
  233. canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[0]);
  234. break;
  235. case UT_DATA_TYPE_TEMP_PRESS:
  236. _draw_temperature(
  237. canvas,
  238. unitemp_sensor_getActive(generalview_sensor_index),
  239. temp_positions[1][0],
  240. temp_positions[1][1],
  241. ColorWhite);
  242. _draw_pressure(canvas, unitemp_sensor_getActive(generalview_sensor_index));
  243. break;
  244. case UT_DATA_TYPE_TEMP_HUM_PRESS:
  245. _draw_temperature(
  246. canvas,
  247. unitemp_sensor_getActive(generalview_sensor_index),
  248. temp_positions[2][0],
  249. temp_positions[2][1],
  250. ColorWhite);
  251. _draw_humidity(
  252. canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[1]);
  253. _draw_pressure(canvas, unitemp_sensor_getActive(generalview_sensor_index));
  254. break;
  255. }
  256. }
  257. static void _draw_carousel_info(Canvas* canvas) {
  258. canvas_set_font(canvas, FontPrimary);
  259. canvas_draw_str(canvas, 10, 23, "Type:");
  260. if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &ONE_WIRE) {
  261. OneWireSensor* s = unitemp_sensor_getActive(generalview_sensor_index)->instance;
  262. canvas_set_font(canvas, FontPrimary);
  263. canvas_draw_str(canvas, 10, 35, "GPIO:");
  264. canvas_draw_str(canvas, 10, 47, "ID:");
  265. canvas_set_font(canvas, FontSecondary);
  266. canvas_draw_str(
  267. canvas,
  268. 41,
  269. 23,
  270. unitemp_onewire_sensor_getModel(unitemp_sensor_getActive(generalview_sensor_index)));
  271. canvas_draw_str(canvas, 41, 35, s->bus->gpio->name);
  272. snprintf(
  273. app->buff,
  274. BUFF_SIZE,
  275. "%02X%02X%02X%02X%02X%02X%02X%02X",
  276. s->deviceID[0],
  277. s->deviceID[1],
  278. s->deviceID[2],
  279. s->deviceID[3],
  280. s->deviceID[4],
  281. s->deviceID[5],
  282. s->deviceID[6],
  283. s->deviceID[7]);
  284. canvas_draw_str(canvas, 24, 47, app->buff);
  285. }
  286. if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &SINGLE_WIRE) {
  287. canvas_set_font(canvas, FontPrimary);
  288. canvas_draw_str(canvas, 10, 35, "GPIO:");
  289. canvas_set_font(canvas, FontSecondary);
  290. canvas_draw_str(
  291. canvas, 41, 23, unitemp_sensor_getActive(generalview_sensor_index)->type->typename);
  292. canvas_draw_str(
  293. canvas,
  294. 41,
  295. 35,
  296. ((SingleWireSensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance)
  297. ->gpio->name);
  298. }
  299. if(unitemp_sensor_getActive(generalview_sensor_index)->type->interface == &I2C) {
  300. canvas_set_font(canvas, FontPrimary);
  301. canvas_draw_str(canvas, 10, 35, "I2C addr:");
  302. canvas_draw_str(canvas, 10, 46, "SDA pin:");
  303. canvas_draw_str(canvas, 10, 58, "SCL pin:");
  304. canvas_set_font(canvas, FontSecondary);
  305. canvas_draw_str(
  306. canvas, 41, 23, unitemp_sensor_getActive(generalview_sensor_index)->type->typename);
  307. snprintf(
  308. app->buff,
  309. BUFF_SIZE,
  310. "0x%02X",
  311. ((I2CSensor*)unitemp_sensor_getActive(generalview_sensor_index)->instance)
  312. ->currentI2CAdr);
  313. canvas_draw_str(canvas, 57, 35, app->buff);
  314. canvas_draw_str(canvas, 54, 46, "16 (C1)");
  315. canvas_draw_str(canvas, 54, 58, "15 (C0)");
  316. }
  317. }
  318. static void _draw_view_sensorsCarousel(Canvas* canvas) {
  319. //Рисование рамки
  320. canvas_draw_rframe(canvas, 0, 0, 128, 63, 7);
  321. canvas_draw_rframe(canvas, 0, 0, 128, 64, 7);
  322. //Печать имени
  323. canvas_set_font(canvas, FontPrimary);
  324. canvas_draw_str_aligned(
  325. canvas,
  326. 64,
  327. 7,
  328. AlignCenter,
  329. AlignCenter,
  330. unitemp_sensor_getActive(generalview_sensor_index)->name);
  331. //Подчёркивание
  332. uint8_t line_len =
  333. canvas_string_width(canvas, unitemp_sensor_getActive(generalview_sensor_index)->name) + 2;
  334. canvas_draw_line(canvas, 64 - line_len / 2, 12, 64 + line_len / 2, 12);
  335. //Стрелка вправо
  336. if(unitemp_sensors_getTypesCount() > 0 &&
  337. generalview_sensor_index < unitemp_sensors_getActiveCount() - 1) {
  338. canvas_draw_icon(canvas, 122, 29, &I_ButtonRight_4x7);
  339. }
  340. //Стрелка влево
  341. if(generalview_sensor_index > 0) {
  342. canvas_draw_icon(canvas, 2, 29, &I_ButtonLeft_4x7);
  343. }
  344. switch(carousel_info_selector) {
  345. case CAROUSEL_VALUES:
  346. _draw_carousel_values(canvas);
  347. break;
  348. case CAROUSEL_INFO:
  349. _draw_carousel_info(canvas);
  350. break;
  351. }
  352. }
  353. static void _draw_callback(Canvas* canvas, void* _model) {
  354. UNUSED(_model);
  355. app->sensors_ready = true;
  356. uint8_t sensors_count = unitemp_sensors_getActiveCount();
  357. if(generalview_sensor_index + 1 > sensors_count) generalview_sensor_index = 0;
  358. if(sensors_count == 0) {
  359. current_view = G_NO_SENSORS_VIEW;
  360. _draw_view_noSensors(canvas);
  361. } else {
  362. if(sensors_count == 1) current_view = G_CAROUSEL_VIEW;
  363. if(current_view == G_NO_SENSORS_VIEW) current_view = G_CAROUSEL_VIEW;
  364. if(current_view == G_LIST_VIEW) _draw_view_sensorsList(canvas);
  365. if(current_view == G_CAROUSEL_VIEW) _draw_view_sensorsCarousel(canvas);
  366. }
  367. }
  368. static bool _input_callback(InputEvent* event, void* context) {
  369. UNUSED(context);
  370. //Обработка короткого нажатия "ок"
  371. if(event->key == InputKeyOk && event->type == InputTypeShort) {
  372. //Меню добавления датчика при их отсутствии
  373. if(current_view == G_NO_SENSORS_VIEW) {
  374. app->sensors_ready = false;
  375. unitemp_SensorsList_switch();
  376. } else if(current_view == G_LIST_VIEW) {
  377. //Переход в главное меню при выключенном селекторе
  378. app->sensors_ready = false;
  379. unitemp_MainMenu_switch();
  380. } else if(current_view == G_CAROUSEL_VIEW) {
  381. app->sensors_ready = false;
  382. unitemp_SensorActions_switch(unitemp_sensor_getActive(generalview_sensor_index));
  383. }
  384. }
  385. //Обработка короткого нажатия "вниз"
  386. if(event->key == InputKeyDown && event->type == InputTypeShort) {
  387. //Переход из значений в информацию в карусели
  388. if(current_view == G_CAROUSEL_VIEW && carousel_info_selector == CAROUSEL_VALUES) {
  389. carousel_info_selector = CAROUSEL_INFO;
  390. return true;
  391. }
  392. //Переход в карусель из списка
  393. if(current_view == G_LIST_VIEW) {
  394. current_view = G_CAROUSEL_VIEW;
  395. return true;
  396. }
  397. }
  398. //Обработка короткого нажатия "вверх"
  399. if(event->key == InputKeyUp && event->type == InputTypeShort) {
  400. //Переход из информации в значения в карусели
  401. if(current_view == G_CAROUSEL_VIEW && carousel_info_selector == CAROUSEL_INFO) {
  402. carousel_info_selector = CAROUSEL_VALUES;
  403. return true;
  404. }
  405. //Переход в список из карусели
  406. if(current_view == G_CAROUSEL_VIEW && carousel_info_selector == CAROUSEL_VALUES &&
  407. unitemp_sensors_getActiveCount() > 1) {
  408. current_view = G_LIST_VIEW;
  409. return true;
  410. }
  411. }
  412. //Обработка короткого нажатия "вправо"
  413. if(event->key == InputKeyRight && event->type == InputTypeShort) {
  414. //Пролистывание карусели вперёд
  415. if(current_view == G_CAROUSEL_VIEW) {
  416. if(++generalview_sensor_index >= unitemp_sensors_getActiveCount()) {
  417. generalview_sensor_index = 0;
  418. if(carousel_info_selector == CAROUSEL_VALUES) current_view = G_LIST_VIEW;
  419. }
  420. return true;
  421. }
  422. //Пролистывание списка вперёд
  423. if(current_view == G_LIST_VIEW) {
  424. generalview_sensor_index += 4;
  425. if(generalview_sensor_index >= unitemp_sensors_getActiveCount()) {
  426. generalview_sensor_index = 0;
  427. current_view = G_CAROUSEL_VIEW;
  428. }
  429. return true;
  430. }
  431. }
  432. //Обработка короткого нажатия "влево"
  433. if(event->key == InputKeyLeft && event->type == InputTypeShort) {
  434. //Пролистывание карусели назад
  435. if(current_view == G_CAROUSEL_VIEW) {
  436. if(--generalview_sensor_index >= unitemp_sensors_getActiveCount()) {
  437. generalview_sensor_index = unitemp_sensors_getActiveCount() - 1;
  438. if(carousel_info_selector == CAROUSEL_VALUES) current_view = G_LIST_VIEW;
  439. }
  440. return true;
  441. }
  442. //Пролистывание списка назад
  443. if(current_view == G_LIST_VIEW) {
  444. generalview_sensor_index -= 4;
  445. if(generalview_sensor_index >= unitemp_sensors_getActiveCount()) {
  446. generalview_sensor_index = unitemp_sensors_getActiveCount() - 1;
  447. current_view = G_CAROUSEL_VIEW;
  448. }
  449. return true;
  450. }
  451. }
  452. //Обработка короткого нажатия "назад"
  453. if(event->key == InputKeyBack && event->type == InputTypeShort) {
  454. //Выход из приложения при карусели или отсутствии датчиков
  455. if(current_view == G_NO_SENSORS_VIEW ||
  456. ((current_view == G_CAROUSEL_VIEW) && (carousel_info_selector == CAROUSEL_VALUES))) {
  457. app->processing = false;
  458. return true;
  459. }
  460. //Переключение селектора вида карусели
  461. if((current_view == G_CAROUSEL_VIEW) && (carousel_info_selector != CAROUSEL_VALUES)) {
  462. carousel_info_selector = CAROUSEL_VALUES;
  463. return true;
  464. }
  465. //Переход в карусель из списка
  466. if(current_view == G_LIST_VIEW) {
  467. current_view = G_CAROUSEL_VIEW;
  468. return true;
  469. }
  470. }
  471. return true;
  472. }
  473. void unitemp_General_alloc(void) {
  474. view = view_alloc();
  475. view_set_context(view, app);
  476. view_set_draw_callback(view, _draw_callback);
  477. view_set_input_callback(view, _input_callback);
  478. view_dispatcher_add_view(app->view_dispatcher, UnitempViewGeneral, view);
  479. }
  480. void unitemp_General_switch(void) {
  481. app->sensors_ready = true;
  482. view_dispatcher_switch_to_view(app->view_dispatcher, UnitempViewGeneral);
  483. }
  484. void unitemp_General_free(void) {
  485. view_free(view);
  486. }