Skip to content

Commit c784de2

Browse files
committed
[atoms3] Add version info and version_request packet
1 parent 17cee50 commit c784de2

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

firmware/atom_s3_i2c_display/extra_script.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8: noqa
22
import os
3+
import subprocess
34

45
from SCons.Script import Import
56

@@ -23,6 +24,17 @@ def validate_i2c_address(addr):
2324

2425
Import("env")
2526

27+
try:
28+
riberry_version = subprocess.check_output(
29+
["git", "log", "-1", "--pretty=format:%h"],
30+
universal_newlines=True
31+
).strip()
32+
env.Append(CPPDEFINES=[f"RIBERRY_VERSION=\\\"{riberry_version}\\\""])
33+
except subprocess.CalledProcessError:
34+
print("\033[91mWarning: Failed to get git commit hash. Using default RIBERRY_VERSION.\033[0m")
35+
env.Append(CPPDEFINES=["RIBERRY_VERSION=\\\"unknown\\\""])
36+
37+
2638
USE_GROVE = os.getenv("USE_GROVE")
2739
LCD_ROTATION = os.getenv("LCD_ROTATION")
2840
I2C_ADDR = os.getenv("I2C_ADDR")

firmware/atom_s3_i2c_display/lib/com/communication_base.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <communication_base.h>
33

44
#include "firmware_update.h"
5+
#include "riberry_config.h"
56

67
CommunicationBase* CommunicationBase::instance = nullptr;
78
Stream* CommunicationBase::_stream = nullptr;
@@ -229,6 +230,12 @@ void CommunicationBase::processPacket(const String& str, int offset) {
229230
instance->pairing.setDataToSend(dataToSend);
230231
break;
231232
}
233+
case FIRMWARE_VERSION_REQUEST: {
234+
_stream->flush();
235+
String version = VERSION;
236+
write(version, version.length());
237+
break;
238+
}
232239
case FIRMWARE_UPDATE_MODE: {
233240
stopStream();
234241
instance->lcd.lockLcd();

firmware/atom_s3_i2c_display/lib/com/packet.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ enum PacketType : uint8_t {
1515
SET_IP_REQUEST = 0x13,
1616
SPEECH_TO_TEXT_MODE = 0x14,
1717

18+
FIRMWARE_VERSION_REQUEST = 0xFD,
1819
FIRMWARE_UPDATE_MODE = 0xFF,
1920
};

firmware/atom_s3_i2c_display/lib/lcd/primitive_lcd.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <primitive_lcd.h>
22

3+
#include "color.h"
4+
#include "riberry_config.h"
5+
36
PrimitiveLCD::PrimitiveLCD() : LGFX(), qrCodeData("") {
47
init();
58
lcdMutex = xSemaphoreCreateRecursiveMutex();
@@ -273,7 +276,10 @@ void PrimitiveLCD::printWaitMessage(int i2cAddress) {
273276
void PrimitiveLCD::drawNoDataReceived() {
274277
fillScreen(color565(255, 0, 0)); // Fill the screen with red
275278
setCursor(0, 0);
276-
printColorText("No data received.\n");
279+
char log_msg[50];
280+
sprintf(log_msg, "No data received.\n%sV:%s\n%s", Color::Foreground::YELLOW, VERSION,
281+
Color::Foreground::RESET);
282+
printColorText(log_msg);
277283
}
278284

279285
void PrimitiveLCD::drawBlack() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef RIBERRY_CONFIG_H
2+
#define RIBERRY_CONFIG_H
3+
4+
#include <Arduino.h>
5+
6+
#ifdef RIBERRY_VERSION
7+
constexpr const char VERSION[] = RIBERRY_VERSION;
8+
#else
9+
constexpr const char VERSION[] = "v0.0.0"; // OK
10+
#endif
11+
12+
#endif // RIBERRY_CONFIG_H

riberry/com/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class PacketType(IntEnum):
2424
SET_IP_REQUEST = 0x13
2525
SPEECH_TO_TEXT_MODE = 0x14
2626

27+
FIRMWARE_VERSION_REQUEST = 0xFD
2728
FIRMWARE_UPDATE_MODE = 0xFF
2829

2930
class ComBase:

0 commit comments

Comments
 (0)