0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 22:31:25 +03:00

167 lines
3.4 KiB
C
Raw Normal View History

2023-09-09 08:03:56 +01:00
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2023-10-06 00:18:47 +01:00
#ifdef ENABLE_PWRON_PASSWORD
2023-09-09 08:03:56 +01:00
#include <string.h>
2023-09-10 13:52:41 +01:00
2023-09-09 08:03:56 +01:00
#include "ARMCM0.h"
#include "app/uart.h"
#include "audio.h"
#include "driver/keyboard.h"
#include "driver/st7565.h"
#include "misc.h"
#include "settings.h"
#include "ui/helper.h"
#include "ui/inputbox.h"
#include "ui/lock.h"
static void Render(void)
{
unsigned int i;
2023-09-09 11:17:45 +01:00
char String[7];
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
memset(g_status_line, 0, sizeof(g_status_line));
memset(g_frame_buffer, 0, sizeof(g_frame_buffer));
2023-09-09 08:03:56 +01:00
strcpy(String, "LOCK");
2023-09-12 15:31:37 +01:00
UI_PrintString(String, 0, 127, 1, 10);
2023-09-09 08:03:56 +01:00
for (i = 0; i < 6; i++)
2023-10-08 20:23:37 +01:00
String[i] = (g_input_box[i] == 10) ? '-' : '*';
2023-09-09 08:03:56 +01:00
String[6] = 0;
2023-09-12 15:31:37 +01:00
UI_PrintString(String, 0, 127, 3, 12);
2023-09-09 08:03:56 +01:00
ST7565_BlitStatusLine();
ST7565_BlitFullScreen();
}
void UI_DisplayLock(void)
{
2023-10-13 17:46:28 +01:00
unsigned int g_debounce_counter = 0;
// bool g_key_being_held = false;
key_code_t g_key_reading_0 = KEY_INVALID;
// key_code_t g_key_reading_1;
key_code_t Key;
beep_type_t Beep;
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
g_update_display = true;
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
memset(g_input_box, 10, sizeof(g_input_box));
2023-09-09 08:03:56 +01:00
while (1)
{
2023-10-08 20:23:37 +01:00
while (!g_next_time_slice) {}
2023-09-09 08:03:56 +01:00
// TODO: Original code doesn't do the below, but is needed for proper key debounce
2023-10-08 20:23:37 +01:00
g_next_time_slice = false;
2023-09-14 19:38:28 +01:00
Key = KEYBOARD_Poll();
2023-09-09 08:03:56 +01:00
2023-10-08 17:14:13 +01:00
if (g_key_reading_0 == Key)
2023-09-09 08:03:56 +01:00
{
2023-10-08 17:14:13 +01:00
if (++g_debounce_counter == key_debounce_10ms)
2023-09-09 08:03:56 +01:00
{
if (Key == KEY_INVALID)
{
2023-10-13 17:46:28 +01:00
// g_key_reading_1 = KEY_INVALID;
2023-09-09 08:03:56 +01:00
}
else
{
2023-10-13 17:46:28 +01:00
// g_key_reading_1 = Key;
2023-09-09 08:03:56 +01:00
switch (Key)
{
case KEY_0:
case KEY_1:
case KEY_2:
case KEY_3:
case KEY_4:
case KEY_5:
case KEY_6:
case KEY_7:
case KEY_8:
case KEY_9:
2023-10-26 14:10:11 +01:00
INPUTBOX_append(Key - KEY_0);
2023-09-14 19:38:28 +01:00
2023-10-08 20:23:37 +01:00
if (g_input_box_index < 6) // 6 frequency digits
2023-09-09 08:03:56 +01:00
{
Beep = BEEP_1KHZ_60MS_OPTIONAL;
}
else
{
uint32_t Password;
2023-10-08 20:23:37 +01:00
g_input_box_index = 0;
2023-09-09 08:03:56 +01:00
2023-10-08 20:23:37 +01:00
NUMBER_Get(g_input_box, &Password);
2023-09-09 08:03:56 +01:00
2023-10-08 17:14:13 +01:00
if ((g_eeprom.power_on_password * 100) == Password)
2023-09-09 08:03:56 +01:00
{
AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL);
return;
}
2023-10-08 20:23:37 +01:00
memset(g_input_box, 10, sizeof(g_input_box));
2023-09-09 08:03:56 +01:00
Beep = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
}
AUDIO_PlayBeep(Beep);
2023-10-08 20:23:37 +01:00
g_update_display = true;
2023-09-09 08:03:56 +01:00
break;
case KEY_EXIT:
2023-10-08 20:23:37 +01:00
if (g_input_box_index > 0)
2023-09-09 08:03:56 +01:00
{
2023-10-08 20:23:37 +01:00
g_input_box[--g_input_box_index] = 10;
g_update_display = true;
2023-09-09 08:03:56 +01:00
}
AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL);
default:
break;
}
}
2023-10-13 17:46:28 +01:00
// g_key_being_held = false;
2023-09-09 08:03:56 +01:00
}
}
else
{
2023-10-08 17:14:13 +01:00
g_debounce_counter = 0;
2023-10-13 17:46:28 +01:00
g_key_reading_0 = Key;
2023-09-09 08:03:56 +01:00
}
if (UART_IsCommandAvailable())
{
__disable_irq();
UART_HandleCommand();
__enable_irq();
}
2023-10-08 20:23:37 +01:00
if (g_update_display)
2023-09-09 08:03:56 +01:00
{
Render();
2023-10-08 20:23:37 +01:00
g_update_display = false;
2023-09-09 08:03:56 +01:00
}
}
}
2023-10-06 00:18:47 +01:00
#endif