Case: added text - on case front and id on lid

This commit is contained in:
Martin Bauer 2021-07-30 14:39:03 +02:00
parent 1852159f15
commit a45f49804c
11 changed files with 12 additions and 8230 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ __pycache__
*.st *.st
/espidf /espidf
/venv /venv
/hardware/case/generated

View File

@ -1,127 +0,0 @@
import struct
from collections import namedtuple
from datetime import datetime
import subprocess
from distutils.version import StrictVersion
from esptool import LoadFirmwareImage # required to get hash and checksum right
import os
# locale.setlocale(locale.LC_ALL, 'en_US')
APP_DESC_SIZE = 256 # sizeof(esp_app_desc_t)
APP_DESC_STRUCT = "<II2I32s32s16s16s32s32B20I"
AppDesc = namedtuple('AppDesc',
[
"secure_version",
"version",
"project_name",
"time",
"date",
"idf_ver",
"app_elf_sha256",
]
)
def version_number_from_git(tag_prefix='release/', sha_length=10, version_format="{version}.dev{commits}+{sha}"):
def get_released_versions():
tags = sorted(subprocess.getoutput('git tag').split('\n'))
versions = [t[len(tag_prefix):]
for t in tags if t.startswith(tag_prefix)]
return versions
def tag_from_version(v):
return tag_prefix + v
def increment_version(v):
parsed_version = [int(i) for i in v.split('.')]
parsed_version[-1] += 1
return '.'.join(str(i) for i in parsed_version)
version_strings = get_released_versions()
version_strings.sort(key=StrictVersion)
latest_release = version_strings[-1]
commits_since_tag = subprocess.getoutput(
'git rev-list {}..HEAD --count'.format(tag_from_version(latest_release)))
sha = subprocess.getoutput('git rev-parse HEAD')[:sha_length]
is_dirty = len(subprocess.getoutput(
"git status --untracked-files=no -s")) > 0
if int(commits_since_tag) == 0:
version_string = latest_release
else:
next_version = increment_version(latest_release)
version_string = version_format.format(
version=next_version, commits=commits_since_tag, sha=sha)
if is_dirty:
version_string += ".dirty"
return version_string
def read_app_description_from_segment(segment):
def process_bytes(b):
if not isinstance(b, bytes):
return b
s = b.decode()
return s[:s.find("\x00")]
unpacked = struct.unpack(APP_DESC_STRUCT, segment.data[:APP_DESC_SIZE])
unpacked = tuple(process_bytes(e) for e in unpacked)
magic_word, secure_version, _, _, version, project_name, time, date, idf_ver, app_elf_sha256, *_ = unpacked
assert magic_word == 0xABCD5432
return AppDesc(secure_version, version, project_name, time, date, idf_ver, app_elf_sha256)
def patch_app_description_in_segment(segment, version, project_name, time, date):
assert len(version) < 32
assert len(project_name) < 32
assert len(time) < 16
assert len(date) < 16
def fill_zeros(s, total_length):
s += "\x00" * (total_length - len(s))
s = s.encode()
assert len(s) == total_length
return s
raw_app_desc = segment.data[:APP_DESC_SIZE]
unpacked = list(struct.unpack(APP_DESC_STRUCT, raw_app_desc))
unpacked[4] = fill_zeros(version, 32)
unpacked[5] = fill_zeros(project_name, 32)
unpacked[6] = fill_zeros(time, 16)
unpacked[7] = fill_zeros(date, 16)
packed = struct.pack(APP_DESC_STRUCT, *unpacked)
original_data = segment.data
segment.data = packed + original_data[APP_DESC_SIZE:]
def patch_firmware(input_file, output_file):
img = LoadFirmwareImage("esp32", input_file)
version = version_number_from_git()
now = datetime.now()
time = now.strftime("%H:%M:%S")
date = now.strftime("%b %d %Y")
patch_app_description_in_segment(img.segments[0], version, "swimtracker.bauer.tech", time, date)
img.save(output_file)
if __name__ == "__main__":
firmware_file = ".pio/build/esp32/firmware.bin"
version_file_name = "VERSION"
patch_firmware(firmware_file, firmware_file) # patch inplace
with open(version_file_name, "w") as version_file:
print(version_number_from_git(), file=version_file)
subprocess.run(["scp", firmware_file, "root@server:/volumes/swimtracker-update"])
subprocess.run(["scp", version_file_name, "root@server:/volumes/swimtracker-update"])
os.unlink(firmware_file)
os.unlink(version_file_name)

View File

