2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using NativeAdc = Interop.Peripheral.Adc;
20 namespace Tizen.Peripheral
23 /// The class allows applications to use the platform ADC peripheral.
25 /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
26 public class Adc : IDisposable
29 /// Native handle to ADC.
31 private IntPtr _handle;
32 private bool _disposed = false;
35 /// Opens the ADC pin.
37 /// <param name="device">The ADC device number.</param>
38 /// <param name="channel">The ADC channel number to control.</param>
39 public Adc(int device, int channel)
41 var ret = NativeAdc.Open(device, channel, out IntPtr handle);
42 if (ret != Internals.Errors.ErrorCode.None)
43 throw ExceptionFactory.CreateException(ret);
49 /// Closes the ADC pin.
57 /// Gets the current value of the ADC pin.
59 public uint ReadValue()
61 var ret = NativeAdc.Read(_handle, out uint adcValue);
62 if (ret != Internals.Errors.ErrorCode.None)
63 throw ExceptionFactory.CreateException(ret);
69 /// Closes the ADC pin.
71 public void Close() => Dispose();
74 /// Disposes the ADC pin.
79 GC.SuppressFinalize(this);
83 /// Disposes the ADC pin.
85 protected virtual void Dispose(bool disposing)
92 NativeAdc.Close(_handle);