Minor alignment of rgb_breathe_table generator (#19403)
This commit is contained in:
parent
99b69dc80e
commit
ab1898e660
@ -5,7 +5,9 @@ from argparse import ArgumentTypeError
|
||||
|
||||
from milc import cli
|
||||
|
||||
import qmk.path
|
||||
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
||||
from qmk.commands import dump_lines
|
||||
from qmk.path import normpath
|
||||
|
||||
|
||||
def breathing_center(value):
|
||||
@ -24,17 +26,10 @@ def breathing_max(value):
|
||||
raise ArgumentTypeError('Breathing max must be between 0 and 255')
|
||||
|
||||
|
||||
@cli.argument('-c', '--center', arg_only=True, type=breathing_center, default=1.85, help='The breathing center value, from 1 to 2.7. Default: 1.85')
|
||||
@cli.argument('-m', '--max', arg_only=True, type=breathing_max, default=255, help='The breathing maximum value, from 0 to 255. Default: 255')
|
||||
@cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to')
|
||||
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help='Quiet mode, only output error messages')
|
||||
@cli.subcommand('Generates an RGB Light breathing table header.')
|
||||
def generate_rgb_breathe_table(cli):
|
||||
"""Generate a rgblight_breathe_table.h file containing a breathing LUT for RGB Lighting (Underglow) feature.
|
||||
"""
|
||||
def _generate_table(lines, center, maximum):
|
||||
breathe_values = [0] * 256
|
||||
for pos in range(0, 256):
|
||||
breathe_values[pos] = (int)((math.exp(math.sin((pos / 255) * math.pi)) - cli.args.center / math.e) * (cli.args.max / (math.e - 1 / math.e)))
|
||||
breathe_values[pos] = (int)((math.exp(math.sin((pos / 255) * math.pi)) - center / math.e) * (maximum / (math.e - 1 / math.e)))
|
||||
|
||||
values_template = ''
|
||||
for s in range(0, 3):
|
||||
@ -51,11 +46,7 @@ def generate_rgb_breathe_table(cli):
|
||||
values_template += '#endif'
|
||||
values_template += '\n\n' if s < 2 else ''
|
||||
|
||||
table_template = '''#pragma once
|
||||
|
||||
#define RGBLIGHT_EFFECT_BREATHE_TABLE
|
||||
|
||||
// clang-format off
|
||||
table_template = '''#define RGBLIGHT_EFFECT_BREATHE_TABLE
|
||||
|
||||
// Breathing center: {0:.2f}
|
||||
// Breathing max: {1:d}
|
||||
@ -65,15 +56,23 @@ const uint8_t PROGMEM rgblight_effect_breathe_table[] = {{
|
||||
}};
|
||||
|
||||
static const int table_scale = 256 / sizeof(rgblight_effect_breathe_table);
|
||||
'''.format(cli.args.center, cli.args.max, values_template)
|
||||
'''.format(center, maximum, values_template)
|
||||
lines.append(table_template)
|
||||
|
||||
if cli.args.output:
|
||||
cli.args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||
if cli.args.output.exists():
|
||||
cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak'))
|
||||
cli.args.output.write_text(table_template)
|
||||
|
||||
if not cli.args.quiet:
|
||||
cli.log.info('Wrote header to %s.', cli.args.output)
|
||||
else:
|
||||
print(table_template)
|
||||
@cli.argument('-c', '--center', arg_only=True, type=breathing_center, default=1.85, help='The breathing center value, from 1 to 2.7. Default: 1.85')
|
||||
@cli.argument('-m', '--max', arg_only=True, type=breathing_max, default=255, help='The breathing maximum value, from 0 to 255. Default: 255')
|
||||
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
|
||||
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help='Quiet mode, only output error messages')
|
||||
@cli.subcommand('Generates an RGB Light breathing table header.')
|
||||
def generate_rgb_breathe_table(cli):
|
||||
"""Generate a rgblight_breathe_table.h file containing a breathing LUT for RGB Lighting (Underglow) feature.
|
||||
"""
|
||||
|
||||
# Build the header file.
|
||||
header_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '// clang-format off']
|
||||
|
||||
_generate_table(header_lines, cli.args.center, cli.args.max)
|
||||
|
||||
# Show the results
|
||||
dump_lines(cli.args.output, header_lines, cli.args.quiet)
|
||||
|
@ -1,8 +1,31 @@
|
||||
// Copyright 2022 QMK
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
/*******************************************************************************
|
||||
88888888888 888 d8b .d888 d8b 888 d8b
|
||||
888 888 Y8P d88P" Y8P 888 Y8P
|
||||
888 888 888 888
|
||||
888 88888b. 888 .d8888b 888888 888 888 .d88b. 888 .d8888b
|
||||
888 888 "88b 888 88K 888 888 888 d8P Y8b 888 88K
|
||||
888 888 888 888 "Y8888b. 888 888 888 88888888 888 "Y8888b.
|
||||
888 888 888 888 X88 888 888 888 Y8b. 888 X88
|
||||
888 888 888 888 88888P' 888 888 888 "Y8888 888 88888P'
|
||||
888 888
|
||||
888 888
|
||||
888 888
|
||||
.d88b. .d88b. 88888b. .d88b. 888d888 8888b. 888888 .d88b. .d88888
|
||||
d88P"88b d8P Y8b 888 "88b d8P Y8b 888P" "88b 888 d8P Y8b d88" 888
|
||||
888 888 88888888 888 888 88888888 888 .d888888 888 88888888 888 888
|
||||
Y88b 888 Y8b. 888 888 Y8b. 888 888 888 Y88b. Y8b. Y88b 888
|
||||
"Y88888 "Y8888 888 888 "Y8888 888 "Y888888 "Y888 "Y8888 "Y88888
|
||||
888
|
||||
Y8b d88P
|
||||
"Y88P"
|
||||
*******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define RGBLIGHT_EFFECT_BREATHE_TABLE
|
||||
|
||||
// clang-format off
|
||||
#define RGBLIGHT_EFFECT_BREATHE_TABLE
|
||||
|
||||
// Breathing center: 1.85
|
||||
// Breathing max: 255
|
||||
@ -115,3 +138,4 @@ const uint8_t PROGMEM rgblight_effect_breathe_table[] = {
|
||||
};
|
||||
|
||||
static const int table_scale = 256 / sizeof(rgblight_effect_breathe_table);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user