Browse Source

Make M155 / M156 a bit more flexible

Scott Lahteine 9 years ago
parent
commit
dd75fca4d9
2 changed files with 14 additions and 17 deletions
  1. 7
    9
      Marlin/Marlin_main.cpp
  2. 7
    8
      Marlin/twibus.h

+ 7
- 9
Marlin/Marlin_main.cpp View File

5259
    */
5259
    */
5260
   inline void gcode_M155() {
5260
   inline void gcode_M155() {
5261
     // Set the target address
5261
     // Set the target address
5262
-    if (code_seen('A'))
5263
-      i2c.address(code_value_byte());
5262
+    if (code_seen('A')) i2c.address(code_value_byte());
5264
 
5263
 
5265
     // Add a new byte to the buffer
5264
     // Add a new byte to the buffer
5266
-    else if (code_seen('B'))
5267
-      i2c.addbyte(code_value_int());
5265
+    if (code_seen('B')) i2c.addbyte(code_value_byte());
5268
 
5266
 
5269
     // Flush the buffer to the bus
5267
     // Flush the buffer to the bus
5270
-    else if (code_seen('S')) i2c.send();
5268
+    if (code_seen('S')) i2c.send();
5271
 
5269
 
5272
     // Reset and rewind the buffer
5270
     // Reset and rewind the buffer
5273
     else if (code_seen('R')) i2c.reset();
5271
     else if (code_seen('R')) i2c.reset();
5279
    * Usage: M156 A<slave device address base 10> B<number of bytes>
5277
    * Usage: M156 A<slave device address base 10> B<number of bytes>
5280
    */
5278
    */
5281
   inline void gcode_M156() {
5279
   inline void gcode_M156() {
5282
-    uint8_t addr = code_seen('A') ? code_value_byte() : 0;
5283
-    int bytes    = code_seen('B') ? code_value_int() : 1;
5280
+    if (code_seen('A')) i2c.address(code_value_byte());
5284
 
5281
 
5285
-    if (addr && bytes > 0 && bytes <= 32) {
5286
-      i2c.address(addr);
5282
+    uint8_t bytes = code_seen('B') ? code_value_byte() : 1;
5283
+
5284
+    if (i2c.addr > 0 && bytes > 0 && bytes <= 32) {
5287
       i2c.reqbytes(bytes);
5285
       i2c.reqbytes(bytes);
5288
     }
5286
     }
5289
     else {
5287
     else {

+ 7
- 8
Marlin/twibus.h View File

60
     const int timeout = 5;
60
     const int timeout = 5;
61
 
61
 
62
     /**
62
     /**
63
-     * @brief Target device address
64
-     * @description The target device address. Persists until changed.
65
-     *              
66
-     */
67
-    uint8_t addr = 0;
68
-
69
-    /**
70
      * @brief Number of bytes on buffer
63
      * @brief Number of bytes on buffer
71
      * @description Number of bytes in the buffer waiting to be flushed to the bus.
64
      * @description Number of bytes in the buffer waiting to be flushed to the bus.
72
      */
65
      */
76
      * @brief Internal buffer
69
      * @brief Internal buffer
77
      * @details A fixed buffer. TWI commands can be no longer than this.
70
      * @details A fixed buffer. TWI commands can be no longer than this.
78
      */
71
      */
79
-    char buffer[30];
72
+    char buffer[32];
80
 
73
 
81
 
74
 
82
   public:
75
   public:
83
     /**
76
     /**
77
+     * @brief Target device address
78
+     * @description The target device address. Persists until changed.
79
+     */
80
+    uint8_t addr = 0;
81
+
82
+    /**
84
      * @brief Class constructor
83
      * @brief Class constructor
85
      * @details Initialize the TWI bus and clear the buffer
84
      * @details Initialize the TWI bus and clear the buffer
86
      */
85
      */

Loading…
Cancel
Save