Skip to content

Commit 2ffb2dc

Browse files
authored
Update otwConfigurator.py
1 parent 7c34f0e commit 2ffb2dc

1 file changed

Lines changed: 95 additions & 22 deletions

File tree

otwConfigurator.py

Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,62 @@
1-
# OpenTimeWatch Configurator tool
1+
# OpenTimeWatchOS Configurator Tool
2+
3+
print("Welcome to OpenTimeWatchOS configuration script")
4+
OSVarPath = "src/osVariables/osVariables.cpp"
5+
OSConfPath = "platformio.ini"
6+
7+
def configureBoard(userBoard):
8+
if userBoard == 1:
9+
try:
10+
with open(OSConfPath, 'r') as file:
11+
lines = file.readlines()
12+
for i, line in enumerate(lines):
13+
if i == 6: # Uncomment line 7
14+
lines[i] = line.lstrip(";")
15+
elif i == 5: # Comment line 6
16+
if not line.startswith(";"):
17+
lines[i] = ";" + line
18+
elif i == 10: # Uncomment line 11
19+
lines[i] = line.lstrip(";")
20+
elif i == 9: # Comment line 10
21+
if not line.startswith(";"):
22+
lines[i] = ";" + line
23+
elif i == 15: # Uncomment line 16
24+
lines[i] = line.lstrip(";")
25+
with open(OSConfPath, 'w') as file:
26+
file.writelines(lines)
27+
except Exception as e:
28+
print(f"An error occurred: {e}")
29+
30+
else:
31+
try:
32+
with open(OSConfPath, 'r') as file:
33+
lines = file.readlines()
34+
for i, line in enumerate(lines):
35+
if i == 5: # Uncomment line 6
36+
lines[i] = line.lstrip(";")
37+
elif i == 6: # Comment line 7
38+
if not line.startswith(";"):
39+
lines[i] = ";" + line
40+
elif i == 9: # Uncomment line 10
41+
lines[i] = line.lstrip(";")
42+
elif i == 10: # Comment line 11
43+
if not line.startswith(";"):
44+
lines[i] = ";" + line
45+
elif i == 15: # Comment line 16
46+
if not line.startswith(";"):
47+
lines[i] = ";" + line
48+
with open(OSConfPath, 'w') as file:
49+
file.writelines(lines)
50+
except Exception as e:
51+
print(f"An error occurred: {e}")
252

3-
print("Welcome to OpenTimeWatchOS configurator tool")
4-
file_path = "/home/jaswanth/Developer/Arduino/OpenTimeWatch-OS/src/osVariables/osVariables.cpp"
553

654
def configureWifiNetwork(userSSID):
755
try:
8-
with open(file_path, 'r') as file:
56+
with open(OSVarPath, 'r') as file:
957
lines = file.readlines()
1058

11-
with open(file_path, 'w') as file:
59+
with open(OSVarPath, 'w') as file:
1260
for line in lines:
1361
if 'const char* ssid = ' in line:
1462
line = f'const char* ssid = "{userSSID}";\n'
@@ -18,10 +66,10 @@ def configureWifiNetwork(userSSID):
1866

1967
def configureWifiPassword(userPassword):
2068
try:
21-
with open(file_path, 'r') as file:
69+
with open(OSVarPath, 'r') as file:
2270
lines = file.readlines()
2371

24-
with open(file_path, 'w') as file:
72+
with open(OSVarPath, 'w') as file:
2573
for line in lines:
2674
if 'const char* password = ' in line:
2775
line = f'const char* password = "{userPassword}";\n'
@@ -31,10 +79,10 @@ def configureWifiPassword(userPassword):
3179

3280
def configureGMTOffset(userGMT):
3381
try:
34-
with open(file_path, 'r') as file:
82+
with open(OSVarPath, 'r') as file:
3583
lines = file.readlines()
3684

37-
with open(file_path, 'w') as file:
85+
with open(OSVarPath, 'w') as file:
3886
for line in lines:
3987
if 'const long gmtOffset_sec = ' in line:
4088
line = f'const long gmtOffset_sec = {userGMT};\n'
@@ -44,10 +92,10 @@ def configureGMTOffset(userGMT):
4492

4593
def configureDayLightOffset(userDayLight):
4694
try:
47-
with open(file_path, 'r') as file:
95+
with open(OSVarPath, 'r') as file:
4896
lines = file.readlines()
4997

50-
with open(file_path, 'w') as file:
98+
with open(OSVarPath, 'w') as file:
5199
for line in lines:
52100
if 'const int daylightOffset_sec = ' in line:
53101
line = f'const int daylightOffset_sec = {userDayLight};\n'
@@ -56,14 +104,39 @@ def configureDayLightOffset(userDayLight):
56104
print(f"An error occurred: {e}")
57105

58106
if __name__ == "__main__":
59-
60-
userSSID = input("Enter your WiFi network name: ")
61-
configureWifiNetwork(userSSID)
62-
userPassword = input("Enter your WiFi network password: ")
63-
configureWifiPassword(userPassword)
64-
userGMT = input("Enter your area's GMT offset(in seconds): ")
65-
configureGMTOffset(userGMT)
66-
userDayLight = input("Enter your area's day light offset(in seconds): ")
67-
configureDayLightOffset(userDayLight)
68-
69-
print("Configuration complete. Please compile and upload the firmware.")
107+
print("1. Configure")
108+
print("2. About")
109+
print("3. Exit")
110+
userOption = input("Select an option: ")
111+
112+
if userOption == "1":
113+
print("Watch Hardware: ")
114+
print("1. T-QT-Pro-N4R2")
115+
print("2. T-QT-Pro-N8")
116+
userBoard = int(input("Select your board: "))
117+
configureBoard(userBoard)
118+
if userBoard == 1:
119+
print("You have selected T-QT-Pro-N8")
120+
else:
121+
print("You have selected T-QT-Pro-N4R2")
122+
userSSID = input("Enter your WiFi network name: ")
123+
configureWifiNetwork(userSSID)
124+
userPassword = input("Enter your WiFi network password: ")
125+
configureWifiPassword(userPassword)
126+
userGMT = input("Enter your area's GMT offset(in seconds): ")
127+
configureGMTOffset(userGMT)
128+
userDayLight = input("Enter your area's day light offset(in seconds): ")
129+
configureDayLightOffset(userDayLight)
130+
print("Configuration complete. Please upload the code.")
131+
elif userOption == "2":
132+
print("OpenTimeWatchOS Configuration Script V1.1")
133+
print("This is a configuration script for OpenTimeWatchOS for your watch hardware")
134+
print("It allows you to configure the Board, WiFi SSID, password, GMT offset, and daylight offset")
135+
print("For more information, visit the OpenTimeWatchOS GitHub repository.")
136+
print("https://github.com/OpenTimeWatch-Project/OpenTimeWatch-OS")
137+
elif userOption == "3":
138+
print("Exiting the script. Goodbye!")
139+
exit(0)
140+
else:
141+
print("Invalid option. Please try again.")
142+
exit(1)

0 commit comments

Comments
 (0)