add servo motor api to resoure module
authorJeonghoon Park <jh1979.park@samsung.com>
Fri, 15 Dec 2017 08:26:09 +0000 (17:26 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Fri, 15 Dec 2017 08:26:09 +0000 (17:26 +0900)
inc/resource/resource_servo_motor.h [new file with mode: 0644]
inc/resource/resource_servo_motor_internal.h [new file with mode: 0644]
src/resource/resource_servo_motor.c [new file with mode: 0644]

diff --git a/inc/resource/resource_servo_motor.h b/inc/resource/resource_servo_motor.h
new file mode 100644 (file)
index 0000000..2cda1da
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jeonghoon Park <jh1979.park@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __RESOURCE_SERVO_MOTOR_H__
+#define __RESOURCE_SERVO_MOTOR_H__
+
+int resource_set_servo_motor_value(unsigned int motor_id, int value);
+
+#endif /* __RESOURCE_SERVO_MOTOR_H__ */
diff --git a/inc/resource/resource_servo_motor_internal.h b/inc/resource/resource_servo_motor_internal.h
new file mode 100644 (file)
index 0000000..e038390
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jeonghoon Park <jh1979.park@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __RESOURCE_SERVO_MOTOR_INTERNAL_H__
+#define __RESOURCE_SERVO_MOTOR_INTERNAL_H__
+
+void resource_close_servo_motor(unsigned int ch);
+void resource_close_servo_motor_all(void);
+
+#endif /* __RESOURCE_SERVO_MOTOR_INTERNAL_H__ */
diff --git a/src/resource/resource_servo_motor.c b/src/resource/resource_servo_motor.c
new file mode 100644 (file)
index 0000000..4226597
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jeonghoon Park <jh1979.park@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "log.h"
+#include "resource/resource_PCA9685.h"
+
+#define SERVO_MOTOR_MAX 16
+
+static int servo_motor_index[SERVO_MOTOR_MAX] = {0, };
+
+static int resource_servo_motor_init(unsigned int ch)
+{
+       int ret = 0;
+       ret = resource_pca9685_init(ch);
+       if (ret) {
+               _E("failed to init PCA9685 with ch[%u]", ch);
+               return -1;
+       }
+       servo_motor_index[ch] = 1;
+
+       return 0;
+}
+
+void resource_close_servo_motor(unsigned int ch)
+{
+       if (servo_motor_index[ch] == 1) {
+               resource_pca9685_fini(ch);
+               servo_motor_index[ch] = 0;
+       }
+
+       return;
+}
+
+void resource_close_servo_motor_all(void)
+{
+       unsigned int i;
+
+       for (i = 1; i < SERVO_MOTOR_MAX; i++)
+               resource_close_servo_motor(i);
+
+       return;
+}
+
+int resource_set_servo_motor_value(unsigned int motor_id, int value)
+{
+       int ret = 0;
+
+       if (motor_id == 0)
+               return -1;
+
+       if (motor_id >= SERVO_MOTOR_MAX)
+               return -1;
+
+       if (servo_motor_index[motor_id] == 0) {
+               ret = resource_servo_motor_init(motor_id);
+               if (ret)
+                       return -1;
+       }
+
+       ret = resource_pca9685_set_value_to_channel(motor_id, 0, value);
+
+       return ret;
+}