Browse Source

🎨 Misc. shorthand operators

Scott Lahteine 3 years ago
parent
commit
76d784f75f

+ 1
- 1
Marlin/src/HAL/DUE/usb/compiler.h View File

1059
     while (val_index < 8)
1059
     while (val_index < 8)
1060
     {
1060
     {
1061
         data[val_index++] = value & 0xFF;
1061
         data[val_index++] = value & 0xFF;
1062
-        value = value >> 8;
1062
+        value >>= 8;
1063
     }
1063
     }
1064
 }
1064
 }
1065
 
1065
 

+ 8
- 8
Marlin/src/HAL/LINUX/eeprom.cpp View File

69
   std::size_t bytes_written = 0;
69
   std::size_t bytes_written = 0;
70
 
70
 
71
   for (std::size_t i = 0; i < size; i++) {
71
   for (std::size_t i = 0; i < size; i++) {
72
-    buffer[pos+i] = value[i];
73
-    bytes_written ++;
72
+    buffer[pos + i] = value[i];
73
+    bytes_written++;
74
   }
74
   }
75
 
75
 
76
   crc16(crc, value, size);
76
   crc16(crc, value, size);
77
-  pos = pos + size;
77
+  pos += size;
78
   return (bytes_written != size);  // return true for any error
78
   return (bytes_written != size);  // return true for any error
79
 }
79
 }
80
 
80
 
82
   std::size_t bytes_read = 0;
82
   std::size_t bytes_read = 0;
83
   if (writing) {
83
   if (writing) {
84
     for (std::size_t i = 0; i < size; i++) {
84
     for (std::size_t i = 0; i < size; i++) {
85
-      value[i] = buffer[pos+i];
86
-      bytes_read ++;
85
+      value[i] = buffer[pos + i];
86
+      bytes_read++;
87
     }
87
     }
88
     crc16(crc, value, size);
88
     crc16(crc, value, size);
89
   }
89
   }
90
   else {
90
   else {
91
     uint8_t temp[size];
91
     uint8_t temp[size];
92
     for (std::size_t i = 0; i < size; i++) {
92
     for (std::size_t i = 0; i < size; i++) {
93
-      temp[i] = buffer[pos+i];
94
-      bytes_read ++;
93
+      temp[i] = buffer[pos + i];
94
+      bytes_read++;
95
     }
95
     }
96
     crc16(crc, temp, size);
96
     crc16(crc, temp, size);
97
   }
97
   }
98
 
98
 
99
-  pos = pos + size;
99
+  pos += size;
100
   return bytes_read != size;  // return true for any error
100
   return bytes_read != size;  // return true for any error
101
 }
101
 }
102
 
102
 

+ 2
- 2
Marlin/src/HAL/LINUX/hardware/Heater.h View File

26
 struct LowpassFilter {
26
 struct LowpassFilter {
27
   uint64_t data_delay = 0;
27
   uint64_t data_delay = 0;
28
   uint16_t update(uint16_t value) {
28
   uint16_t update(uint16_t value) {
29
-    data_delay = data_delay - (data_delay >> 6) + value;
30
-    return (uint16_t)(data_delay >> 6);
29
+    data_delay += value - (data_delay >> 6);
30
+    return uint16_t(data_delay >> 6);
31
   }
31
   }
32
 };
32
 };
33
 
33
 

+ 2
- 2
Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp View File

