|
| 1 | +/* |
| 2 | + * Copyright (C) EdgeTX |
| 3 | + * |
| 4 | + * Based on code named |
| 5 | + * opentx - https://github.com/opentx/opentx |
| 6 | + * th9x - http://code.google.com/p/th9x |
| 7 | + * er9x - http://code.google.com/p/er9x |
| 8 | + * gruvin9x - http://code.google.com/p/gruvin9x |
| 9 | + * |
| 10 | + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html |
| 11 | + * |
| 12 | + * This program is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License version 2 as |
| 14 | + * published by the Free Software Foundation. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + */ |
| 21 | + |
| 22 | +#include "edgetx.h" |
| 23 | +#include "os/sleep.h" |
| 24 | + |
| 25 | +#if defined(SERVO_PWM) |
| 26 | + |
| 27 | +#if LCD_W >= 212 |
| 28 | + #define HW_SETTINGS_COLUMN1 12*FW |
| 29 | + #define HW_SETTINGS_COLUMN2 (20*FW - 3) |
| 30 | + #define HW_SETTINGS_COLUMN3 HW_SETTINGS_COLUMN2 |
| 31 | +#else |
| 32 | + #define HW_SETTINGS_COLUMN1 30 |
| 33 | + #define HW_SETTINGS_COLUMN2 (HW_SETTINGS_COLUMN1 + 5*FW) |
| 34 | + #define HW_SETTINGS_COLUMN3 HW_SETTINGS_COLUMN2 + FW |
| 35 | +#endif |
| 36 | + |
| 37 | +#if !defined(SIMU) |
| 38 | +extern void pwmOutputDisable(); |
| 39 | +extern void pwmOutputInit(); |
| 40 | +extern void pwmOutputEnable(uint16_t pulse_width_us); |
| 41 | +#else |
| 42 | +void pwmOutputDisable() {} |
| 43 | +void pwmOutputInit() {} |
| 44 | +void pwmOutputEnable(uint16_t) {} |
| 45 | +#endif |
| 46 | + |
| 47 | +static uint8_t pwmOutputSource; |
| 48 | + |
| 49 | +enum { |
| 50 | + ITEM_PWM_SOURCE, |
| 51 | + ITEM_SERVO_PWM_MAX, |
| 52 | +}; |
| 53 | + |
| 54 | +void menuServoPwmTool(event_t event) |
| 55 | +{ |
| 56 | + SUBMENU(STR_PWM_OUTPUT, 0, {0}); |
| 57 | + |
| 58 | + if (menuEvent == EVT_ENTRY_UP) { |
| 59 | + TRACE("stopping servo pwm..."); |
| 60 | + pwmOutputDisable(); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + if (event == EVT_ENTRY) { |
| 65 | + TRACE("starting servo pwm..."); |
| 66 | + pwmOutputSource = MIXSRC_NONE; |
| 67 | + pwmOutputInit(); |
| 68 | + } |
| 69 | + |
| 70 | + if (pwmOutputSource > MIXSRC_NONE) { |
| 71 | + mixsrc_t chan = pwmOutputSource - MIXSRC_FIRST; |
| 72 | + pwmOutputEnable(PPM_CH_CENTER(chan) + channelOutputs[chan] / 2); |
| 73 | + } else { |
| 74 | + pwmOutputDisable(); |
| 75 | + } |
| 76 | + |
| 77 | + for (int i = 0; i < ITEM_SERVO_PWM_MAX; i++) { |
| 78 | + LcdFlags attr = (menuVerticalPosition == i ? (s_editMode > 0 ? INVERS | BLINK : INVERS) : 0); |
| 79 | + coord_t y = MENU_HEADER_HEIGHT + 12 + i * FH; |
| 80 | + |
| 81 | + switch (i) { |
| 82 | + case ITEM_PWM_SOURCE: |
| 83 | + lcdDrawTextAlignedLeft(y, STR_PWM_OUTPUT); |
| 84 | + drawSource(HW_SETTINGS_COLUMN2, y, pwmOutputSource, attr); |
| 85 | + if (attr & BLINK) |
| 86 | + CHECK_INCDEC_GENVAR(event, pwmOutputSource, 0, MAX_OUTPUT_CHANNELS); |
| 87 | + break; |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +#endif |
| 93 | + |
0 commit comments