Skip to content

Commit

Permalink
fix uart for gps when bluetooth is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptosiek committed Oct 9, 2023
1 parent a815cf0 commit d0e9b8e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
56 changes: 53 additions & 3 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,54 @@ def hardware_wifi_bt(self, status):
exec_cmd(
["sudo", "sed", "-i", f"$a{disable}", BOOT_FILE], False
)
# UART configuration will change if we disable bluetooth
# https://www.raspberrypi.com/documentation/computers/configuration.html#primary-and-secondary-uart
if status:
exec_cmd(
[
"sudo",
"sed",
"-i",
"-e",
's/^\#DEVICES\="\/dev\/ttyS0"/DEVICES\="\/dev\/ttyS0"/',
"/etc/default/gpsd",
],
False,
)
exec_cmd(
[
"sudo",
"sed",
"-i",
"-e",
's/^DEVICES\="\/dev\/ttyAMA0"/\#DEVICES\="\/dev\/ttyAMA0"/',
"/etc/default/gpsd",
],
False,
)
else:
exec_cmd(
[
"sudo",
"sed",
"-i",
"-e",
's/^DEVICES\="\/dev\/ttyS0"/\#DEVICES\="\/dev\/ttyS0"/',
"/etc/default/gpsd",
],
False,
)
exec_cmd(
[
"sudo",
"sed",
"-i",
"-e",
's/^\#DEVICES\="\/dev\/ttyAMA0"/DEVICES\="\/dev\/ttyAMA0"/',
"/etc/default/gpsd",
],
False,
)

def get_wifi_bt_status(self):
if not self.G_IS_RASPI:
Expand All @@ -1073,9 +1121,11 @@ def get_wifi_bt_status(self):
status = {"wlan": False, "bluetooth": False}
try:
# json option requires raspbian buster
raw_status = exec_cmd_return_value(["sudo", "rfkill", "--json"], cmd_print=False)
raw_status = exec_cmd_return_value(
["sudo", "rfkill", "--json"], cmd_print=False
)
json_status = json.loads(raw_status)
# "": Raspberry Pi OS, "rfkilldevices":
# "": Raspberry Pi OS, "rfkilldevices":
self.parse_wifi_bt_json(json_status, status, ["", "rfkilldevices"])
except Exception as e:
app_logger.warning(f"Exception occurred trying to get wifi/bt status: {e}")
Expand Down Expand Up @@ -1103,7 +1153,7 @@ def onoff_wifi_bt(self, key=None):
onoff_cmd = {
"Wifi": {
True: ["sudo", "rfkill", "block", "wifi"],
False: ["sudo"", rfkill", "unblock", "wifi"],
False: ["sudo", "rfkill", "unblock", "wifi"],
},
"Bluetooth": {
True: ["sudo", "rfkill", "block", "bluetooth"],
Expand Down
8 changes: 4 additions & 4 deletions modules/logger_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def init_db(self):
res = self.cur.fetchone()
replace_flg = False
if (
res is not None
and len(res) >= 5
res is not None
and len(res) >= 5
and res[4].replace(" ", "") != self.create_table_sql.replace(" ", "")
):
log_db_moved = self.config.G_LOG_DB + "-old_layout"
Expand Down Expand Up @@ -897,8 +897,8 @@ def update_track(self, timestamp):
shutil.copy(self.config.G_LOG_DB, db_file)

query = (
'SELECT distance,position_lat,position_long FROM BIKECOMPUTER_LOG '
+ 'WHERE position_lat is not null AND position_long is not null '
"SELECT distance,position_lat,position_long FROM BIKECOMPUTER_LOG "
+ "WHERE position_lat is not null AND position_long is not null "
+ 'and typeof(position_lat) = "real" and typeof(position_long) = "real"'
)
if timestamp is not None:
Expand Down
6 changes: 2 additions & 4 deletions modules/pyqt/menu/pyqt_system_menu_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def preprocess(self):

def debug_log(self):
self.change_page("Debug Log", preprocess=True)

def set_log_level_to_debug(self, change=True):
# assume the initial log level is INFO.
# Future support for multiple log levels.
Expand All @@ -164,9 +164,7 @@ def set_log_level_to_debug(self, change=True):
else:
app_logger.setLevel(level=logging.DEBUG)
self.is_log_lebel_debug = True
self.buttons["Debug Level Log"].change_toggle(
self.is_log_lebel_debug
)
self.buttons["Debug Level Log"].change_toggle(self.is_log_lebel_debug)


class BluetoothTetheringListWidget(ListWidget):
Expand Down
4 changes: 0 additions & 4 deletions scripts/comment_out.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/uncomment.sh

This file was deleted.

0 comments on commit d0e9b8e

Please sign in to comment.