135
   while ((instruction = UnwTabGetNextInstruction(cb, ucb)) != -1) {
135
   while ((instruction = UnwTabGetNextInstruction(cb, ucb)) != -1) {
136
 
136
 
137
     if ((instruction & 0xC0) == 0x00) { // ARM_EXIDX_CMD_DATA_POP
137
     if ((instruction & 0xC0) == 0x00) { // ARM_EXIDX_CMD_DATA_POP
138
-      /* vsp = vsp + (xxxxxx << 2) + 4 */
138
+      /* vsp += (xxxxxx << 2) + 4 */
139
       ucb->vrs[13] += ((instruction & 0x3F) << 2) + 4;
139
       ucb->vrs[13] += ((instruction & 0x3F) << 2) + 4;
140
     }
140
     }
141
     else if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH
141
     else if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH
142
-      /* vsp = vsp - (xxxxxx << 2) - 4 */
142
+      /* vsp -= (xxxxxx << 2) - 4 */
143
       ucb->vrs[13] -= ((instruction & 0x3F) << 2) - 4;
143
       ucb->vrs[13] -= ((instruction & 0x3F) << 2) - 4;
144
     }
144
     }
145
     else if ((instruction & 0xF0) == 0x80) {
145
     else if ((instruction & 0xF0) == 0x80) {

+ 1
- 1
Marlin/src/feature/power_monitor.h View File

32
   uint32_t filter_buf;
32
   uint32_t filter_buf;
33
   float value;
33
   float value;
34
   void add_sample(const uint16_t sample) {
34
   void add_sample(const uint16_t sample) {
35
-    filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
35
+    filter_buf += (uint32_t(sample) << K_SCALE) - (filter_buf >> K_VALUE);
36
   }
36
   }
37
   void capture() {
37
   void capture() {
38
     value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE))));
38
     value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE))));

+ 2
- 2
Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp View File

1141
         else
1141
         else
1142
           queue.inject(F("M290 Z-0.01"));
1142
           queue.inject(F("M290 Z-0.01"));
1143
 
1143
 
1144
-        z_offset_add = z_offset_add - ZOffset_distance;
1144
+        z_offset_add -= ZOffset_distance;
1145
         break;
1145
         break;
1146
 
1146
 
1147
       case 1:
1147
       case 1:
1156
         else
1156
         else
1157
           queue.inject(F("M290 Z-0.01"));
1157
           queue.inject(F("M290 Z-0.01"));
1158
 
1158
 
1159
-        z_offset_add = z_offset_add + ZOffset_distance;
1159
+        z_offset_add += ZOffset_distance;
1160
         break;
1160
         break;
1161
 
1161
 
1162
       default:
1162
       default:

+ 1
- 1
Marlin/src/lcd/extui/mks_ui/wifi_module.cpp View File

1638
 
1638
 
1639
       esp_msg_index += cpyLen;
1639
       esp_msg_index += cpyLen;
1640
 
1640
 
1641
-      leftLen = leftLen - cpyLen;
1641
+      leftLen -= cpyLen;
1642
       tail_pos = charAtArray(esp_msg_buf, esp_msg_index, ESP_PROTOC_TAIL);
1642
       tail_pos = charAtArray(esp_msg_buf, esp_msg_index, ESP_PROTOC_TAIL);
1643
 
1643
 
1644
       if (tail_pos == -1) {
1644
       if (tail_pos == -1) {

+ 1
- 1
Marlin/src/lcd/tft/touch.cpp View File

175
       ui.refresh();
175
       ui.refresh();
176
       break;
176
       break;
177
     case PAGE_DOWN:
177
     case PAGE_DOWN:
178
-      encoderTopLine = encoderTopLine + 2 * LCD_HEIGHT < screen_items ? encoderTopLine + LCD_HEIGHT : screen_items - LCD_HEIGHT;
178
+      encoderTopLine = (encoderTopLine + 2 * LCD_HEIGHT < screen_items) ? encoderTopLine + LCD_HEIGHT : screen_items - LCD_HEIGHT;
179
       ui.encoderPosition = ui.encoderPosition + LCD_HEIGHT < (uint32_t)screen_items ? ui.encoderPosition + LCD_HEIGHT : screen_items;
179
       ui.encoderPosition = ui.encoderPosition + LCD_HEIGHT < (uint32_t)screen_items ? ui.encoderPosition + LCD_HEIGHT : screen_items;
180
       ui.refresh();
180
       ui.refresh();
181
       break;
181
       break;

Loading…
Cancel
Save