Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Sound menu tweaks #161

wants to merge 2 commits into from

Conversation

noisedsn
Copy link
Contributor

buttons A/D as +/-; back item renamed.


while (true) {
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
lilka::controller.setAutoRepeat(lilka::Button::A, 0, 0);
Copy link
Collaborator

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);
аби не їсти всі наявні ресурси процесора
тому винести всю цю штуку обов'язково назовні

Copy link
Collaborator

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;
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

за замовчуванням автоповтор кнопок не налаштовано.
тому ти його налаштовуєш до того всіх оцих циклів, перед while(true)

і повертаєш перед виходом передавши в setAutorepeat нулі перед виходом(неважливо кнопкою B чи при виборі пункту меню)

наявний код працює з певним шансом, що автоповтор залишиться встановленим при виході з твого додатку

Copy link
Collaborator

@frostmorn frostmorn Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зажми кнопку A при виборі пункту гучність, а потім нажми стрілочку вверх аби це побачити :D
автоповтор спрацює для пункту назад, і так як відмальовувати буде нічого, ти вийдеш до того
як значення контроллера повернуться в норму, тому твій додаток буде знову відкрито :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

після цього відповідно просто вибери пункт назад або натисни B, побачиш прикол

@frostmorn frostmorn added enhancement New feature or request scope:keira labels Dec 27, 2024
@frostmorn
Copy link
Collaborator

на мій погляд ти вже трошки перемудрив тут, пішов читати


if (index == 3 || menu.getButton() == lilka::Button::B) {
break;
} else if (index == 0) {
Copy link
Collaborator

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 і так далі.
просто обробив ситуацію, забув про неї

Copy link
Collaborator

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();
Copy link
Collaborator

@frostmorn frostmorn Dec 28, 2024

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();
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

винесення подібного в константи прекрасна думка

@frostmorn frostmorn closed this Dec 28, 2024
@frostmorn
Copy link
Collaborator

#172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scope:keira
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants