Exemple #1
0
//******************************************************************************
/// \brief  Set debug state
/// \param  mxt Device context
/// \param  debug_state true = debug enabled, false = debug disabled
/// \return #mxt_rc
int sysfs_set_debug(struct mxt_device *mxt, bool debug_state)
{
  int ret;

  // Check device is initialised
  if (!mxt) {
    mxt_err(mxt->ctx, "Device uninitialised");
    return MXT_ERROR_NO_DEVICE;
  }

  if (mxt->sysfs.debug_v2 == true) {
    ret = write_boolean_file(mxt, make_path(mxt, "debug_v2_enable"), debug_state);
    if (ret)
      ret = write_boolean_file(mxt, make_path(mxt, "debug_enable"), debug_state);

    if (debug_state) {
      ret = sysfs_open_notify_fd(mxt);
      if (ret)
        return ret;
    } else {
      close(mxt->sysfs.debug_notify_fd);
    }
  } else {
    ret = MXT_SUCCESS;

    if (debug_state) {
      // Allocate buffer space
      mxt->sysfs.debug_msg_buf_size = dmesg_buf_size();
      mxt->sysfs.debug_msg_buf =
        (char *)calloc(mxt->sysfs.debug_msg_buf_size, sizeof(char));
      if (mxt->sysfs.debug_msg_buf == NULL) {
        mxt_err(mxt->ctx, "Error allocating memory for debug_msg_buf_size");
        ret = mxt_errno_to_rc(errno);
      }
    } else if (mxt->sysfs.debug_msg_buf) {
      // Free up the message buffer
      free(mxt->sysfs.debug_msg_buf);
      mxt->sysfs.debug_msg_buf = NULL;
    }

    if (ret == MXT_SUCCESS)
      ret = write_boolean_file(mxt, make_path(mxt, "debug_enable"), debug_state);
  }

  return ret;
}
Exemple #2
0
//******************************************************************************
/// \brief  Set debug state
/// \param  mxt Device context
/// \param  debug_state true = debug enabled, false = debug disabled
/// \return #mxt_rc
int sysfs_set_debug(struct mxt_device *mxt, bool debug_state)
{
  int ret;

  // Check device is initialised
  if (!mxt) {
    mxt_err(mxt->ctx, "Device uninitialised");
    return MXT_ERROR_NO_DEVICE;
  }

  if (mxt->sysfs.debug_v2 == true) {
    ret = write_boolean_file(mxt, make_path(mxt, "debug_v2_enable"), debug_state);
    if (ret)
      ret = write_boolean_file(mxt, make_path(mxt, "debug_enable"), debug_state);

    if (debug_state) {
      ret = sysfs_open_notify_fd(mxt);
      if (ret)
        return ret;
    } else {
      close(mxt->sysfs.debug_notify_fd);
    }
  } else {
    if (debug_state) {
      ret = dmesg_alloc_buffer(mxt);
      if (ret)
        return ret;
    } else {
      dmesg_free_buffer(mxt);
    }

    ret = write_boolean_file(mxt, make_path(mxt, "debug_enable"), debug_state);
  }

  return ret;
}