-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sound menu tweaks #161
Sound menu tweaks #161
Conversation
|
||
while (true) { | ||
while (!menu.isFinished()) { | ||
menu.update(); | ||
menu.draw(canvas); | ||
queueDraw(); | ||
lilka::controller.setAutoRepeat(lilka::Button::A, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в цьому циклі нічого крім відмальовування не повинно бути. взагалі. можна хіба що додати щось типу
vTaskDelay(5 / portTICK_PERIOD_MS);
аби не їсти всі наявні ресурси процесора
тому винести всю цю штуку обов'язково назовні
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ситуації в яких це потрібно можливі, але це не твоя ситуація :)
} else { | ||
volumeLevel = 0; | ||
} | ||
int increment = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
так само, твій інкремент ніколи не змінюється. немає необхідності його постійно переписувати.
ідеально винести як макрос в заголовочний файл audio.h
#define VOLUME_INCREMENT 5
це дозволить за необхідності керувати цим налаштуванням і не копатися в коді
|
||
delay(100); // AutoRepeat чомусь не працює правильно в меню | ||
lilka::controller.setAutoRepeat(lilka::Button::A, 100, 500); | ||
lilka::controller.setAutoRepeat(lilka::Button::D, 100, 500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
за замовчуванням автоповтор кнопок не налаштовано.
тому ти його налаштовуєш до того всіх оцих циклів, перед while(true)
і повертаєш перед виходом передавши в setAutorepeat нулі перед виходом(неважливо кнопкою B чи при виборі пункту меню)
наявний код працює з певним шансом, що автоповтор залишиться встановленим при виході з твого додатку
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зажми кнопку A при виборі пункту гучність, а потім нажми стрілочку вверх аби це побачити :D
автоповтор спрацює для пункту назад, і так як відмальовувати буде нічого, ти вийдеш до того
як значення контроллера повернуться в норму, тому твій додаток буде знову відкрито :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
після цього відповідно просто вибери пункт назад або натисни B, побачиш прикол
… one was written.
на мій погляд ти вже трошки перемудрив тут, пішов читати |
|
||
if (index == 3 || menu.getButton() == lilka::Button::B) { | ||
break; | ||
} else if (index == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можна break на 30 стрічці замінити на return, це буде значити моментальний вихід з функції.
тому не потрібно буде мільйони вкладень if в if в if і так далі.
просто обробив ситуацію, забув про неї
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
дуже вдобно використовувати з різноманітними перевірками типу
відкрити файл, а файл відкрився?
відкрити директорію, а вона відкрилася? і etc.
тому мотай на вус :)
} else if (index == 0) { | ||
bool justPressed = true; | ||
|
||
lilka::State state = lilka::controller.getState(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
наіщо чіпати той нещасний контролер, якщо ця інфа є в меню.
зроби проосто на 26 стрічці auto button = menu.getButton() і оброблюй її всюди
lilka::State state = lilka::controller.getState(); | ||
|
||
while (state.a.pressed || state.d.pressed) { | ||
unsigned long repeatStart = millis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
попередній варіант з використанням автоповтору контролера мені подобався значно значно більше
@@ -1,3 +1,6 @@ | |||
#define VOLUME_INCREMENT 5 | |||
#define REPEAT_INTERVAL 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
винесення подібного в константи прекрасна думка
buttons A/D as +/-; back item renamed.