Skip to content

Commit

Permalink
feat: better error handling
Browse files Browse the repository at this point in the history
Logs are better for connection events!
mookums committed Jan 22, 2024
1 parent faea778 commit d5a8ec1
Showing 4 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions arduino/feather-evm.ino
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ uint16_t read_from_msp(unsigned int reg, int size) {
Wire.beginTransmission(msp_address);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(msp_address, 1);
Wire.requestFrom(msp_address, size);

unsigned int returnInt = Wire.read();
for(int i = 0; i < size-1; i++) {
@@ -70,7 +70,7 @@ int get_register_from_params(String command_params) {

int get_third_from_params(String command_params) {
String sub = command_params.substring(command_params.indexOf(' '));
String third = sub.substring(command_params.indexOf(' ')+1);
String third = sub.substring(command_params.indexOf(' '));
return third.toInt();
}

@@ -92,10 +92,11 @@ void loop() {
if (x == '\n')
{
input[i] = 0x00;

String command = String(input);
String command_head = command.substring(0, command.indexOf(' '));
String command_params = command.substring(command.indexOf(' ') + 1);

unsigned int device = get_device_from_params(command_params);
unsigned int reg = get_register_from_params(command_params);
unsigned int third = get_third_from_params(command_params);
5 changes: 3 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -42,7 +42,8 @@ fn open_serial_port(port_state: tauri::State<PortState>, port_name: &str, baud_r
Ok(p) => p,
Err(e) => match e.kind {
ErrorKind::NoDevice => return 1,
_ => return 2,
ErrorKind::Io(_) => return 3,
_ => return 4,
},
};

@@ -56,7 +57,7 @@ fn open_serial_port(port_state: tauri::State<PortState>, port_name: &str, baud_r
return 0;
}
Err(_) => {
return 3;
return 2;
}
}
}
5 changes: 5 additions & 0 deletions src/lib/Connect.svelte
Original file line number Diff line number Diff line change
@@ -28,6 +28,11 @@
break;
}
case StatusCode.UNKNOWN: {
portError = port_name + ": Error Opening Port (In use by another process?)";
break;
}
default: {
portError = port_name + ": " + portResponse;
break;
2 changes: 2 additions & 0 deletions src/lib/StatusCode.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ enum StatusCode {
SUCCESS=0,
NO_DEVICE=1,
MUTEX_ERROR=2,
IO_ERROR=3,
UNKNOWN=4,
}

export default StatusCode;

0 comments on commit d5a8ec1

Please sign in to comment.