├── README.md
├── Release Notes
├── SPI_SETUP
├── BLACKLIB-SPI0-00A0.dts
├── BLACKLIB-SPI1-00A0.dts
├── readme.md
├── setup_from_BBB
└── setup_from_host
├── v1_0
├── BlackDef.h
├── BlackErr.h
├── BlackLib.cpp
├── BlackLib.h
├── DOCS
│ ├── EN
│ │ ├── BlackLib-UserManual.pdf
│ │ └── GpioFlagsUsageTable.pdf
│ └── TR
│ │ ├── BlackLib-KullanimKilavuzu.pdf
│ │ └── GpioBayraklariKullanimTablosu.pdf
├── LICENSE
│ ├── COPYING
│ └── COPYING.LESSER
├── README
└── example.cpp
├── v2_0
├── BlackADC.cpp
├── BlackADC.h
├── BlackCore.cpp
├── BlackCore.h
├── BlackDef.h
├── BlackErr.h
├── BlackGPIO.cpp
├── BlackGPIO.h
├── BlackI2C.cpp
├── BlackI2C.h
├── BlackLib.h
├── BlackPWM.cpp
├── BlackPWM.h
├── BlackSPI.cpp
├── BlackSPI.h
├── BlackUART.cpp
├── BlackUART.h
├── LICENSE
│ ├── COPYING
│ └── COPYING.LESSER
├── README.md
├── ReleaseNotes
├── SPI_SETUP
│ ├── BLACKLIB-SPI0-00A0.dts
│ ├── BLACKLIB-SPI1-00A0.dts
│ ├── readme.md
│ ├── setup_from_BBB
│ └── setup_from_host
├── WebPages.dox
├── exampleAndTiming.cpp
└── exampleAndTiming
│ ├── Timing.cpp
│ ├── Timing.h
│ ├── exampleAndTiming_ADC.h
│ ├── exampleAndTiming_GPIO.h
│ ├── exampleAndTiming_I2C.h
│ ├── exampleAndTiming_PWM.h
│ ├── exampleAndTiming_SPI.h
│ ├── exampleAndTiming_UART.h
│ └── results
│ ├── BlackADC_timing_results.out
│ ├── BlackGPIO_timing_results.out
│ ├── BlackI2C_timing_results.out
│ ├── BlackPWM_timing_results.out
│ ├── BlackSPI_timing_results.out
│ └── BlackUART_timing_results.out
└── v3_0
├── BlackADC
├── BlackADC.cpp
└── BlackADC.h
├── BlackCore.cpp
├── BlackCore.h
├── BlackDef.h
├── BlackDirectory
├── BlackDirectory.cpp
└── BlackDirectory.h
├── BlackErr.h
├── BlackGPIO
├── BlackGPIO.cpp
└── BlackGPIO.h
├── BlackI2C
├── BlackI2C.cpp
└── BlackI2C.h
├── BlackLib.h
├── BlackMutex
├── BlackMutex.cpp
└── BlackMutex.h
├── BlackPWM
├── BlackPWM.cpp
└── BlackPWM.h
├── BlackSPI
├── BlackSPI.cpp
└── BlackSPI.h
├── BlackThread
├── BlackThread.cpp
└── BlackThread.h
├── BlackTime
├── BlackTime.cpp
└── BlackTime.h
├── BlackUART
├── BlackUART.cpp
└── BlackUART.h
├── LICENSE
├── COPYING
└── COPYING.LESSER
├── README.md
├── Release Notes
├── SPI_SETUP
├── BLACKLIB-SPI0-00A0.dts
├── BLACKLIB-SPI1-00A0.dts
├── readme.md
├── setup_from_BBB
└── setup_from_host
├── examples.cpp
├── examples
├── example_ADC.h
├── example_GPIO.h
├── example_I2C.h
├── example_PWM.h
├── example_SPI.h
├── example_UART.h
├── example_directory.h
├── example_threadAndMutex.h
└── example_time.h
└── makefile
/README.md:
--------------------------------------------------------------------------------
1 | BlackLib library is written for controlling Beaglebone Black's feature. It takes power from C++ language. It is created for reading analog input, generating pwm signal, using gpio pins, and communicating with other devices over uart, spi and i2c. In addition to them, it includes debugging feature. So you can check errors after call any function in the library. It also takes parallel programming, mutex usability, realization of directory operation and realization of time operation ability with the last update(BlackLiv v3.0).
2 |
3 |
4 | --------------------------------------------------------------------------------
5 | ## Debugging
6 |
7 | It always tracks member functions errors and records these errors to data structures. All end nodes which interact with end users, have overloaded fail() functions. So you can check all errors or specific error whichever you want.
8 |
9 |
10 | --------------------------------------------------------------------------------
11 | ## Class Hierarchy
12 |
13 | ### Library Core
14 |
15 | BlackLib includes BlackCore class for doing core process. End users can't access to it. Because it is abstract class and all member functions, except constructor and destructor, are private or protected.
16 |
17 | ### Sub Level Cores
18 |
19 | BlackLib includes sub level cores for GPIO, ADC and PWM features. Preparing stages are realized in here, at sub level cores. Therefore, if you don't like end nodes or you don't want to use these, you can derive your own class(es), from these sub level cores. But end nodes designed for taking care of your all need.
20 |
21 | ### End Node Classes
22 |
23 | End node classes are designed for interacting with end user. You can read, set or control Beaglebone Black's ADC, GPIO or PWM features or you can communicate with other devices with using UART, SPI or I2C protocol, from these classes. Also you can develop professional applications with using parallel programming, mutexes, directory operations and time operations. These classes include primary functions like read or set properties of Beaglebone Black's features and include additional functions like ADC parser, gpio pin toggle etc. to make easier your life.
24 |
25 |
26 | --------------------------------------------------------------------------------
27 | ## Definitions
28 |
29 | BlackLib includes enum type definitions for your and Beaglebone Black's safety. GPIO, ADC, PWM, UART, SPI, I2C names; PWM, GPIO values; GPIO directions and a lot more features defined with enums. It means you can't call some member functions without use this enums. These enums avoid user errors like write 345 to gpio export file instead of 34.
30 |
31 |
32 | --------------------------------------------------------------------------------
33 | ## Contact
34 |
35 | For any comment or suggestion please contact the creator of BlackLib Library at contact[at]blacklib.yigityuce.com
36 |
37 |
38 | --------------------------------------------------------------------------------
39 | http://blacklib.yigityuce.com
40 |
--------------------------------------------------------------------------------
/Release Notes:
--------------------------------------------------------------------------------
1 |
2 |
3 | RELEASE NOTES FOR BLACKLIB v3.0
4 |
5 |
6 | New Features
7 |
8 | # New Classes:
9 |
10 | * Add BlackDirectory class for executing "rmdir", "rm -rf", "mkdir", "ls", "cd", "pwd" etc. commands.
11 | * Add BlackThread class for supporting multi-task operations(parallel programming).
12 | * Add BlackMutex class for supporting thread synchronization and developing safe applications.
13 | * Add BlackTime class for doing basic time operations and measuring the elapsed time.
14 |
15 | # Usability:
16 |
17 | * Add makefile support for cross-compilation.
18 |
19 |
20 |
21 |
22 |
23 |
24 | Updates
25 |
26 | # Bug Fixes:
27 |
28 | * Add "unistd.h" include file to BlackUART, BlackSPI and BlackI2C classes.
29 |
30 | # Usability Improvements:
31 |
32 | * Update BlackDef.h and some enumarations are distributed to related files.
33 |
34 | # Documantation:
35 |
36 | * Update "Example Project File Tree"s in the all classes.
37 |
38 | # Design Updates:
39 |
40 | * Remove Timing class from the "exampleAndTiming" directory.
41 | * Change "exampleAndTiming" directory name to "examples".
42 | * Add "BlackADC", "BlackGPIO", "BlackPWM", "BlackI2C", "BlackUART" and "BlackSPI" directories and source
43 | files of these classes are moved to these directories.
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/SPI_SETUP/BLACKLIB-SPI0-00A0.dts:
--------------------------------------------------------------------------------
1 | /*
2 | * ####################################################################################
3 | * # Custom device tree file to create virtual SPI0 cape in BlackLib Library. #
4 | * # Copyright (C) 2014 by Yigit YUCE #
5 | * ####################################################################################
6 | * # #
7 | * # This file is part of BlackLib library. #
8 | * # #
9 | * # BlackLib library is free software: you can redistribute it and/or modify #
10 | * # it under the terms of the GNU Lesser General Public License as published by #
11 | * # the Free Software Foundation, either version 3 of the License, or #
12 | * # (at your option) any later version. #
13 | * # #
14 | * # BlackLib library is distributed in the hope that it will be useful, #
15 | * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 | * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 | * # GNU Lesser General Public License for more details. #
18 | * # #
19 | * # You should have received a copy of the GNU Lesser General Public License #
20 | * # along with this program. If not, see . #
21 | * # #
22 | * # For any comment or suggestion please contact the creator of BlackLib Library #
23 | * # at ygtyce@gmail.com #
24 | * # #
25 | * ####################################################################################
26 | */
27 |
28 | /dts-v1/;
29 | /plugin/;
30 |
31 | / {
32 | compatible = "ti,beaglebone", "ti,beaglebone-black";
33 |
34 | part-number = "BLACKLIB-SPI0";
35 | version = "00A0";
36 |
37 | exclusive-use =
38 | "P9.17", /* spi0_cs0 */
39 | "P9.18", /* spi0_d1 */
40 | "P9.21", /* spi0_d0 */
41 | "P9.22", /* spi0_sclk */
42 | "spi0"; /* the hardware ip uses */
43 |
44 | fragment@0 {
45 | target = <&am33xx_pinmux>;
46 | __overlay__ {
47 | bb_spi0_pins: pinmux_bb_spi0_pins {
48 | pinctrl-single,pins = <
49 | 0x150 0x30 /* spi0_sclk.spi0_sclk, INPUT_PULLUP | MODE0 */
50 | 0x154 0x30 /* spi0_d0.spi0_d0, INPUT_PULLUP | MODE0 */
51 | 0x158 0x10 /* spi0_d1.spi0_d1, OUTPUT_PULLUP | MODE0 */
52 | 0x15c 0x10 /* spi0_cs0.spi0_cs0, OUTPUT_PULLUP | MODE0 */
53 | >;
54 | };
55 | };
56 | };
57 |
58 | fragment@1 {
59 | target = <&spi0>;
60 | __overlay__ {
61 | #address-cells = <1>;
62 | #size-cells = <0>;
63 |
64 | status = "okay";
65 | pinctrl-names = "default";
66 | pinctrl-0 = <&bb_spi0_pins>;
67 |
68 | spidev@0{
69 | compatible = "spidev";
70 | reg = <0>;
71 | spi-max-frequency = <24000000>;
72 | };
73 | spidev@1{
74 | compatible = "spidev";
75 | reg = <1>;
76 | spi-max-frequency = <24000000>;
77 | };
78 | };
79 | };
80 | };
81 |
--------------------------------------------------------------------------------
/SPI_SETUP/BLACKLIB-SPI1-00A0.dts:
--------------------------------------------------------------------------------
1 | /*
2 | * ####################################################################################
3 | * # Custom device tree file to create virtual SPI0 cape in BlackLib Library. #
4 | * # Copyright (C) 2014 by Yigit YUCE #
5 | * ####################################################################################
6 | * # #
7 | * # This file is part of BlackLib library. #
8 | * # #
9 | * # BlackLib library is free software: you can redistribute it and/or modify #
10 | * # it under the terms of the GNU Lesser General Public License as published by #
11 | * # the Free Software Foundation, either version 3 of the License, or #
12 | * # (at your option) any later version. #
13 | * # #
14 | * # BlackLib library is distributed in the hope that it will be useful, #
15 | * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 | * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 | * # GNU Lesser General Public License for more details. #
18 | * # #
19 | * # You should have received a copy of the GNU Lesser General Public License #
20 | * # along with this program. If not, see . #
21 | * # #
22 | * # For any comment or suggestion please contact the creator of BlackLib Library #
23 | * # at ygtyce@gmail.com #
24 | * # #
25 | * ####################################################################################
26 | */
27 |
28 | /dts-v1/;
29 | /plugin/;
30 |
31 | / {
32 | compatible = "ti,beaglebone", "ti,beaglebone-black";
33 |
34 | part-number = "BLACKLIB-SPI1";
35 | version = "00A0";
36 |
37 | exclusive-use =
38 | "P9.31", /* spi1_sclk */
39 | "P9.29", /* spi1_d0 */
40 | "P9.30", /* spi1_d1 */
41 | "P9.28", /* spi1_cs0 */
42 | // "P9.42", /* spi1_cs1 */
43 | "spi1"; /* the hardware ip uses */
44 |
45 | fragment@0 {
46 | target = <&am33xx_pinmux>;
47 | __overlay__ {
48 | bb_spi1_pins: pinmux_bb_spi1_pins {
49 | pinctrl-single,pins = <
50 | 0x190 0x33 /* mcasp0_aclkx.spi1_sclk, INPUT_PULLUP | MODE3 */
51 | 0x194 0x33 /* mcasp0_fsx.spi1_d0, INPUT_PULLUP | MODE3 */
52 | 0x198 0x13 /* mcasp0_axr0.spi1_d1, OUTPUT_PULLUP | MODE3 */
53 | 0x19c 0x13 /* mcasp0_ahclkr.spi1_cs0, OUTPUT_PULLUP | MODE3 */
54 | // 0x164 0x12 /* eCAP0_in_PWM0_out.spi1_cs1 OUTPUT_PULLUP | MODE2 */
55 | >;
56 | };
57 | };
58 | };
59 |
60 | fragment@1 {
61 | target = <&spi1>;
62 | __overlay__ {
63 | #address-cells = <1>;
64 | #size-cells = <0>;
65 |
66 | status = "okay";
67 | pinctrl-names = "default";
68 | pinctrl-0 = <&bb_spi1_pins>;
69 |
70 | spidev@0{
71 | compatible = "spidev";
72 | reg = <0>;
73 | spi-max-frequency = <24000000>;
74 | };
75 | spidev@1{
76 | compatible = "spidev";
77 | reg = <1>;
78 | spi-max-frequency = <24000000>;
79 | };
80 | };
81 | };
82 | };
83 |
--------------------------------------------------------------------------------
/SPI_SETUP/readme.md:
--------------------------------------------------------------------------------
1 | If you want to use spi, you must use custom device tree overlays.
2 | For this reason i wrote setup scripts and custom device tree overlays.
3 | You must run one of these scripts for using spi feature of Beaglebone
4 | Black. You can do this with two ways.
5 |
6 | ### FROM HOST PC
7 |
8 | - If you are doing these steps from your host pc, you must run
9 | "setup_from_host" script. Before run this, you must give executable
10 | permission.
11 |
12 | - You can do this with this command: "chmod +x setup_from_host"
13 |
14 | - "BLACKLIB-SPI0-00A0.dts", "BLACKLIB-SPI1-00A0.dts" and "setup_from_host" files
15 | must be located in this directory.
16 |
17 | - After do that you must run the script with this command: "./setup_from_host"
18 |
19 | - When you run the script, it will ask you Beaglebone Black's root user's
20 | password two times. This is required for executing "scp" and "ssh" command.
21 |
22 | - That's all.
23 |
24 |
25 |
26 | ### INSIDE FROM BEAGLEBONE BLACK
27 |
28 | - If you are doing these steps from your BBB, you must connect to BBB and
29 | change your current directory to script's directory with "cd" command.
30 |
31 | - "BLACKLIB-SPI0-00A0.dts", "BLACKLIB-SPI1-00A0.dts" and "setup_from_BBB" files
32 | must be located in this directory.
33 |
34 | - Before run this script, you must give executable permission. You can do this
35 | with this command: "chmod +x setup_from_BBB"
36 |
37 | - After do that you must run the script with this command: "./setup_from_BBB"
38 |
39 | - That's all.
40 |
41 |
--------------------------------------------------------------------------------
/SPI_SETUP/setup_from_BBB:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | dtc -O dtb -o BLACKLIB-SPI0-00A0.dtbo -b 0 -@ BLACKLIB-SPI0-00A0.dts
4 |
5 | dtc -O dtb -o BLACKLIB-SPI1-00A0.dtbo -b 0 -@ BLACKLIB-SPI1-00A0.dts
6 |
7 | cp -r BLACKLIB-SPI0-00A0.dtbo BLACKLIB-SPI1-00A0.dtbo /lib/firmware
8 |
9 | rm -rf BLACKLIB-SPI*
10 |
--------------------------------------------------------------------------------
/SPI_SETUP/setup_from_host:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | scp BLACKLIB-SPI0-00A0.dts BLACKLIB-SPI1-00A0.dts root@192.168.7.2:/tmp
4 |
5 | ssh root@192.168.7.2 '
6 | cd /tmp
7 |
8 | dtc -O dtb -o BLACKLIB-SPI0-00A0.dtbo -b 0 -@ BLACKLIB-SPI0-00A0.dts
9 |
10 | dtc -O dtb -o BLACKLIB-SPI1-00A0.dtbo -b 0 -@ BLACKLIB-SPI1-00A0.dts
11 |
12 | cp -r BLACKLIB-SPI0-00A0.dtbo BLACKLIB-SPI1-00A0.dtbo /lib/firmware
13 |
14 | rm -rf BLACKLIB-SPI*
15 | '
16 |
--------------------------------------------------------------------------------
/v1_0/DOCS/EN/BlackLib-UserManual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yigityuce/BlackLib/f722948929036d492819dcd2daed373e66c1d25e/v1_0/DOCS/EN/BlackLib-UserManual.pdf
--------------------------------------------------------------------------------
/v1_0/DOCS/EN/GpioFlagsUsageTable.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yigityuce/BlackLib/f722948929036d492819dcd2daed373e66c1d25e/v1_0/DOCS/EN/GpioFlagsUsageTable.pdf
--------------------------------------------------------------------------------
/v1_0/DOCS/TR/BlackLib-KullanimKilavuzu.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yigityuce/BlackLib/f722948929036d492819dcd2daed373e66c1d25e/v1_0/DOCS/TR/BlackLib-KullanimKilavuzu.pdf
--------------------------------------------------------------------------------
/v1_0/DOCS/TR/GpioBayraklariKullanimTablosu.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yigityuce/BlackLib/f722948929036d492819dcd2daed373e66c1d25e/v1_0/DOCS/TR/GpioBayraklariKullanimTablosu.pdf
--------------------------------------------------------------------------------
/v1_0/LICENSE/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/v1_0/README:
--------------------------------------------------------------------------------
1 | BlackLib library is wrote for controlling Beaglebone Black's feature. It takes power from C++ language. It is created for reading analog input, generating pwm signal and using gpio pins. In addition to them, it includes debugging feature. So you can check errors after call any function in the library.
2 |
3 |
4 | --------------------------------------------------------------------------------
5 | + Debugging
6 |
7 | It always tracks member functions errors and records these errors to data structures. All end nodes which interact with end users, have overloaded fail() functions. So you can check all errors or specific error whichever you want.
8 |
9 |
10 | --------------------------------------------------------------------------------
11 | + Class Hierarchy
12 |
13 | + + Library Core
14 |
15 | BlackLib includes BlackCore class for doing core process. End users can't access to it. Because it is abstract class and all member functions, except constructor and destructor, are private or protected.
16 |
17 | + + Sub Level Cores
18 |
19 | BlackLib includes sub level cores for GPIO, ADC and PWM features. Preparing, device tree loading or initialization stages are realized in here, at sub level cores. Therefore, if you don't like end nodes or you don't want to use these, you can derive your own class(es), from these sub level cores. But end nodes designed for taking care of your all need.
20 |
21 | + + End Node Classes
22 |
23 | End node classes are designed for interacting with end user. You can read, set or control Beaglebone Black's ADC, GPIO or PWM features from these classes. These classes include primary functions like read or set properties of Beaglebone Black's features and include additional functions like ADC parser, gpio pin toggle etc. to make easier your life.
24 |
25 |
26 | --------------------------------------------------------------------------------
27 | + Definitions
28 |
29 | BlackLib includes enum type definitions for your and Beaglebone Black's safety. GPIO, ADC, PWM names; PWM, GPIO values; GPIO directions and a lot more features defined with enums. It means you can't call some member functions without use this enums. These enums avoid user errors like write 345 to gpio export file instead of 34.
30 |
31 |
32 | --------------------------------------------------------------------------------
33 | + Contact
34 |
35 | For any comment or suggestion please contact the creator of BlackLib Library at contact@blacklib.yigityuce.com
36 |
37 |
38 | --------------------------------------------------------------------------------
39 | blacklib.yigityuce.com
40 |
--------------------------------------------------------------------------------
/v1_0/example.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ########################################################################################
4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5 | # Copyright (C) 2013-2014 by Yigit YUCE #
6 | ########################################################################################
7 | # #
8 | # This file is part of BlackLib library. #
9 | # #
10 | # BlackLib library is free software: you can redistribute it and/or modify #
11 | # it under the terms of the GNU Lesser General Public License as published by #
12 | # the Free Software Foundation, either version 3 of the License, or #
13 | # (at your option) any later version. #
14 | # #
15 | # BlackLib library is distributed in the hope that it will be useful, #
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18 | # GNU Lesser General Public License for more details. #
19 | # #
20 | # You should have received a copy of the GNU Lesser General Public License #
21 | # along with this program. If not, see . #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ########################################################################################
27 |
28 | */
29 |
30 |
31 | #include
32 | #include
33 | #include
34 | #include "BlackLib.h"
35 | using namespace std;
36 |
37 | void linePrint(int number,char symbol)
38 | {
39 | for(int i=0;i. #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ####################################################################################
27 |
28 | */
29 |
30 | #include "BlackCore.h"
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | namespace BlackLib
39 | {
40 |
41 | // ########################################### BLACKCORE DEFINITION STARTS ########################################### //
42 | BlackCore::BlackCore()
43 | {
44 | this->coreErrors = new errorCore();
45 |
46 | this->findCapeMgrName();
47 | this->findOcpName();
48 | this->slotsFilePath = "/sys/devices/" + this->capeMgrName + "/slots";
49 | }
50 |
51 | BlackCore::~BlackCore()
52 | {
53 | delete this->coreErrors;
54 | }
55 |
56 | std::string BlackCore::executeCommand(std::string command)
57 | {
58 | FILE* pipe = popen(command.c_str(), "r");
59 | if ( pipe==NULL )
60 | {
61 | return "ERROR";
62 | }
63 |
64 | char buffer[128];
65 | std::string result = "";
66 |
67 | while( !feof(pipe) )
68 | {
69 | if( fgets(buffer, 128, pipe) != NULL )
70 | {
71 | result += buffer;
72 | }
73 | }
74 |
75 | pclose(pipe);
76 | return result;
77 | }
78 |
79 | std::string BlackCore::searchDirectory(std::string seachIn, std::string searchThis)
80 | {
81 | std::string str;
82 | DIR *path;
83 | dirent *entry;
84 |
85 | path = opendir(seachIn.c_str());
86 | if( path != NULL )
87 | {
88 | while( (entry = readdir(path)) != NULL)
89 | {
90 | if( entry->d_name[0] == '.')
91 | {
92 | continue;
93 | }
94 |
95 | str = entry->d_name;
96 | if(strstr(entry->d_name,searchThis.c_str()) != NULL )
97 | {
98 | closedir(path);
99 | return str;
100 | }
101 | }
102 | }
103 | closedir(path);
104 |
105 | return SEARCH_DIR_NOT_FOUND;
106 | }
107 |
108 | bool BlackCore::findCapeMgrName()
109 | {
110 | std::string searchResult = this->searchDirectory("/sys/devices/","bone_capemgr.");
111 |
112 | if(searchResult == SEARCH_DIR_NOT_FOUND)
113 | {
114 | this->capeMgrName = "bone_capemgr." + DEFAULT_CAPE_MGR_NUMBER;
115 | this->coreErrors->capeMgrError = true;
116 | return false;
117 | }
118 | else
119 | {
120 | this->capeMgrName = searchResult;
121 | this->coreErrors->capeMgrError = false;
122 | return true;
123 | }
124 | }
125 |
126 | bool BlackCore::findOcpName()
127 | {
128 | std::string searchResult = this->searchDirectory("/sys/devices/","ocp.");
129 |
130 | if(searchResult == SEARCH_DIR_NOT_FOUND)
131 | {
132 | this->ocpName = "ocp." + DEFAULT_OCP_NUMBER;
133 | this->coreErrors->ocpError = true;
134 | return false;
135 | }
136 | else
137 | {
138 | this->ocpName = searchResult;
139 | this->coreErrors->ocpError = false;
140 | return true;
141 | }
142 | }
143 |
144 |
145 |
146 |
147 | std::string BlackCore::searchDirectoryOcp(BlackCore::ocpSearch searchThis)
148 | {
149 | std::string searchResult;
150 | std::string searchPath = "/sys/devices/" + this->getOcpName() + "/";
151 |
152 | if( searchThis == this->SPI0 )
153 | {
154 | searchPath += DEFAULT_SPI0_PINMUX + ".spi/spi_master/";
155 | }
156 | else if( searchThis == this->SPI1 )
157 | {
158 | searchPath += DEFAULT_SPI1_PINMUX + ".spi/spi_master/";
159 | }
160 |
161 |
162 | switch(searchThis)
163 | {
164 | case ADC_helper:
165 | {
166 | searchResult = this->searchDirectory(searchPath,"helper.");
167 | break;
168 | }
169 |
170 | case PWM_P8_13:
171 | {
172 | searchResult = this->searchDirectory(searchPath,"pwm_test_P8_13.");
173 | break;
174 | }
175 |
176 | case PWM_P8_19:
177 | {
178 | searchResult = this->searchDirectory(searchPath,"pwm_test_P8_19.");
179 | break;
180 | }
181 |
182 | case PWM_P9_14:
183 | {
184 | searchResult = this->searchDirectory(searchPath,"pwm_test_P9_14.");
185 | break;
186 | }
187 |
188 | case PWM_P9_16:
189 | {
190 | searchResult = this->searchDirectory(searchPath,"pwm_test_P9_16.");
191 | break;
192 | }
193 |
194 | case PWM_P9_21:
195 | {
196 | searchResult = this->searchDirectory(searchPath,"pwm_test_P9_21.");
197 | break;
198 | }
199 |
200 | case PWM_P9_22:
201 | {
202 | searchResult = this->searchDirectory(searchPath,"pwm_test_P9_22.");
203 | break;
204 | }
205 |
206 | case PWM_P9_42:
207 | {
208 | searchResult = this->searchDirectory(searchPath,"pwm_test_P9_42.");
209 | break;
210 | }
211 |
212 | case SPI0:
213 | {
214 | searchResult = this->searchDirectory(searchPath,"spi");
215 | break;
216 | }
217 |
218 | case SPI1:
219 | {
220 | searchResult = this->searchDirectory(searchPath,"spi");
221 | break;
222 | }
223 | }
224 |
225 |
226 | return searchResult;
227 | }
228 |
229 | errorCore *BlackCore::getErrorsFromCore()
230 | {
231 | return (this->coreErrors);
232 | }
233 |
234 |
235 |
236 | std::string BlackCore::getCapeMgrName()
237 | {
238 | return this->capeMgrName;
239 | }
240 |
241 | std::string BlackCore::getOcpName()
242 | {
243 | return this->ocpName;
244 | }
245 |
246 | std::string BlackCore::getSlotsFilePath()
247 | {
248 | return this->slotsFilePath;
249 | }
250 |
251 | // ############################################ BLACKCORE DEFINITION ENDS ############################################ //
252 |
253 |
254 |
255 | } /* namespace BlackLib */
256 |
--------------------------------------------------------------------------------
/v2_0/BlackCore.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ####################################################################################
4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5 | # Copyright (C) 2013-2014 by Yigit YUCE #
6 | ####################################################################################
7 | # #
8 | # This file is part of BlackLib library. #
9 | # #
10 | # BlackLib library is free software: you can redistribute it and/or modify #
11 | # it under the terms of the GNU Lesser General Public License as published by #
12 | # the Free Software Foundation, either version 3 of the License, or #
13 | # (at your option) any later version. #
14 | # #
15 | # BlackLib library is distributed in the hope that it will be useful, #
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18 | # GNU Lesser General Public License for more details. #
19 | # #
20 | # You should have received a copy of the GNU Lesser General Public License #
21 | # along with this program. If not, see . #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ####################################################################################
27 |
28 | */
29 |
30 | #ifndef BLACKCORE_H_
31 | #define BLACKCORE_H_
32 |
33 |
34 | #include "BlackErr.h" // Black Errors header file
35 | #include "BlackDef.h" // Black Definitions header file
36 |
37 |
38 | #include
39 | #include
40 | #include // need for tostr() function
41 | #include // need for popen() function in BlackCore::executeShellCmd()
42 | #include // need for dirent struct in BlackCore::searchDirectory()
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | namespace BlackLib
52 | {
53 |
54 | /*! @brief Uses for converting the different types variable to string type.
55 | *
56 | * @tparam T variable which will convert.
57 | * @return String type value of T type variable.
58 | */
59 | template
60 | inline std::string tostr(const T& t)
61 | {
62 | std::ostringstream os;
63 | os << t;
64 | return os.str();
65 | }
66 |
67 |
68 |
69 |
70 |
71 | // ########################################### BLACKCORE DECLARATION STARTS ########################################### //
72 |
73 | /*! @brief Base class of the other classes.
74 | *
75 | * This class is core of the @b BlackLib Library.
76 | * It includes private functions like communicating with operating system and their limited versions for
77 | * using from derived class.
78 | */
79 | class BlackCore
80 | {
81 | private:
82 | errorCore *coreErrors; /*!< @brief is used to hold the errors of BlackCore class */
83 | std::string capeMgrName; /*!< @brief is used to hold the capemgr name */
84 | std::string ocpName; /*!< @brief is used to hold the ocp name */
85 | std::string slotsFilePath; /*!< @brief is used to hold the slots file path */
86 |
87 | /*! @brief Finds full name of capemgr directory.
88 | *
89 | * This function searches @b "/sys/devices/" directory,
90 | * to find directory which starts with @b "bone_capemgr."
91 | * @return True if successful, else false.
92 | * @sa BlackCore::searchDirectory()
93 | */
94 | bool findCapeMgrName();
95 |
96 | /*! @brief Finds full name of ocp directory.
97 | *
98 | * This function searches @b "/sys/devices/" directory,
99 | * to find directory which starts with @b "ocp."
100 | * @return True if successful, else false.
101 | * @sa BlackCore::searchDirectory()
102 | */
103 | bool findOcpName();
104 |
105 | /*! @brief Executes system call.
106 | *
107 | * This function executes system commands with using popen() function.
108 | * This example executes "ls" command with argument "la" and saves
109 | * output to returnValue variable. @n @n
110 | * string returnValue = executeCommand("ls -la");
111 | */
112 | std::string executeCommand(std::string command);
113 |
114 | /*! @brief Searches specified directory to find specified file/directory.
115 | *
116 | * @param[in] searchIn searching directory
117 | * @param[in] searchThis search file/directory
118 | * @return Full name of searching file/directory.
119 | */
120 | std::string searchDirectory(std::string searchIn, std::string searchThis);
121 |
122 | /*! @brief First declaration of this function.
123 | */
124 | virtual bool loadDeviceTree() = 0;
125 |
126 |
127 |
128 | protected:
129 |
130 | /*!
131 | * This enum is used for defining ADC, PWM and SPI device driver names.
132 | */
133 | enum ocpSearch { ADC_helper = 0, /*!< enumeration for @a adc device driver name for using at BlackCore::searchDirectoryOcp() function parameter*/
134 | PWM_P8_13 = 1, /*!< enumeration for @a P8_13 pwm device driver name */
135 | PWM_P8_19 = 2, /*!< enumeration for @a P8_19 pwm device driver name */
136 | PWM_P9_14 = 3, /*!< enumeration for @a P9_14 pwm device driver name */
137 | PWM_P9_16 = 4, /*!< enumeration for @a P9_16 pwm device driver name */
138 | PWM_P9_21 = 5, /*!< enumeration for @a P9_21 pwm device driver name */
139 | PWM_P9_22 = 6, /*!< enumeration for @a P9_22 pwm device driver name */
140 | PWM_P9_42 = 7, /*!< enumeration for @a P9_42 pwm device driver name */
141 | SPI0 = 8, /*!< enumeration for @a SPI0 spi device driver name */
142 | SPI1 = 9 /*!< enumeration for @a SPI1 spi device driver name */
143 | };
144 |
145 | /*! @brief Searches ocp directory to find specified file/directory.
146 | *
147 | * This function searches ocp directory only. It can be used from derived class.
148 | * @param[in] searchThis takes BlackCore::ocpSearch type variable(enum)
149 | * @return Full name of searching file/directory.
150 | */
151 | std::string searchDirectoryOcp(BlackCore::ocpSearch searchThis);
152 |
153 | /*! @brief Exports errorCore struct to derived class.
154 | *
155 | * @return errorCore struct pointer.
156 | */
157 | errorCore *getErrorsFromCore();
158 |
159 | /*! @brief Exports capemgr name to derived class.
160 | *
161 | * @return BlackCore::capeMgrName variable.
162 | */
163 | std::string getCapeMgrName();
164 |
165 | /*! @brief Exports ocp name to derived class.
166 | *
167 | * @return BlackCore::ocpName variable.
168 | */
169 | std::string getOcpName();
170 |
171 | /*! @brief Exports slots file path to derived class.
172 | *
173 | * @return BlackCore::slotsFilePath variable.
174 | */
175 | std::string getSlotsFilePath();
176 |
177 |
178 |
179 | public:
180 | /*! @brief Constructor of BlackCore class.
181 | *
182 | * This function initializes errorCore struct and runs these functions:
183 | * @li findCapeMgrName()
184 | * @li findOcpName()
185 | */
186 | BlackCore();
187 |
188 | /*! @brief Destructor of BlackCore class.
189 | *
190 | * This function deletes errorCore struct pointer.
191 | */
192 | virtual ~BlackCore();
193 |
194 | };
195 | // ############################################ BLACKCORE DECLARATION ENDS ############################################ //
196 |
197 |
198 | } /* namespace BlackLib */
199 |
200 | #endif /* BLACKCORE_H_ */
201 |
--------------------------------------------------------------------------------
/v2_0/BlackLib.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ####################################################################################
4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5 | # Copyright (C) 2013-2014 by Yigit YUCE #
6 | ####################################################################################
7 | # #
8 | # This file is part of BlackLib library. #
9 | # #
10 | # BlackLib library is free software: you can redistribute it and/or modify #
11 | # it under the terms of the GNU Lesser General Public License as published by #
12 | # the Free Software Foundation, either version 3 of the License, or #
13 | # (at your option) any later version. #
14 | # #
15 | # BlackLib library is distributed in the hope that it will be useful, #
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18 | # GNU Lesser General Public License for more details. #
19 | # #
20 | # You should have received a copy of the GNU Lesser General Public License #
21 | # along with this program. If not, see . #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ####################################################################################
27 |
28 | */
29 |
30 |
31 | #ifndef BLACKLIB_H_
32 | #define BLACKLIB_H_
33 |
34 | #include "BlackCore.h"
35 | #include "BlackADC.h"
36 | #include "BlackPWM.h"
37 | #include "BlackGPIO.h"
38 | #include "BlackUART.h"
39 | #include "BlackSPI.h"
40 | #include "BlackI2C.h"
41 |
42 |
43 | #endif /* BLACKLIB_H_ */
44 |
--------------------------------------------------------------------------------
/v2_0/LICENSE/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/v2_0/README.md:
--------------------------------------------------------------------------------
1 | BlackLib library is wrote for controlling Beaglebone Black's feature. It takes power from C++ language. It is created for reading analog input, generating pwm signal, using gpio pins, and communicating with other devices over uart, spi and i2c. In addition to them, it includes debugging feature. So you can check errors after call any function in the library.
2 |
3 |
4 | --------------------------------------------------------------------------------
5 | ## Debugging
6 |
7 | It always tracks member functions errors and records these errors to data structures. All end nodes which interact with end users, have overloaded fail() functions. So you can check all errors or specific error whichever you want.
8 |
9 |
10 | --------------------------------------------------------------------------------
11 | ## Class Hierarchy
12 |
13 | ### Library Core
14 |
15 | BlackLib includes BlackCore class for doing core process. End users can't access to it. Because it is abstract class and all member functions, except constructor and destructor, are private or protected.
16 |
17 | ### Sub Level Cores
18 |
19 | BlackLib includes sub level cores for GPIO, ADC and PWM features. Preparing stages are realized in here, at sub level cores. Therefore, if you don't like end nodes or you don't want to use these, you can derive your own class(es), from these sub level cores. But end nodes designed for taking care of your all need.
20 |
21 | ### End Node Classes
22 |
23 | End node classes are designed for interacting with end user. You can read, set or control Beaglebone Black's ADC, GPIO or PWM features or you can communicate with other devices with using UART, SPI or I2C protocol, from these classes. These classes include primary functions like read or set properties of Beaglebone Black's features and include additional functions like ADC parser, gpio pin toggle etc. to make easier your life.
24 |
25 |
26 | --------------------------------------------------------------------------------
27 | ## Definitions
28 |
29 | BlackLib includes enum type definitions for your and Beaglebone Black's safety. GPIO, ADC, PWM, UART, SPI, I2C names; PWM, GPIO values; GPIO directions and a lot more features defined with enums. It means you can't call some member functions without use this enums. These enums avoid user errors like write 345 to gpio export file instead of 34.
30 |
31 |
32 | --------------------------------------------------------------------------------
33 | ## Contact
34 |
35 | For any comment or suggestion please contact the creator of BlackLib Library at contact[at]blacklib.yigityuce.com
36 |
37 |
38 | --------------------------------------------------------------------------------
39 | http://blacklib.yigityuce.com
40 |
--------------------------------------------------------------------------------
/v2_0/ReleaseNotes:
--------------------------------------------------------------------------------
1 |
2 |
3 | RELEASE NOTES FOR BLACKLIB v2.0
4 |
5 |
6 | New Features
7 |
8 | # Communication Protocols:
9 |
10 | * Add new communication protocol classes. These are uart, spi and i2c.
11 | * Add install script for using spi.
12 |
13 | # Documantation:
14 |
15 | * Add code examples to almost all functions.
16 | * Add warning and information parts.
17 | * Add example project tree and including information of every class.
18 | * No more User-Manual support.
19 |
20 | # Performance:
21 |
22 | * Add workingMode(SecureMode, FastMode) enumaration.
23 | * Add secure and fast working modes to BlackGPIO.
24 |
25 | # Usability:
26 |
27 | * Add namespace which named "BlackLib".
28 | * Add default error string which occured when file openning, to BlackDef.h (FILE_COULD_NOT_OPEN_STRING)
29 | * Add default error integer value which occured when file openning, to BlackDef.h (FILE_COULD_NOT_OPEN_INT)
30 | * Add default error float value which occured when file openning, to BlackDef.h (FILE_COULD_NOT_OPEN_FLOAT)
31 | * Add default error string which occured when checking gpio ready state, to BlackDef.h (GPIO_PIN_NOT_READY_STRING)
32 | * Add default error integer which occured when checking gpio ready state, to BlackDef.h (GPIO_PIN_NOT_READY_INT)
33 | * Add default error string which occured when searching pwm driver name, to BlackDef.h (PWM_TEST_NAME_NOT_FOUND)
34 | * Add timeType(picosecond, nanosecond, microsecond, milisecond, second) enumaration.
35 | * Add BlackCoreGPIO::getValueFilePath() function.
36 | * Add BlackGPIO::setWorkingMode() function.
37 | * Add BlackGPIO::getWorkingMode() function.
38 | * Add BlackGPIO::getNumericValue() function.
39 | * Add BlackCorePWM::getPeriodFilePath() function.
40 | * Add BlackCorePWM::getDutyFilePath() function.
41 | * Add BlackCorePWM::getRunFilePath() function.
42 | * Add BlackCorePWM::getPolarityFilePath() function.
43 | * Add operator(>>) overloads to BlackGPIO.
44 | * Add operator(>>) overloads to BlackADC.
45 |
46 |
47 |
48 |
49 |
50 | Updates
51 |
52 | # Name Changes:
53 |
54 | * Change "adc_name" enumaration name to "adcName".
55 | * Change "gpio_type" enumaration name to "direction".
56 | * Change "gpio_name" enumaration name to "gpioName".
57 | * Change "gpio_value" enumaration name to "digitalValue".
58 | * Change "pwm_run_value" enumaration name to "runValue".
59 | * Change "pwm_polarity" enumaration name to "polarityType".
60 | * Change BlackADC::getParsedValue() function name to BlackADC::getConvertedValue().
61 | * Change BlackGPIO::getType() function name to BlackGPIO::getDirection().
62 | * Merge "pwm_bus_name" and "pwm_pin_name" enumarations and change name to "pwmName".
63 |
64 | # Usability Improvements:
65 |
66 | * Update included files.
67 | * Insert "SPI0" and "SPI1" enumarators to BlackCore::ocpSearch for searching spi device number at the ocp directory.
68 | * Update BlackCore::searchDirectoryOcp() function for searching spi device driver.
69 | * Delete debug messages from BlackADC and BlackGPIO classes.
70 | * Add working mode support to BlackGPIO::getValue() function.
71 | * Add working mode support to BlackGPIO::setValue() function.
72 | * Add time type support to BlackPWM::setPeriodTime() function.
73 | * Add time type support to BlackPWM::setSpaceRatioTime() function.
74 | * Add time type support to BlackPWM::setLoadRatioTime() function.
75 | * Add "bothDirection" enumarator to "direction" (old name is "gpio_type") enumaration. (Note: If this enumarator is
76 | used at BlackGPIO constructor parameter, it assumes your pin direction is input.)
77 |
78 | # Performance Improvements:
79 |
80 | * Delete BlackCore::setSlotsFilePath() function and merge into the constructor.
81 | * Optimize BlackADC::getValue() function.
82 | * Optimize BlackADC::getNumericValue() function.
83 | * Optimize BlackCoreGPIO::setDirection() function.
84 | * Optimize BLACKPWM::setPeriodTime() function.
85 | * Optimize BLACKPWM::setSpaceRatioTime() function.
86 | * Optimize BLACKPWM::setLoadRatioTime() function.
87 | * Optimize BLACKPWM::setDutyPercent() function.
88 | * Optimize BLACKPWM::setPolarity() function.
89 | * Optimize BLACKPWM::setRunState() function.
90 | * Optimize BLACKPWM::tooglePolarity() function.
91 | * Optimize BLACKPWM::toggleRunState() function.
92 | * Optimize BLACKPWM::getNumericPeriodValue() and delete "strtoimax()" helper function from this function.
93 | * Optimize BLACKPWM::getNumericDutyValue() and delete "strtoimax()" helper function from this function.
94 | * Change initialization of error structure at BlackCore constructor.
95 | * Change initialization of error structure at BlackCoreADC constructor.
96 | * Change initialization of error structure at BlackCoreGPIO constructor.
97 | * Change initialization of error structure at BlackCorePWM constructor.
98 | * Change initialization of error structure at BlackADC constructor.
99 | * Change initialization of error structure at BlackGPIO constructor.
100 | * Change initialization of error structure at BlackPWM constructor.
101 | * Add error structure pointer delete to BlackCore destructor for preventing memory leak.
102 | * Add error structure pointer delete to BlackCoreADC destructor for preventing memory leak.
103 | * Add error structure pointer delete to BlackCoreGPIO destructor for preventing memory leak.
104 | * Add error structure pointer delete to BlackCorePWM destructor for preventing memory leak.
105 | * Add error structure pointer delete to BlackADC destructor for preventing memory leak.
106 | * Add error structure pointer delete to BlackGPIO destructor for preventing memory leak.
107 | * Add error structure pointer delete to BlackPWM destructor for preventing memory leak.
108 | * Change BLACKPWM::getNumericPeriodValue() function to inline.
109 | * Change BLACKPWM::getNumericDutyValue() function to inline.
110 | * Change toStr() function to inline.
111 |
112 |
113 | # Design Updates:
114 |
115 | * Clean everything about initialization process from BlackGPIO class like "isInitializeBefore" flag, "initializeErr"
116 | enumarator, initialize() and triggerInitialize() function.
117 | * Clean everything about initialization process from BlackPWM class like "isInitializeBefore" flag, "initializeErr"
118 | enumarator, initialize() and triggerInitialize() function.
119 | * Delete BlackCorePWM::getPwmName() function.
120 | * Delete BlackCorePWM::parsePwmName() function.
121 | * Delete BlackCorePWM::getPwmName() function.
122 | * Change "bool BlackCorePWM::findPwmTestName()" function to "std::string BlackCorePWM::findPwmTestName(pwmName)".
123 | * Change "BlackCorePWM::setPeriodTime(uint32_t)" function to "BlackCorePWM::setPeriodTime(uint64_t, timeType)".
124 | * Change "BlackCorePWM::setSpaceRatioTime(uint32_t)" function to "BlackCorePWM::setSpaceRatioTime(uint64_t, timeType)".
125 | * Change "BlackCorePWM::setLoadRatioTime(uint32_t)" function to "BlackCorePWM::setLoadRatioTime(uint64_t, timeType)".
126 | * Move "pwmPinName" variable from BlackPWM to BlackCorePWM.
127 |
128 |
129 |
--------------------------------------------------------------------------------
/v2_0/SPI_SETUP/BLACKLIB-SPI0-00A0.dts:
--------------------------------------------------------------------------------
1 | /*
2 | * ####################################################################################
3 | * # Custom device tree file to create virtual SPI0 cape in BlackLib Library. #
4 | * # Copyright (C) 2014 by Yigit YUCE #
5 | * ####################################################################################
6 | * # #
7 | * # This file is part of BlackLib library. #
8 | * # #
9 | * # BlackLib library is free software: you can redistribute it and/or modify #
10 | * # it under the terms of the GNU Lesser General Public License as published by #
11 | * # the Free Software Foundation, either version 3 of the License, or #
12 | * # (at your option) any later version. #
13 | * # #
14 | * # BlackLib library is distributed in the hope that it will be useful, #
15 | * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 | * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 | * # GNU Lesser General Public License for more details. #
18 | * # #
19 | * # You should have received a copy of the GNU Lesser General Public License #
20 | * # along with this program. If not, see . #
21 | * # #
22 | * # For any comment or suggestion please contact the creator of BlackLib Library #
23 | * # at ygtyce@gmail.com #
24 | * # #
25 | * ####################################################################################
26 | */
27 |
28 | /dts-v1/;
29 | /plugin/;
30 |
31 | / {
32 | compatible = "ti,beaglebone", "ti,beaglebone-black";
33 |
34 | part-number = "BLACKLIB-SPI0";
35 | version = "00A0";
36 |
37 | exclusive-use =
38 | "P9.17", /* spi0_cs0 */
39 | "P9.18", /* spi0_d1 */
40 | "P9.21", /* spi0_d0 */
41 | "P9.22", /* spi0_sclk */
42 | "spi0"; /* the hardware ip uses */
43 |
44 | fragment@0 {
45 | target = <&am33xx_pinmux>;
46 | __overlay__ {
47 | bb_spi0_pins: pinmux_bb_spi0_pins {
48 | pinctrl-single,pins = <
49 | 0x150 0x30 /* spi0_sclk.spi0_sclk, INPUT_PULLUP | MODE0 */
50 | 0x154 0x30 /* spi0_d0.spi0_d0, INPUT_PULLUP | MODE0 */
51 | 0x158 0x10 /* spi0_d1.spi0_d1, OUTPUT_PULLUP | MODE0 */
52 | 0x15c 0x10 /* spi0_cs0.spi0_cs0, OUTPUT_PULLUP | MODE0 */
53 | >;
54 | };
55 | };
56 | };
57 |
58 | fragment@1 {
59 | target = <&spi0>;
60 | __overlay__ {
61 | #address-cells = <1>;
62 | #size-cells = <0>;
63 |
64 | status = "okay";
65 | pinctrl-names = "default";
66 | pinctrl-0 = <&bb_spi0_pins>;
67 |
68 | spidev@0{
69 | compatible = "spidev";
70 | reg = <0>;
71 | spi-max-frequency = <24000000>;
72 | };
73 | spidev@1{
74 | compatible = "spidev";
75 | reg = <1>;
76 | spi-max-frequency = <24000000>;
77 | };
78 | };
79 | };
80 | };
81 |
--------------------------------------------------------------------------------
/v2_0/SPI_SETUP/BLACKLIB-SPI1-00A0.dts:
--------------------------------------------------------------------------------
1 | /*
2 | * ####################################################################################
3 | * # Custom device tree file to create virtual SPI0 cape in BlackLib Library. #
4 | * # Copyright (C) 2014 by Yigit YUCE #
5 | * ####################################################################################
6 | * # #
7 | * # This file is part of BlackLib library. #
8 | * # #
9 | * # BlackLib library is free software: you can redistribute it and/or modify #
10 | * # it under the terms of the GNU Lesser General Public License as published by #
11 | * # the Free Software Foundation, either version 3 of the License, or #
12 | * # (at your option) any later version. #
13 | * # #
14 | * # BlackLib library is distributed in the hope that it will be useful, #
15 | * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 | * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 | * # GNU Lesser General Public License for more details. #
18 | * # #
19 | * # You should have received a copy of the GNU Lesser General Public License #
20 | * # along with this program. If not, see . #
21 | * # #
22 | * # For any comment or suggestion please contact the creator of BlackLib Library #
23 | * # at ygtyce@gmail.com #
24 | * # #
25 | * ####################################################################################
26 | */
27 |
28 | /dts-v1/;
29 | /plugin/;
30 |
31 | / {
32 | compatible = "ti,beaglebone", "ti,beaglebone-black";
33 |
34 | part-number = "BLACKLIB-SPI1";
35 | version = "00A0";
36 |
37 | exclusive-use =
38 | "P9.31", /* spi1_sclk */
39 | "P9.29", /* spi1_d0 */
40 | "P9.30", /* spi1_d1 */
41 | "P9.28", /* spi1_cs0 */
42 | // "P9.42", /* spi1_cs1 */
43 | "spi1"; /* the hardware ip uses */
44 |
45 | fragment@0 {
46 | target = <&am33xx_pinmux>;
47 | __overlay__ {
48 | bb_spi1_pins: pinmux_bb_spi1_pins {
49 | pinctrl-single,pins = <
50 | 0x190 0x33 /* mcasp0_aclkx.spi1_sclk, INPUT_PULLUP | MODE3 */
51 | 0x194 0x33 /* mcasp0_fsx.spi1_d0, INPUT_PULLUP | MODE3 */
52 | 0x198 0x13 /* mcasp0_axr0.spi1_d1, OUTPUT_PULLUP | MODE3 */
53 | 0x19c 0x13 /* mcasp0_ahclkr.spi1_cs0, OUTPUT_PULLUP | MODE3 */
54 | // 0x164 0x12 /* eCAP0_in_PWM0_out.spi1_cs1 OUTPUT_PULLUP | MODE2 */
55 | >;
56 | };
57 | };
58 | };
59 |
60 | fragment@1 {
61 | target = <&spi1>;
62 | __overlay__ {
63 | #address-cells = <1>;
64 | #size-cells = <0>;
65 |
66 | status = "okay";
67 | pinctrl-names = "default";
68 | pinctrl-0 = <&bb_spi1_pins>;
69 |
70 | spidev@0{
71 | compatible = "spidev";
72 | reg = <0>;
73 | spi-max-frequency = <24000000>;
74 | };
75 | spidev@1{
76 | compatible = "spidev";
77 | reg = <1>;
78 | spi-max-frequency = <24000000>;
79 | };
80 | };
81 | };
82 | };
83 |
--------------------------------------------------------------------------------
/v2_0/SPI_SETUP/readme.md:
--------------------------------------------------------------------------------
1 | If you want to use spi, you must use custom device tree overlays.
2 | For this reason i wrote setup scripts and custom device tree overlays.
3 | You must run one of these scripts for using spi feature of Beaglebone
4 | Black. You can do this with two ways.
5 |
6 | ### FROM HOST PC
7 |
8 | - If you are doing these steps from your host pc, you must run
9 | "setup_from_host" script. Before run this, you must give executable
10 | permission.
11 |
12 | - You can do this with this command: "chmod +x setup_from_host"
13 |
14 | - "BLACKLIB-SPI0-00A0.dts", "BLACKLIB-SPI1-00A0.dts" and "setup_from_host" files
15 | must be located in this directory.
16 |
17 | - After do that you must run the script with this command: "./setup_from_host"
18 |
19 | - When you run the script, it will ask you Beaglebone Black's root user's
20 | password two times. This is required for executing "scp" and "ssh" command.
21 |
22 | - That's all.
23 |
24 |
25 |
26 | ### INSIDE FROM BEAGLEBONE BLACK
27 |
28 | - If you are doing these steps from your BBB, you must connect to BBB and
29 | change your current directory to script's directory with "cd" command.
30 |
31 | - "BLACKLIB-SPI0-00A0.dts", "BLACKLIB-SPI1-00A0.dts" and "setup_from_BBB" files
32 | must be located in this directory.
33 |
34 | - Before run this script, you must give executable permission. You can do this
35 | with this command: "chmod +x setup_from_BBB"
36 |
37 | - After do that you must run the script with this command: "./setup_from_BBB"
38 |
39 | - That's all.
40 |
41 |
--------------------------------------------------------------------------------
/v2_0/SPI_SETUP/setup_from_BBB:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | dtc -O dtb -o BLACKLIB-SPI0-00A0.dtbo -b 0 -@ BLACKLIB-SPI0-00A0.dts
4 |
5 | dtc -O dtb -o BLACKLIB-SPI1-00A0.dtbo -b 0 -@ BLACKLIB-SPI1-00A0.dts
6 |
7 | cp -r BLACKLIB-SPI0-00A0.dtbo BLACKLIB-SPI1-00A0.dtbo /lib/firmware
8 |
9 | rm -rf BLACKLIB-SPI*
10 |
--------------------------------------------------------------------------------
/v2_0/SPI_SETUP/setup_from_host:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | scp BLACKLIB-SPI0-00A0.dts BLACKLIB-SPI1-00A0.dts root@192.168.7.2:/tmp
4 |
5 | ssh root@192.168.7.2 '
6 | cd /tmp
7 |
8 | dtc -O dtb -o BLACKLIB-SPI0-00A0.dtbo -b 0 -@ BLACKLIB-SPI0-00A0.dts
9 |
10 | dtc -O dtb -o BLACKLIB-SPI1-00A0.dtbo -b 0 -@ BLACKLIB-SPI1-00A0.dts
11 |
12 | cp -r BLACKLIB-SPI0-00A0.dtbo BLACKLIB-SPI1-00A0.dtbo /lib/firmware
13 |
14 | rm -rf BLACKLIB-SPI*
15 | '
16 |
--------------------------------------------------------------------------------
/v2_0/exampleAndTiming.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ####################################################################################
4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5 | # Copyright (C) 2013-2014 by Yigit YUCE #
6 | ####################################################################################
7 | # #
8 | # This file is part of BlackLib library. #
9 | # #
10 | # BlackLib library is free software: you can redistribute it and/or modify #
11 | # it under the terms of the GNU Lesser General Public License as published by #
12 | # the Free Software Foundation, either version 3 of the License, or #
13 | # (at your option) any later version. #
14 | # #
15 | # BlackLib library is distributed in the hope that it will be useful, #
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18 | # GNU Lesser General Public License for more details. #
19 | # #
20 | # You should have received a copy of the GNU Lesser General Public License #
21 | # along with this program. If not, see . #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ####################################################################################
27 |
28 | */
29 |
30 |
31 | #include "BlackLib.h"
32 |
33 | #include "exampleAndTiming/exampleAndTiming_GPIO.h"
34 | #include "exampleAndTiming/exampleAndTiming_ADC.h"
35 | #include "exampleAndTiming/exampleAndTiming_PWM.h"
36 | #include "exampleAndTiming/exampleAndTiming_SPI.h"
37 | #include "exampleAndTiming/exampleAndTiming_UART.h"
38 | #include "exampleAndTiming/exampleAndTiming_I2C.h"
39 |
40 |
41 | int main()
42 | {
43 | exampleAndTiming_GPIO();
44 | exampleAndTiming_ADC();
45 | exampleAndTiming_PWM();
46 | exampleAndTiming_SPI();
47 | exampleAndTiming_UART();
48 | exampleAndTiming_I2C();
49 |
50 | return 0;
51 | }
52 |
--------------------------------------------------------------------------------
/v2_0/exampleAndTiming/Timing.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ####################################################################################
4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5 | # Copyright (C) 2013-2014 by Yigit YUCE #
6 | ####################################################################################
7 | # #
8 | # This file is part of BlackLib library. #
9 | # #
10 | # BlackLib library is free software: you can redistribute it and/or modify #
11 | # it under the terms of the GNU Lesser General Public License as published by #
12 | # the Free Software Foundation, either version 3 of the License, or #
13 | # (at your option) any later version. #
14 | # #
15 | # BlackLib library is distributed in the hope that it will be useful, #
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18 | # GNU Lesser General Public License for more details. #
19 | # #
20 | # You should have received a copy of the GNU Lesser General Public License #
21 | # along with this program. If not, see . #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ####################################################################################
27 |
28 | */
29 |
30 | #include "Timing.h"
31 |
32 | void Timing::startMeasure(std::string ID)
33 | {
34 | timeval startTm;
35 | gettimeofday(&startTm,NULL);
36 | this->timeMap[ID] = (long int)startTm.tv_usec;
37 | }
38 |
39 | void Timing::endMeasure(std::string ID)
40 | {
41 | timeval stopTm;
42 | gettimeofday(&stopTm,NULL);
43 | this->timeMap[ID] = (long int)stopTm.tv_usec - this->timeMap[ID];
44 | }
45 |
46 | elapsedTime Timing::getMeasure(std::string ID)
47 | {
48 | long int elapsed = this->timeMap[ID];
49 | elapsedTime elapsedStruct;
50 |
51 |
52 | if( elapsed < 1000 ) // 0-999 us
53 | {
54 | elapsedStruct.microSecond = elapsed;
55 | elapsedStruct.miliSecond = 0;
56 | elapsedStruct.second = 0;
57 | }
58 | else
59 | if( elapsed < 1000*1000 ) // 0.999 ms - 999 ms
60 | {
61 | elapsedStruct.microSecond = (elapsed % 1000);
62 | elapsedStruct.miliSecond = (elapsed - (elapsed % 1000)) / 1000;
63 | elapsedStruct.second = 0;
64 | }
65 | else // 0.999 sec - infinite sec
66 | {
67 | elapsedStruct.microSecond = (elapsed % 1000);
68 | elapsedStruct.miliSecond = (elapsed - (elapsed % 1000)) / 1000;
69 | elapsedStruct.second = (elapsed - (elapsed % 1000000)) / 1000000;
70 | }
71 |
72 | return elapsedStruct;
73 | }
74 |
75 | std::string Timing::getAllMeasureTable()
76 | {
77 | unsigned int maxStringSize = 5;
78 | std::string table;
79 |
80 | std::map::iterator iter = this->timeMap.begin();
81 | for( ; iter != this->timeMap.end() ; ++iter )
82 | {
83 | if( (*iter).first.size() > maxStringSize )
84 | {
85 | maxStringSize = (*iter).first.size();
86 | }
87 | }
88 |
89 | std::string lineString( maxStringSize+25 , '-');
90 | table += lineString;
91 | table += "\n| ";
92 | table += ( (maxStringSize>5) ? std::string(maxStringSize-5, ' ') + std::string("LABEL") : std::string("LABEL") );
93 | table += " | SEC | mSEC | uSEC |\n";
94 | table += lineString;
95 |
96 | iter = this->timeMap.begin();
97 | for( ; iter != this->timeMap.end() ; ++iter )
98 | {
99 | std::string id = (*iter).first;
100 | elapsedTime et = this->getMeasure(id);
101 | std::string et_usec = this->tostr(et.microSecond);
102 | std::string et_msec = this->tostr(et.miliSecond);
103 | std::string et_sec = this->tostr(et.second);
104 | table += "\n| ";
105 | table += ( (id.size() < maxStringSize) ? std::string(maxStringSize-id.size(), ' ') + id : id );
106 | table += " | ";
107 | table += ( (et_sec.size() < 4) ? std::string(4-et_sec.size(), ' ') + et_sec : et_sec );
108 | table += " | ";
109 | table += ( (et_msec.size() < 4) ? std::string(4-et_msec.size(), ' ') + et_msec : et_msec );
110 | table += " | ";
111 | table += ( (et_usec.size() < 4) ? std::string(4-et_usec.size(), ' ') + et_usec : et_usec );
112 | table += " |\n";
113 | table += lineString;
114 | }
115 |
116 | table += "\n";
117 |
118 | return table;
119 |
120 | }
121 |
122 | bool Timing::saveToFile(std::string filename)
123 | {
124 | std::ofstream out;
125 | out.open(filename.c_str(), std::ios::out );
126 |
127 | if(out.fail())
128 | {
129 | out.close();
130 | return false;
131 | }
132 | else
133 | {
134 | std::string writeThis = "\nFilename: ";
135 | writeThis += filename;
136 | writeThis += "\n\n";
137 | writeThis += this->getAllMeasureTable();
138 |
139 | out << writeThis;
140 | out.close();
141 | return true;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/v2_0/exampleAndTiming/Timing.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ####################################################################################
4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5 | # Copyright (C) 2013-2014 by Yigit YUCE #
6 | ####################################################################################
7 | # #
8 | # This file is part of BlackLib library. #
9 | # #
10 | # BlackLib library is free software: you can redistribute it and/or modify #
11 | # it under the terms of the GNU Lesser General Public License as published by #
12 | # the Free Software Foundation, either version 3 of the License, or #
13 | # (at your option) any later version. #
14 | # #
15 | # BlackLib library is distributed in the hope that it will be useful, #
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18 | # GNU Lesser General Public License for more details. #
19 | # #
20 | # You should have received a copy of the GNU Lesser General Public License #
21 | # along with this program. If not, see . #
22 | # #
23 | # For any comment or suggestion please contact the creator of BlackLib Library #
24 | # at ygtyce@gmail.com #
25 | # #
26 | ####################################################################################
27 |
28 | */
29 |
30 |
31 | #ifndef TIMING_H_
32 | #define TIMING_H_
33 |
34 | #include
35 | #include
36 | #include