[FL-1443, FL-1289] Move assets compilation to separate Makefile. Add scripts folder. Add OTP flashing with DFU. (#531)
* Assets: move assets compilation to separate Makefile. Move all scripts to scripts folder. Add scripts ReadMe. Add precompiled assets. * Split assets.py into separate entities. Option bytes for FL-1289 and checker/setter. * Cli: explicitly initialize variable befor use in api_hal_vcp_rx_with_timeout * Rename ob_check script to ob.
This commit is contained in:
11
assets/Makefile
Normal file
11
assets/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
PROJECT_ROOT = $(abspath $(dir $(abspath $(firstword $(MAKEFILE_LIST))))..)
|
||||
|
||||
include $(PROJECT_ROOT)/assets/assets.mk
|
||||
|
||||
$(ASSETS): $(ASSETS_SOURCES) $(ASSETS_COMPILLER)
|
||||
@echo "\tASSETS\t" $@
|
||||
@$(ASSETS_COMPILLER) icons -s $(ASSETS_SOURCE_DIR) -o $(ASSETS_COMPILED_DIR)
|
||||
|
||||
clean:
|
||||
@echo "\tCLEAN\t"
|
||||
@$(RM) $(ASSETS)
|
@@ -1,3 +1,13 @@
|
||||
# Requirements
|
||||
|
||||
- Python3
|
||||
- ImageMagic
|
||||
- Make
|
||||
|
||||
# Compiling
|
||||
|
||||
make all
|
||||
|
||||
# Asset naming rules
|
||||
|
||||
## Images and Animations
|
||||
|
@@ -1,10 +1,10 @@
|
||||
ASSETS_DIR := $(PROJECT_ROOT)/assets
|
||||
ASSETS_COMPILLER := $(ASSETS_DIR)/assets.py
|
||||
ASSETS_OUTPUT_DIR := $(ASSETS_DIR)/output
|
||||
ASSETS_COMPILLER := $(PROJECT_ROOT)/scripts/assets.py
|
||||
ASSETS_COMPILED_DIR := $(ASSETS_DIR)/compiled
|
||||
ASSETS_SOURCE_DIR := $(ASSETS_DIR)/icons
|
||||
|
||||
ASSETS_SOURCES += $(shell find $(ASSETS_SOURCE_DIR) -type f -iname '*.png' -or -iname 'frame_rate')
|
||||
ASSETS += $(ASSETS_OUTPUT_DIR)/assets_icons.c
|
||||
ASSETS += $(ASSETS_COMPILED_DIR)/assets_icons.c
|
||||
|
||||
CFLAGS += -I$(ASSETS_OUTPUT_DIR)
|
||||
C_SOURCES += $(ASSETS_OUTPUT_DIR)/assets_icons.c
|
||||
CFLAGS += -I$(ASSETS_COMPILED_DIR)
|
||||
C_SOURCES += $(ASSETS_COMPILED_DIR)/assets_icons.c
|
||||
|
251
assets/assets.py
251
assets/assets.py
@@ -1,251 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import logging
|
||||
import argparse
|
||||
import subprocess
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import struct
|
||||
import datetime
|
||||
|
||||
ICONS_SUPPORTED_FORMATS = ["png"]
|
||||
|
||||
ICONS_TEMPLATE_H_HEADER = """#pragma once
|
||||
|
||||
#include <gui/icon.h>
|
||||
|
||||
typedef enum {
|
||||
"""
|
||||
ICONS_TEMPLATE_H_ICON_NAME = "\t{name},\n"
|
||||
ICONS_TEMPLATE_H_FOOTER = """} IconName;
|
||||
|
||||
Icon * assets_icons_get(IconName name);
|
||||
"""
|
||||
|
||||
ICONS_TEMPLATE_H_I = """#pragma once
|
||||
|
||||
#include <assets_icons.h>
|
||||
|
||||
const IconData * assets_icons_get_data(IconName name);
|
||||
"""
|
||||
|
||||
ICONS_TEMPLATE_C_HEADER = """#include \"assets_icons_i.h\"
|
||||
#include <gui/icon_i.h>
|
||||
|
||||
"""
|
||||
ICONS_TEMPLATE_C_FRAME = "const uint8_t {name}[] = {data};\n"
|
||||
ICONS_TEMPLATE_C_DATA = "const uint8_t *{name}[] = {data};\n"
|
||||
ICONS_TEMPLATE_C_ICONS_ARRAY_START = "const IconData icons[] = {\n"
|
||||
ICONS_TEMPLATE_C_ICONS_ITEM = "\t{{ .width={width}, .height={height}, .frame_count={frame_count}, .frame_rate={frame_rate}, .frames=_{name} }},\n"
|
||||
ICONS_TEMPLATE_C_ICONS_ARRAY_END = "};"
|
||||
ICONS_TEMPLATE_C_FOOTER = """
|
||||
const IconData * assets_icons_get_data(IconName name) {
|
||||
return &icons[name];
|
||||
}
|
||||
|
||||
Icon * assets_icons_get(IconName name) {
|
||||
return icon_alloc(assets_icons_get_data(name));
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class Assets:
|
||||
def __init__(self):
|
||||
# command args
|
||||
self.parser = argparse.ArgumentParser()
|
||||
self.parser.add_argument("-d", "--debug", action="store_true", help="Debug")
|
||||
self.subparsers = self.parser.add_subparsers(help="sub-command help")
|
||||
self.parser_icons = self.subparsers.add_parser(
|
||||
"icons", help="Process icons and build icon registry"
|
||||
)
|
||||
self.parser_icons.add_argument(
|
||||
"-s", "--source-directory", help="Source directory"
|
||||
)
|
||||
self.parser_icons.add_argument(
|
||||
"-o", "--output-directory", help="Output directory"
|
||||
)
|
||||
self.parser_icons.set_defaults(func=self.icons)
|
||||
self.parser_otp = self.subparsers.add_parser(
|
||||
"otp", help="OTP HW version generator"
|
||||
)
|
||||
self.parser_otp.add_argument(
|
||||
"--version", type=int, help="Version", required=True
|
||||
)
|
||||
self.parser_otp.add_argument(
|
||||
"--firmware", type=int, help="Firmware", required=True
|
||||
)
|
||||
self.parser_otp.add_argument("--body", type=int, help="Body", required=True)
|
||||
self.parser_otp.add_argument(
|
||||
"--connect", type=int, help="Connect", required=True
|
||||
)
|
||||
self.parser_otp.add_argument("--name", type=str, help="Name", required=True)
|
||||
self.parser_otp.add_argument("file", help="Output file")
|
||||
self.parser_otp.set_defaults(func=self.otp)
|
||||
# logging
|
||||
self.logger = logging.getLogger()
|
||||
|
||||
def __call__(self):
|
||||
self.args = self.parser.parse_args()
|
||||
if "func" not in self.args:
|
||||
self.parser.error("Choose something to do")
|
||||
# configure log output
|
||||
self.log_level = logging.DEBUG if self.args.debug else logging.INFO
|
||||
self.logger.setLevel(self.log_level)
|
||||
self.handler = logging.StreamHandler(sys.stdout)
|
||||
self.handler.setLevel(self.log_level)
|
||||
self.formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
|
||||
self.handler.setFormatter(self.formatter)
|
||||
self.logger.addHandler(self.handler)
|
||||
# execute requested function
|
||||
self.args.func()
|
||||
|
||||
def otp(self):
|
||||
self.logger.debug(f"Generating OTP")
|
||||
|
||||
if self.args.name:
|
||||
name = re.sub(
|
||||
"[^a-zA-Z0-9.]", "", self.args.name
|
||||
) # Filter all special characters
|
||||
name = list(
|
||||
map(str, map(ord, name[0:8]))
|
||||
) # Strip to 8 chars and map to ascii codes
|
||||
while len(name) < 8:
|
||||
name.append("0")
|
||||
|
||||
n1, n2, n3, n4, n5, n6, n7, n8 = map(int, name)
|
||||
|
||||
data = struct.pack(
|
||||
"<BBBBLBBBBBBBB",
|
||||
self.args.version,
|
||||
self.args.firmware,
|
||||
self.args.body,
|
||||
self.args.connect,
|
||||
int(datetime.datetime.now().timestamp()),
|
||||
n1,
|
||||
n2,
|
||||
n3,
|
||||
n4,
|
||||
n5,
|
||||
n6,
|
||||
n7,
|
||||
n8,
|
||||
)
|
||||
open(self.args.file, "wb").write(data)
|
||||
|
||||
def icons(self):
|
||||
self.logger.debug(f"Converting icons")
|
||||
icons_c = open(os.path.join(self.args.output_directory, "assets_icons.c"), "w")
|
||||
icons_c.write(ICONS_TEMPLATE_C_HEADER)
|
||||
icons = []
|
||||
# Traverse icons tree, append image data to source file
|
||||
for dirpath, dirnames, filenames in os.walk(self.args.source_directory):
|
||||
self.logger.debug(f"Processing directory {dirpath}")
|
||||
if not filenames:
|
||||
continue
|
||||
if "frame_rate" in filenames:
|
||||
self.logger.debug(f"Folder contatins animation")
|
||||
icon_name = "A_" + os.path.split(dirpath)[1].replace("-", "_")
|
||||
width = height = None
|
||||
frame_count = 0
|
||||
frame_rate = 0
|
||||
frame_names = []
|
||||
for filename in sorted(filenames):
|
||||
fullfilename = os.path.join(dirpath, filename)
|
||||
if filename == "frame_rate":
|
||||
frame_rate = int(open(fullfilename, "r").read().strip())
|
||||
continue
|
||||
elif not self.iconIsSupported(filename):
|
||||
continue
|
||||
self.logger.debug(f"Processing animation frame {filename}")
|
||||
temp_width, temp_height, data = self.icon2header(fullfilename)
|
||||
if width is None:
|
||||
width = temp_width
|
||||
if height is None:
|
||||
height = temp_height
|
||||
assert width == temp_width
|
||||
assert height == temp_height
|
||||
frame_name = f"_{icon_name}_{frame_count}"
|
||||
frame_names.append(frame_name)
|
||||
icons_c.write(
|
||||
ICONS_TEMPLATE_C_FRAME.format(name=frame_name, data=data)
|
||||
)
|
||||
frame_count += 1
|
||||
assert frame_rate > 0
|
||||
assert frame_count > 0
|
||||
icons_c.write(
|
||||
ICONS_TEMPLATE_C_DATA.format(
|
||||
name=f"_{icon_name}", data=f'{{{",".join(frame_names)}}}'
|
||||
)
|
||||
)
|
||||
icons_c.write("\n")
|
||||
icons.append((icon_name, width, height, frame_rate, frame_count))
|
||||
else:
|
||||
# process icons
|
||||
for filename in filenames:
|
||||
if not self.iconIsSupported(filename):
|
||||
continue
|
||||
self.logger.debug(f"Processing icon {filename}")
|
||||
icon_name = "I_" + "_".join(filename.split(".")[:-1]).replace(
|
||||
"-", "_"
|
||||
)
|
||||
fullfilename = os.path.join(dirpath, filename)
|
||||
width, height, data = self.icon2header(fullfilename)
|
||||
frame_name = f"_{icon_name}_0"
|
||||
icons_c.write(
|
||||
ICONS_TEMPLATE_C_FRAME.format(name=frame_name, data=data)
|
||||
)
|
||||
icons_c.write(
|
||||
ICONS_TEMPLATE_C_DATA.format(
|
||||
name=f"_{icon_name}", data=f"{{{frame_name}}}"
|
||||
)
|
||||
)
|
||||
icons_c.write("\n")
|
||||
icons.append((icon_name, width, height, 0, 1))
|
||||
# Create array of images:
|
||||
self.logger.debug(f"Finalizing source file")
|
||||
icons_c.write(ICONS_TEMPLATE_C_ICONS_ARRAY_START)
|
||||
for name, width, height, frame_rate, frame_count in icons:
|
||||
icons_c.write(
|
||||
ICONS_TEMPLATE_C_ICONS_ITEM.format(
|
||||
name=name,
|
||||
width=width,
|
||||
height=height,
|
||||
frame_rate=frame_rate,
|
||||
frame_count=frame_count,
|
||||
)
|
||||
)
|
||||
icons_c.write(ICONS_TEMPLATE_C_ICONS_ARRAY_END)
|
||||
icons_c.write(ICONS_TEMPLATE_C_FOOTER)
|
||||
icons_c.write("\n")
|
||||
# Create Public Header
|
||||
self.logger.debug(f"Creating header")
|
||||
icons_h = open(os.path.join(self.args.output_directory, "assets_icons.h"), "w")
|
||||
icons_h.write(ICONS_TEMPLATE_H_HEADER)
|
||||
for name, width, height, frame_rate, frame_count in icons:
|
||||
icons_h.write(ICONS_TEMPLATE_H_ICON_NAME.format(name=name))
|
||||
icons_h.write(ICONS_TEMPLATE_H_FOOTER)
|
||||
# Create Private Header
|
||||
icons_h_i = open(
|
||||
os.path.join(self.args.output_directory, "assets_icons_i.h"), "w"
|
||||
)
|
||||
icons_h_i.write(ICONS_TEMPLATE_H_I)
|
||||
self.logger.debug(f"Done")
|
||||
|
||||
def icon2header(self, file):
|
||||
output = subprocess.check_output(["convert", file, "xbm:-"])
|
||||
assert output
|
||||
f = io.StringIO(output.decode().strip())
|
||||
width = int(f.readline().strip().split(" ")[2])
|
||||
height = int(f.readline().strip().split(" ")[2])
|
||||
data = f.read().strip().replace("\n", "").replace(" ", "").split("=")[1][:-1]
|
||||
return width, height, data
|
||||
|
||||
def iconIsSupported(self, filename):
|
||||
extension = filename.lower().split(".")[-1]
|
||||
return extension in ICONS_SUPPORTED_FORMATS
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Assets()()
|
617
assets/compiled/assets_icons.c
Normal file
617
assets/compiled/assets_icons.c
Normal file
File diff suppressed because one or more lines are too long
131
assets/compiled/assets_icons.h
Normal file
131
assets/compiled/assets_icons.h
Normal file
@@ -0,0 +1,131 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/icon.h>
|
||||
|
||||
typedef enum {
|
||||
I_SDQuestion_35x43,
|
||||
I_SDError_43x35,
|
||||
I_Health_16x16,
|
||||
I_FaceCharging_29x14,
|
||||
I_BatteryBody_52x28,
|
||||
I_Voltage_16x16,
|
||||
I_Temperature_16x16,
|
||||
I_FaceNopower_29x14,
|
||||
I_FaceNormal_29x14,
|
||||
I_Battery_16x16,
|
||||
I_FaceConfused_29x14,
|
||||
I_PassportBottom_128x17,
|
||||
I_DoorLeft_8x56,
|
||||
I_DoorLocked_10x56,
|
||||
I_DoorRight_8x56,
|
||||
I_DoorLeft_70x55,
|
||||
I_PassportLeft_6x47,
|
||||
I_DoorRight_70x55,
|
||||
I_LockPopup_100x49,
|
||||
I_WalkR2_32x32,
|
||||
I_WalkL2_32x32,
|
||||
I_WalkRB1_32x32,
|
||||
I_Home_painting_17x20,
|
||||
I_WalkLB2_32x32,
|
||||
I_Sofa_40x13,
|
||||
I_WalkLB1_32x32,
|
||||
I_PC_22x29,
|
||||
I_WalkL1_32x32,
|
||||
I_TV_20x20,
|
||||
I_WalkR1_32x32,
|
||||
I_WalkRB2_32x32,
|
||||
I_TV_20x24,
|
||||
I_dir_10px,
|
||||
I_Nfc_10px,
|
||||
I_sub1_10px,
|
||||
I_ir_10px,
|
||||
I_ibutt_10px,
|
||||
I_unknown_10px,
|
||||
I_ble_10px,
|
||||
I_125_10px,
|
||||
I_FX_SittingB_40x27,
|
||||
I_BigGames_24x24,
|
||||
I_BigProfile_24x24,
|
||||
I_DolphinOkay_41x43,
|
||||
I_DolphinFirstStart5_45x53,
|
||||
I_DolphinFirstStart4_67x53,
|
||||
I_DolphinFirstStart2_59x51,
|
||||
I_DolphinFirstStart0_70x53,
|
||||
I_DolphinFirstStart6_58x54,
|
||||
I_DolphinFirstStart1_59x53,
|
||||
I_DolphinFirstStart8_56x51,
|
||||
I_DolphinFirstStart7_61x51,
|
||||
I_Flipper_young_80x60,
|
||||
I_BigBurger_24x24,
|
||||
I_FX_Bang_32x6,
|
||||
I_DolphinFirstStart3_57x48,
|
||||
I_BadUsb_9x8,
|
||||
I_PlaceholderR_30x13,
|
||||
I_Background_128x8,
|
||||
I_Lock_8x8,
|
||||
I_Battery_26x8,
|
||||
I_PlaceholderL_11x13,
|
||||
I_Battery_19x8,
|
||||
I_SDcardMounted_11x8,
|
||||
I_SDcardFail_11x8,
|
||||
I_USBConnected_15x8,
|
||||
I_Bluetooth_5x8,
|
||||
I_Background_128x11,
|
||||
I_IrdaArrowUp_4x8,
|
||||
I_IrdaLearnShort_128x31,
|
||||
I_IrdaArrowDown_4x8,
|
||||
I_IrdaLearn_128x64,
|
||||
I_IrdaSend_128x64,
|
||||
I_IrdaSendShort_128x34,
|
||||
I_passport_happy1_43x45,
|
||||
I_passport_bad3_43x45,
|
||||
I_passport_okay2_43x45,
|
||||
I_passport_bad2_43x45,
|
||||
I_passport_okay3_43x45,
|
||||
I_passport_bad1_43x45,
|
||||
I_passport_happy3_43x45,
|
||||
I_passport_happy2_43x45,
|
||||
I_passport_okay1_43x45,
|
||||
I_ButtonRightSmall_3x5,
|
||||
I_ButtonLeft_4x7,
|
||||
I_ButtonLeftSmall_3x5,
|
||||
I_ButtonRight_4x7,
|
||||
I_ButtonCenter_7x7,
|
||||
A_Games_14,
|
||||
A_Plugins_14,
|
||||
A_Passport_14,
|
||||
A_Sub1ghz_14,
|
||||
A_NFC_14,
|
||||
A_Tamagotchi_14,
|
||||
A_FileManager_14,
|
||||
A_125khz_14,
|
||||
A_U2F_14,
|
||||
A_Infrared_14,
|
||||
A_Power_14,
|
||||
A_Settings_14,
|
||||
A_iButton_14,
|
||||
A_Bluetooth_14,
|
||||
A_GPIO_14,
|
||||
I_DolphinMafia_115x62,
|
||||
I_DolphinExcited_64x63,
|
||||
I_iButtonDolphinSuccess_109x60,
|
||||
I_iButtonDolphinVerySuccess_108x52,
|
||||
I_iButtonKey_49x44,
|
||||
I_DolphinNice_96x59,
|
||||
I_DolphinWait_61x59,
|
||||
A_Wink_128x64,
|
||||
A_MDWL_32x32,
|
||||
A_MDWR_32x32,
|
||||
A_WatchingTV_128x64,
|
||||
A_MDI_32x32,
|
||||
A_MDWRB_32x32,
|
||||
A_MDIB_32x32,
|
||||
A_FX_Sitting_40x27,
|
||||
A_MDWLB_32x32,
|
||||
I_KeySave_24x11,
|
||||
I_KeyBackspaceSelected_16x9,
|
||||
I_KeySaveSelected_24x11,
|
||||
I_KeyBackspace_16x9,
|
||||
} IconName;
|
||||
|
||||
Icon * assets_icons_get(IconName name);
|
5
assets/compiled/assets_icons_i.h
Normal file
5
assets/compiled/assets_icons_i.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <assets_icons.h>
|
||||
|
||||
const IconData * assets_icons_get_data(IconName name);
|
1
assets/output/.gitignore
vendored
1
assets/output/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
*
|
Reference in New Issue
Block a user