From 1cd99b2451961f9a43a2cb9e198c82d3003cb36d Mon Sep 17 00:00:00 2001
From: Samuel Tardieu <sam@rfc1149.net>
Date: Tue, 16 Jul 2024 23:28:05 +0200
Subject: [PATCH] Prefix commands with CMD_

---
 controller/src/logic.rs | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/controller/src/logic.rs b/controller/src/logic.rs
index c8fdeeb..1403e27 100644
--- a/controller/src/logic.rs
+++ b/controller/src/logic.rs
@@ -159,14 +159,14 @@ fn i2c_callback(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
     }
 }
 
-const FIRMWARE_VERSION: u8 = 0x08;
-const WHO_AM_I: u8 = 0x0f;
-const PWM_FREQUENCY: u8 = 0x10;
-const MAX_MOTOR_PERCENTAGE: u8 = 0x11;
-const MOTOR_SHUTDOWN_TIMEOUT: u8 = 0x28;
-const MOTOR_SPEED: u8 = 0x30;
-const ENCODER_TICKS: u8 = 0x32;
-const STATUS: u8 = 0x36;
+const CMD_FIRMWARE_VERSION: u8 = 0x08;
+const CMD_WHO_AM_I: u8 = 0x0f;
+const CMD_PWM_FREQUENCY: u8 = 0x10;
+const CMD_MAX_MOTOR_PERCENTAGE: u8 = 0x11;
+const CMD_MOTOR_SHUTDOWN_TIMEOUT: u8 = 0x28;
+const CMD_MOTOR_SPEED: u8 = 0x30;
+const CMD_ENCODER_TICKS: u8 = 0x32;
+const CMD_STATUS: u8 = 0x36;
 
 include!(concat!(env!("OUT_DIR"), "/version.rs"));
 
@@ -177,15 +177,15 @@ fn process_command(
 ) -> bool {
     defmt::trace!("Processing command {:?}", command);
     match command {
-        [FIRMWARE_VERSION] => {
+        [CMD_FIRMWARE_VERSION] => {
             for b in PKG_VERSION {
                 response.push_back(b).unwrap();
             }
         }
-        [WHO_AM_I, ..] => {
+        [CMD_WHO_AM_I, ..] => {
             response.push_back(0x57).unwrap();
         }
-        &[PWM_FREQUENCY, a, b, c] => {
+        &[CMD_PWM_FREQUENCY, a, b, c] => {
             let f = u32::from_le_bytes([a, b, c, 0]);
             if (1..=100_000).contains(&f) {
                 state.motors.set_frequency(hz(f));
@@ -194,13 +194,13 @@ fn process_command(
                 return false;
             }
         }
-        [PWM_FREQUENCY] => {
+        [CMD_PWM_FREQUENCY] => {
             let freq = state.motors.get_frequency().0;
             for &b in &freq.to_le_bytes()[..3] {
                 response.push_back(b).unwrap();
             }
         }
-        &[MAX_MOTOR_PERCENTAGE, p] => {
+        &[CMD_MAX_MOTOR_PERCENTAGE, p] => {
             if (1..=100).contains(&p) {
                 state.max_motor_percentage = p;
             } else {
@@ -208,17 +208,17 @@ fn process_command(
                 return false;
             }
         }
-        [MAX_MOTOR_PERCENTAGE] => {
+        [CMD_MAX_MOTOR_PERCENTAGE] => {
             response.push_back(state.max_motor_percentage).unwrap();
         }
-        [MOTOR_SPEED, ms @ ..] if ms.len() == 2 => {
+        [CMD_MOTOR_SPEED, ms @ ..] if ms.len() == 2 => {
             state.set_motor_speed([ms[0], ms[1]]);
         }
-        [MOTOR_SPEED] => {
+        [CMD_MOTOR_SPEED] => {
             response.push_back(state.motor_speed[0]).unwrap();
             response.push_back(state.motor_speed[1]).unwrap();
         }
-        &[MOTOR_SHUTDOWN_TIMEOUT, ticks] => {
+        &[CMD_MOTOR_SHUTDOWN_TIMEOUT, ticks] => {
             if (1..=100).contains(&ticks) {
                 WATCHDOG_TICKS.store(ticks, Ordering::Relaxed);
             } else {
@@ -226,12 +226,12 @@ fn process_command(
                 return false;
             }
         }
-        [MOTOR_SHUTDOWN_TIMEOUT] => {
+        [CMD_MOTOR_SHUTDOWN_TIMEOUT] => {
             response
                 .push_back(WATCHDOG_TICKS.load(Ordering::Relaxed))
                 .unwrap();
         }
-        [ENCODER_TICKS] => {
+        [CMD_ENCODER_TICKS] => {
             let (left, right) = state.encoders.ticks();
             let (left, right) = (left.to_le_bytes(), right.to_le_bytes());
             response.push_back(left[0]).unwrap();
@@ -239,7 +239,7 @@ fn process_command(
             response.push_back(right[0]).unwrap();
             response.push_back(right[1]).unwrap();
         }
-        [STATUS] => {
+        [CMD_STATUS] => {
             response.push_back(u8::from(state.is_moving())).unwrap();
         }
         _ => {
-- 
GitLab