   g_buf[3] = ((uint8_t *)&g_body_len)[0];
 
   Serial.write(g_buf, g_body_len + HEADER_LEN);
-///  Serial.flush();
+  ///  Serial.flush();
 }
 
 void report_status() {

  if (strcmp(root["cmd"], "switch_set") == 0) {
    int j = min(CHILD_NUM, root["status"].size());
    for (int i = 0; i < j; i++) {
      uint8_t st = root["status"][i];
      set_status(i, st);
    }
  } else if (strcmp(root["cmd"], "switch_get") == 0) {
    g_need_report = 1;
  }
}

void set_status(int index, char st) {
  if (st != 0)
    st = 1;

  Serial.print("set:");
  Serial.println(index);
  Serial.println((int)st);

  if (g_status[index] != st) {
    g_status[index] = st;
  }
   
  if (st == 0) {
    digitalWrite(FIRST_PIN + index, LOW);
  } else {
    digitalWrite(FIRST_PIN + index, HIGH);
  }
  g_need_report = 1;
}

void get_all_status() {
  
}

void check_status() {
  char st[CHILD_NUM] = {0};
  int i = 0;

  for (i = 0; i < CHILD_NUM; i++) {
    st[i] = g_status[i];
  }

  get_all_status();

  for (i = 0; i < CHILD_NUM; i++) {
    if (g_status[i] != st[i]) {
      g_need_report = 1;
      break;
    }
  }
}


  }
}

void init_child() {
  InitTimersSafe();

  for (int i = 0; i < CHILD_NUM; i++) {
    g_child[i] = new Child(FIRST_PIN_CTRL + i, FIRST_PIN_LED + i, FIRST_PIN_PWM + i, FIRST_PIN_TOUCH + i);
  }
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.setTimeout(100);
  Serial.println("setup...");

  init_child();
}

void loop() {
  // put your main code here, to run repeatedly:
  handle_input();

  if (g_need_report) {
    report_status();
    g_need_report = 0;
  }

  for (int i = 0; i < CHILD_NUM; i++) {
    g_child[i]->loop();
  }

  delay(1);
}