@ -5,4 +5,7 @@ otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000, phy_init, data, phy, , 0x1000,
ota_0, 0, ota_0, , 0x120000, ota_0, 0, ota_0, , 0x120000,
ota_1, 0, ota_1, , 0x120000, ota_1, 0, ota_1, , 0x120000,
spiffs, data, spiffs, , 0x1B0000, #small: 1.125 MB
#spiffs, data, spiffs, , 0x1B0000,
#large: (16 mb chips)
spiffs, data, spiffs, , 0xD80000
1 # ESP-IDF Partition Table
5 phy_init, data, phy, , 0x1000,
6 ota_0, 0, ota_0, , 0x120000,
7 ota_1, 0, ota_1, , 0x120000,
8 spiffs, data, spiffs, , 0x1B0000, #small: 1.125 MB
9 #spiffs, data, spiffs, , 0x1B0000,
10 #large: (16 mb chips)
11 spiffs, data, spiffs, , 0xD80000

View File

@ -18,6 +18,7 @@ platform = espressif32
#platform_packages = #platform_packages =
# framework-arduinoespressif32@https://github.com/espressif/arduino-esp32 # framework-arduinoespressif32@https://github.com/espressif/arduino-esp32
board = esp-wrover-kit board = esp-wrover-kit
board_upload.flash_size = "16MB"
#platform = espressif8266 #platform = espressif8266
#board = esp_wroom_02 #board = esp_wroom_02
#build_flags = -Wl,-Teagle.flash.2m1m.ld #build_flags = -Wl,-Teagle.flash.2m1m.ld

View File

@ -73,7 +73,7 @@ bool firmwareUpdate()
} }
return true; return true;
} }
void sessionManagerSetup() void sessionManagerSetup()
{ {
Preferences scalePrefs; Preferences scalePrefs;
@ -202,7 +202,7 @@ void httpSetup(SessionManager<SessionT> *sessionManager, WifiManager *wifiManage
JsonObject device = json.createNestedObject("device"); JsonObject device = json.createNestedObject("device");
device["mac"] = baseMacChr; device["mac"] = baseMacChr;
device["chip"] = modelString; device["chip"] = modelString;
device["unique_name"] = "swimtracker" + getIdSuffix(); device["unique_name"] = "swimtracker" + getIdSuffix();
} }
char jsonText[512]; char jsonText[512];
auto bytesWritten = serializeJson(json, jsonText); auto bytesWritten = serializeJson(json, jsonText);
@ -440,13 +440,17 @@ void setup()
} }
// File system // File system
auto millisBeforeSpiffsInit = millis();
bool spiffsResult = SPIFFS.begin(true); bool spiffsResult = SPIFFS.begin(true);
if (!spiffsResult) if (!spiffsResult)
Serial.println("Failed to mount/format SPIFFS file system"); Serial.println("Failed to mount/format SPIFFS file system");
ESP_ERROR_CHECK(esp_event_loop_create_default()); ESP_ERROR_CHECK(esp_event_loop_create_default());
auto spiffsSetupTimeSecs = (millis() - millisBeforeSpiffsInit) / 1000;
userStorage.init(); userStorage.init();
Serial.printf("Spiffs size: %d MB, setup time %d secs\n", portablefs::totalBytes() / 1024 / 1024, spiffsSetupTimeSecs);
// WiFi // WiFi
Preferences prefs; Preferences prefs;

Binary file not shown.

View File

@ -1,86 +0,0 @@
solid OpenSCAD_Model
facet normal -0 0 1
outer loop
vertex 0 2 42.1
vertex 60 0 42.1
vertex 60 2 42.1
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 60 0 42.1
vertex 0 2 42.1
vertex 0 0 42.1
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 0 0
vertex 60 2 0
vertex 60 0 0
endloop
endfacet
facet normal -0 0 -1
outer loop
vertex 60 2 0
vertex 0 0 0
vertex 0 2 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 0 0 0
vertex 60 0 42.1
vertex 0 0 42.1
endloop
endfacet
facet normal 0 -1 -0
outer loop
vertex 60 0 42.1
vertex 0 0 0
vertex 60 0 0
endloop
endfacet
facet normal 1 -0 0
outer loop
vertex 60 0 42.1
vertex 60 2 0
vertex 60 2 42.1
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 60 2 0
vertex 60 0 42.1
vertex 60 0 0
endloop
endfacet
facet normal 0 1 -0
outer loop
vertex 60 2 0
vertex 0 2 42.1
vertex 60 2 42.1
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 0 2 42.1
vertex 60 2 0
vertex 0 2 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 0 0 0
vertex 0 2 42.1
vertex 0 2 0
endloop
endfacet
facet normal -1 -0 0
outer loop
vertex 0 2 42.1
vertex 0 0 0
vertex 0 0 42.1
endloop
endfacet
endsolid OpenSCAD_Model

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff