-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (39 loc) · 1.35 KB
/
main.py
File metadata and controls
45 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import logging
from change_address import change_sensor_address
from read_force import read_sensor_force
# Configure logging
logging.basicConfig(
filename="main.log",
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
def main():
logging.info("Program started.")
print("Welcome to the Sensor Manager!")
print("1. Change the I2C address of the sensor")
print("2. Read force data from the sensor")
print("3. Exit")
while True:
try:
choice = input("Enter your choice (1/2/3): ").strip()
if choice == "1":
logging.info("User chose to read force data.")
read_sensor_force()
break
elif choice == "2":
logging.info("User chose to change the sensor address.")
change_sensor_address()
break
elif choice == "3":
logging.info("User exited the program.")
print("Goodbye!")
break
else:
print("Invalid choice. Please enter 1, 2, or 3.")
logging.warning(f"Invalid menu choice: {choice}")
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
print(f"An error occurred: {e}")
break
if __name__ == "__main__":
main()