 int register_write(void* userdata, int dev, int reg, int pos, int len, const uint8_t* data) {
 
    if (dev == IDX_DEV) {
+
       switch (reg) {
          
          // LED 1 (red)
          // LED 2 (green)
          //
          case IDX_REG_LED1:
+            digitalWrite(IDX_REG_LED1, data[0] ? HIGH : LOW);
+            return 1;
+
          case IDX_REG_LED2:
-            if (pos == 0 && len == 1) {
-
-               int pin = reg == IDX_REG_LED1 ? PIN_LED1 : PIN_LED2;
-               if (data[0]) {
-                  digitalWrite(pin, HIGH);
-               } else {
-                  digitalWrite(pin, LOW);
-               }
-               return len;
-            } else {
-               return SRDP_ERR_INVALID_REG_POSLEN;
-            }
+            digitalWrite(IDX_REG_LED2, data[0] ? HIGH : LOW);
+            return 1;
 
          // LED 3 (RGB)
          //
          case IDX_REG_LED3:
-            if (pos == 0 && len == 3) {
-
-               led3.write(data[0], data[1], data[2]);
-               return len;
-            } else {
-               return SRDP_ERR_INVALID_REG_POSLEN;
-            }
+            led3.write(data[0], data[1], data[2]);
+            return 3;
 
          // Poti 1/2, Button 1/2 : #watch
          //
          case IDX_REG_POT1_WATCH:
+            pot1.setWatched(data[0] != 0);
+            return 1;
          case IDX_REG_POT2_WATCH:
+            pot2.setWatched(data[0] != 0);
+            return 1;
          case IDX_REG_BTN1_WATCH:
+            btn1.setWatched(data[0] != 0);
+            return 1;
          case IDX_REG_BTN2_WATCH:
-            if (pos == 0 && len == 1) {
-               switch (reg) {
-                  case IDX_REG_POT1_WATCH:
-                     pot1.setWatched(data[0] != 0);
-                     break;
-                  case IDX_REG_POT2_WATCH:
-                     pot2.setWatched(data[0] != 0);
-                     break;
-                  case IDX_REG_BTN1_WATCH:
-                     btn1.setWatched(data[0] != 0);
-                     break;
-                  case IDX_REG_BTN2_WATCH:
-                     btn2.setWatched(data[0] != 0);
-                     break;
-                  default:
-                     // should not arrive here
-                     break;
-               }
-               return 1;
-            } else {
-               return SRDP_ERR_INVALID_REG_POSLEN;
-            }         
+            btn2.setWatched(data[0] != 0);
+            return 1;
 
          // Poti 1/2 : #max
          //
          case IDX_REG_POT1_MAX:
+            pot1.scale(0, *((const uint16_t*) data));
+            return 2;
          case IDX_REG_POT2_MAX:
-            if (pos == 0 && len == 2) {
-               uint16_t max = *((const uint16_t*) data);
-               switch (reg) {
-                  case IDX_REG_POT1_MAX:
-                     pot1.scale(0, max);
-                     break;
-                  case IDX_REG_POT2_MAX:
-                     pot2.scale(0, max);
-                     break;
-                  default:
-                     // should not arrive here
-                     break;
-               }
-               return 2;
-            } else {
-               return SRDP_ERR_INVALID_REG_POSLEN;
-            }         
+            pot2.scale(0, *((const uint16_t*) data));
+            return 2;
 
          // Poti 1/2 : #updateRate
          //
          case IDX_REG_POT1_URATE:
+            pot1.setUpdateRate(*((const uint16_t*) data));
+            return 2;
          case IDX_REG_POT2_URATE:
-            if (pos == 0 && len == 2) {
-               uint16_t urate = *((const uint16_t*) data);
-               switch (reg) {
-                  case IDX_REG_POT1_URATE:
-                     pot1.setUpdateRate(urate);
-                     break;
-                  case IDX_REG_POT2_URATE:
-                     pot2.setUpdateRate(urate);
-                     break;
-                  default:
-                     // should not arrive here
-                     break;
-               }
-               return 2;
-            } else {
-               return SRDP_ERR_INVALID_REG_POSLEN;
-            }         
+            pot2.setUpdateRate(*((const uint16_t*) data));
+            return 2;
 
          case IDX_REG_BTN1:         
          case IDX_REG_BTN2:

      // custom registers for driver (aka "device 0")
      //
      switch (reg) {
         case IDX_REG_FREE_RAM:
            if (pos == 0 && (len == 4 || len == 0)) {
               *((uint32_t*) data) = freeRam();
               return 4;
            } else {
               return SRDP_ERR_INVALID_REG_POSLEN;
            }         
         default:
            return SRDP_ERR_NO_SUCH_REGISTER;
      }

   } else {
      return SRDP_ERR_NO_SUCH_DEVICE;
   }
}


