├── 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 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | struct elapsedTime 43 | { 44 | elapsedTime() 45 | { 46 | microSecond = 0; 47 | miliSecond = 0; 48 | second = 0; 49 | } 50 | 51 | unsigned int microSecond; 52 | unsigned int miliSecond; 53 | unsigned int second; 54 | }; 55 | 56 | 57 | 58 | class Timing 59 | { 60 | private: 61 | std::map timeMap; 62 | template 63 | std::string tostr(const T& t) 64 | { 65 | std::ostringstream os; 66 | os << t; 67 | return os.str(); 68 | } 69 | 70 | public: 71 | Timing(){}; 72 | virtual ~Timing(){}; 73 | 74 | void startMeasure(std::string ID); 75 | void endMeasure(std::string ID); 76 | elapsedTime getMeasure(std::string ID); 77 | 78 | std::string getAllMeasureTable(); 79 | 80 | bool saveToFile(std::string filename); 81 | }; 82 | 83 | #endif /* TIMING_H_ */ 84 | 85 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/exampleAndTiming_ADC.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 | 32 | 33 | 34 | #ifndef EXAMPLEANDTIMING_ADC_H_ 35 | #define EXAMPLEANDTIMING_ADC_H_ 36 | 37 | 38 | #include "../BlackADC.h" 39 | #include 40 | #include 41 | #include "Timing.h" 42 | 43 | 44 | 45 | 46 | 47 | 48 | void exampleAndTiming_ADC() 49 | { 50 | Timing adcTiming; 51 | 52 | adcTiming.startMeasure("1. Constructor"); 53 | BlackLib::BlackADC analog(BlackLib::AIN4 ); // initialization analog input 54 | adcTiming.endMeasure("1. Constructor"); 55 | 56 | 57 | std::string valueStr; 58 | int valueInt; 59 | float valueFloat; 60 | 61 | 62 | adcTiming.startMeasure("2. BlackADC::getValue()"); 63 | valueStr = analog.getValue(); 64 | adcTiming.endMeasure("2. BlackADC::getValue()"); 65 | 66 | 67 | usleep(1000); 68 | 69 | 70 | adcTiming.startMeasure("3. BlackADC::getNumericValue()"); 71 | valueInt = analog.getNumericValue(); 72 | adcTiming.endMeasure("3. BlackADC::getNumericValue()"); 73 | 74 | 75 | usleep(1000); 76 | 77 | 78 | adcTiming.startMeasure("4. BlackADC::getConvertedValue()"); 79 | valueFloat = analog.getConvertedValue( BlackLib::dap2 ); 80 | adcTiming.endMeasure("4. BlackADC::getConvertedValue()"); 81 | 82 | std::cout << "AIN_str: " << valueStr << std::endl; 83 | std::cout << "AIN_int: " << valueInt << std::endl; 84 | std::cout << "AIN_flt: " << valueFloat << std::endl; 85 | 86 | 87 | 88 | 89 | 90 | 91 | valueStr.clear(); 92 | valueInt = 0; 93 | valueFloat = 0.0; 94 | 95 | adcTiming.startMeasure("5. BlackADC::operator>>(std::string)"); 96 | analog >> valueStr; 97 | adcTiming.endMeasure("5. BlackADC::operator>>(std::string)"); 98 | 99 | 100 | usleep(1000); 101 | 102 | 103 | adcTiming.startMeasure("6. BlackADC::operator>>(int)"); 104 | analog >> valueInt; 105 | adcTiming.endMeasure("6. BlackADC::operator>>(int)"); 106 | 107 | 108 | usleep(1000); 109 | 110 | 111 | adcTiming.startMeasure("7. BlackADC::operator>>(float)"); 112 | analog >> valueFloat; 113 | adcTiming.endMeasure("7. BlackADC::operator>>(float)"); 114 | 115 | std::cout << "AIN_str_operator: " << valueStr << std::endl; 116 | std::cout << "AIN_int_operator: " << valueInt << std::endl; 117 | std::cout << "AIN_flt_operator: " << valueFloat << std::endl; 118 | 119 | 120 | std::cout << adcTiming.getAllMeasureTable(); 121 | adcTiming.saveToFile("BlackADC_timing_results.out"); 122 | 123 | } 124 | 125 | 126 | 127 | #endif /* EXAMPLEANDTIMING_ADC_H_ */ 128 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/exampleAndTiming_GPIO.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 | 32 | 33 | 34 | #ifndef EXAMPLEANDTIMING_GPIO_H_ 35 | #define EXAMPLEANDTIMING_GPIO_H_ 36 | 37 | 38 | 39 | 40 | #include "../BlackGPIO.h" 41 | #include 42 | #include 43 | #include "Timing.h" 44 | 45 | 46 | 47 | 48 | void exampleAndTiming_GPIO() 49 | { 50 | Timing gpioTiming; 51 | 52 | gpioTiming.startMeasure("1. Constructor"); 53 | BlackLib::BlackGPIO led1(BlackLib::GPIO_51,BlackLib::output, BlackLib::SecureMode); // initialization first output, secure mode 54 | gpioTiming.endMeasure("1. Constructor"); 55 | 56 | BlackLib::BlackGPIO led2(BlackLib::GPIO_22,BlackLib::output, BlackLib::FastMode); // initialization second output, fast mode 57 | BlackLib::BlackGPIO button1(BlackLib::GPIO_60,BlackLib::input); // initialization first input, secure mode 58 | BlackLib::BlackGPIO button2(BlackLib::GPIO_48,BlackLib::input, BlackLib::FastMode); // initialization second input, fast mode 59 | 60 | 61 | 62 | gpioTiming.startMeasure("2.1. (SecureMode) BlackGPIO::setValue()"); 63 | led1.setValue(BlackLib::high); // turn on the led1 64 | gpioTiming.endMeasure("2.1. (SecureMode) BlackGPIO::setValue()"); 65 | 66 | gpioTiming.startMeasure("2.2. (FastMode) BlackGPIO::setValue()"); 67 | led2.setValue(BlackLib::high); 68 | gpioTiming.endMeasure("2.2. (FastMode) BlackGPIO::setValue()"); 69 | 70 | 71 | 72 | 73 | std::string button1value; 74 | std::string button2value; 75 | std::string led1value; 76 | std::string led2value; 77 | 78 | 79 | gpioTiming.startMeasure("3.1. (SecureMode,InputType) BlackGPIO::getValue()"); 80 | button1value = button1.getValue(); 81 | gpioTiming.endMeasure("3.1. (SecureMode,InputType) BlackGPIO::getValue()"); 82 | 83 | gpioTiming.startMeasure("3.2. (FastMode,InputType) BlackGPIO::getValue()"); 84 | button2value = button2.getValue(); 85 | gpioTiming.endMeasure("3.2. (FastMode,InputType) BlackGPIO::getValue()"); 86 | 87 | 88 | 89 | gpioTiming.startMeasure("3.3. (SecureMode,OutputType) BlackGPIO::getValue()"); 90 | led1value = led1.getValue(); 91 | gpioTiming.endMeasure("3.3. (SecureMode,OutputType) BlackGPIO::getValue()"); 92 | 93 | gpioTiming.startMeasure("3.4. (FastMode,OutputType) BlackGPIO::getValue()"); 94 | led2value = led2.getValue(); 95 | gpioTiming.endMeasure("3.4. (FastMode,OutputType) BlackGPIO::getValue()"); 96 | 97 | sleep(1); 98 | 99 | 100 | 101 | 102 | gpioTiming.startMeasure("4.1. BlackGPIO::toggleValue() (SecureMode)"); 103 | led1.toggleValue(); 104 | gpioTiming.endMeasure("4.1. BlackGPIO::toggleValue() (SecureMode)"); 105 | 106 | gpioTiming.startMeasure("4.2. BlackGPIO::toggleValue() (FastMode)"); 107 | led2.toggleValue(); 108 | gpioTiming.endMeasure("4.2. BlackGPIO::toggleValue() (FastMode)"); 109 | 110 | sleep(1); 111 | 112 | 113 | 114 | 115 | 116 | std::string led1value_operator; 117 | int led1NumericValue_operator; 118 | 119 | gpioTiming.startMeasure("5.1. (SecureMode) BlackGPIO::operator>>(std::string)"); 120 | led1 >> led1value_operator; 121 | gpioTiming.endMeasure("5.1. (SecureMode) BlackGPIO::operator>>(std::string)"); 122 | 123 | gpioTiming.startMeasure("7.1. (SecureMode) BlackGPIO::operator<<()"); 124 | led1 << BlackLib::high; 125 | gpioTiming.endMeasure("7.1. (SecureMode) BlackGPIO::operator<<()"); 126 | 127 | gpioTiming.startMeasure("6.1. (SecureMode) BlackGPIO::operator>>(int)"); 128 | led1 >> led1NumericValue_operator; 129 | gpioTiming.endMeasure("6.1. (SecureMode) BlackGPIO::operator>>(int)"); 130 | 131 | 132 | 133 | 134 | 135 | std::string led2value_operator; 136 | int led2NumericValue_operator; 137 | 138 | gpioTiming.startMeasure("5.2. (FastMode) BlackGPIO::operator>>(std::string)"); 139 | led2 >> led2value_operator; 140 | gpioTiming.endMeasure("5.2. (FastMode) BlackGPIO::operator>>(std::string)"); 141 | 142 | gpioTiming.startMeasure("7.2. (FastMode) BlackGPIO::operator<<()"); 143 | led2 << BlackLib::high; 144 | gpioTiming.endMeasure("7.2. (FastMode) BlackGPIO::operator<<()"); 145 | 146 | gpioTiming.startMeasure("6.2. (FastMode) BlackGPIO::operator>>(int)"); 147 | led2 >> led2NumericValue_operator; 148 | gpioTiming.endMeasure("6.2. (FastMode) BlackGPIO::operator>>(int)"); 149 | 150 | sleep(1); 151 | 152 | 153 | 154 | 155 | std::cout << gpioTiming.getAllMeasureTable(); 156 | gpioTiming.saveToFile("BlackGPIO_timing_results.out"); 157 | } 158 | 159 | 160 | 161 | #endif /* EXAMPLEANDTIMING_GPIO_H_ */ 162 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/exampleAndTiming_PWM.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 | 32 | 33 | #ifndef EXAMPLEANDTIMING_PWM_H_ 34 | #define EXAMPLEANDTIMING_PWM_H_ 35 | 36 | 37 | 38 | 39 | #include "../BlackPWM.h" 40 | #include 41 | #include 42 | #include "Timing.h" 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | void exampleAndTiming_PWM() 54 | { 55 | Timing pwmTiming; 56 | 57 | float percent = 5.0; 58 | std::string currentDuty; 59 | std::string currentPeriod; 60 | std::string currentPercentValue; 61 | std::string currentPolarity; 62 | std::string currentRun; 63 | 64 | int64_t currentDuty_numeric; 65 | int64_t currentPeriod_numeric; 66 | float currentPercentValue_numeric; 67 | 68 | 69 | 70 | 71 | 72 | pwmTiming.startMeasure("1. Constructor"); 73 | BlackLib::BlackPWM pwmLed(BlackLib::EHRPWM2A); 74 | pwmTiming.endMeasure("1. Constructor"); 75 | 76 | 77 | // if new period value is less than the current duty value, the new period value setting 78 | // operation couldn't execute. So firstly duty value is set to zero for safe steps. 79 | pwmLed.setDutyPercent(0.0); 80 | pwmLed.setPeriodTime(100000); 81 | sleep(1); 82 | 83 | 84 | 85 | 86 | pwmTiming.startMeasure("2. BlackPWM::setSpaceRatioTime()"); 87 | pwmLed.setSpaceRatioTime(67, BlackLib::microsecond); 88 | pwmTiming.endMeasure("2. BlackPWM::setSpaceRatioTime()"); 89 | 90 | std::cout << "DUTY after setting space time: \t\t" << pwmLed.getDutyValue() << std::endl; 91 | 92 | 93 | 94 | 95 | 96 | pwmTiming.startMeasure("3. BlackPWM::setPeriodTime()"); 97 | pwmLed.setPeriodTime(300000000, BlackLib::picosecond); 98 | pwmTiming.endMeasure("3. BlackPWM::setPeriodTime()"); 99 | 100 | std::cout << "PERIOD after setting period time: \t" << pwmLed.getPeriodValue() << std::endl; 101 | 102 | 103 | 104 | 105 | 106 | pwmTiming.startMeasure("4. BlackPWM::setLoadRatioTime()"); 107 | pwmLed.setLoadRatioTime(15000, BlackLib::nanosecond); 108 | pwmTiming.endMeasure("4. BlackPWM::setLoadRatioTime()"); 109 | 110 | std::cout << "DUTY after setting load time: \t\t" << pwmLed.getDutyValue() << std::endl; 111 | 112 | 113 | 114 | 115 | 116 | pwmTiming.startMeasure("5. BlackPWM::setDutyPercent()"); 117 | pwmLed.setDutyPercent(11.75); 118 | pwmTiming.endMeasure("5. BlackPWM::setDutyPercent()"); 119 | 120 | std::cout << "DUTY after setting percent: \t\t" << pwmLed.getDutyValue() << std::endl; 121 | 122 | 123 | 124 | 125 | 126 | pwmTiming.startMeasure("6_1. BlackPWM::getDutyValue()"); 127 | currentDuty = pwmLed.getDutyValue(); 128 | pwmTiming.endMeasure("6_1. BlackPWM::getDutyValue()"); 129 | 130 | pwmTiming.startMeasure("6_2. BlackPWM::getNumericDutyValue()"); 131 | currentDuty_numeric = pwmLed.getNumericDutyValue(); 132 | pwmTiming.endMeasure("6_2. BlackPWM::getNumericDutyValue()"); 133 | 134 | 135 | 136 | pwmTiming.startMeasure("7_1. BlackPWM::getPeriodValue()"); 137 | currentPeriod = pwmLed.getPeriodValue(); 138 | pwmTiming.endMeasure("7_1. BlackPWM::getPeriodValue()"); 139 | 140 | pwmTiming.startMeasure("7_2. BlackPWM::getNumericPeriodValue()"); 141 | currentPeriod_numeric = pwmLed.getNumericPeriodValue(); 142 | pwmTiming.endMeasure("7_2. BlackPWM::getNumericPeriodValue()"); 143 | 144 | 145 | 146 | 147 | pwmTiming.startMeasure("8_1. BlackPWM::getValue()"); 148 | currentPercentValue = pwmLed.getValue(); 149 | pwmTiming.endMeasure("8_1. BlackPWM::getValue()"); 150 | 151 | pwmTiming.startMeasure("8_2. BlackPWM::getNumericValue()"); 152 | currentPercentValue_numeric = pwmLed.getNumericValue(); 153 | pwmTiming.endMeasure("8_2. BlackPWM::getNumericValue()"); 154 | 155 | 156 | 157 | 158 | pwmTiming.startMeasure("9_1. BlackPWM::getPolarityValue()"); 159 | currentPolarity = pwmLed.getPolarityValue(); 160 | pwmTiming.endMeasure("9_1. BlackPWM::getPolarityValue()"); 161 | 162 | pwmTiming.startMeasure("9_2. BlackPWM::getRunValue()"); 163 | currentRun = pwmLed.getRunValue(); 164 | pwmTiming.endMeasure("9_2. BlackPWM::getRunValue()"); 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | std::cout << "Duty_str: \t" << currentDuty << std::endl; 178 | std::cout << "Duty_num: \t" << currentDuty_numeric << std::endl; 179 | std::cout << "Period_str: \t" << currentPeriod << std::endl; 180 | std::cout << "Period_num: \t" << currentPeriod_numeric << std::endl; 181 | std::cout << "Percent_str: \t" << currentPercentValue << std::endl; 182 | std::cout << "Percent_num: \t" << currentPercentValue_numeric << std::endl; 183 | std::cout << "Polarity_str: \t" << currentPolarity << std::endl; 184 | std::cout << "Run_str: \t" << currentRun << std::endl; 185 | 186 | 187 | 188 | while( ! pwmLed.fail(BlackLib::BlackPWM::outOfRangeErr) ) 189 | { 190 | pwmLed.setDutyPercent(percent); 191 | 192 | std::cout << std::endl << "New percent value: " << percent << std::endl; 193 | 194 | percent += 25.0; 195 | usleep(500000); 196 | } 197 | 198 | std::cout << std::endl << "Percent value is out of range." << std::endl; 199 | 200 | 201 | std::cout << pwmTiming.getAllMeasureTable(); 202 | pwmTiming.saveToFile("BlackPWM_timing_results.out"); 203 | 204 | } 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | #endif /* EXAMPLEANDTIMING_PWM_H_ */ 213 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/exampleAndTiming_SPI.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 | 32 | 33 | 34 | #ifndef EXAMPLEANDTIMING_SPI_H_ 35 | #define EXAMPLEANDTIMING_SPI_H_ 36 | 37 | 38 | #include "../BlackSPI.h" 39 | #include 40 | #include 41 | #include 42 | #include "Timing.h" 43 | 44 | 45 | 46 | 47 | void exampleAndTiming_SPI() 48 | { 49 | 50 | Timing spiTiming; 51 | 52 | /* 53 | * This part of the example code is about BlackSPI class, write/read buffer and write/read 54 | * byte initialization. 55 | * 56 | * BlackSPI class also can be use like below: 57 | * 1) BlackSPI(enum spiName spi); 58 | * 2) BlackSPI(enum spiName spi, struct BlackSpiProperties spiProperties); 59 | * 3) BlackSPI(enum spiName spi, uint8_t spiBitsPerWord, uint8_t spiMode, uint32_t spiSpeed); 60 | */ 61 | 62 | spiTiming.startMeasure("1. Constructor"); 63 | BlackLib::BlackSPI spiDemo(BlackLib::SPI0_0, 8, BlackLib::SpiDefault , 2400000); 64 | spiTiming.endMeasure("1. Constructor"); 65 | 66 | uint8_t writeByte = 0xb1; 67 | uint8_t readByte; 68 | 69 | uint8_t writeArr[4] = { 0x55, 0xaa, 0xf0, 0x0c } ; 70 | uint8_t readArr[4]; 71 | 72 | 73 | 74 | 75 | 76 | 77 | /* 78 | * This part of the example code is about spi device connection openning with 79 | * BlackLib::openMode enums and getting information about current spi connection. 80 | */ 81 | 82 | spiTiming.startMeasure("2. BlackSPI::open()"); 83 | bool isOpened = spiDemo.open(BlackLib::ReadWrite|BlackLib::NonBlock); 84 | spiTiming.endMeasure("2. BlackSPI::open()"); 85 | 86 | if( !isOpened ) 87 | { 88 | std::cout << "SPI DEVICE CAN\'T OPEN.;" << std::endl; 89 | exit(1); 90 | } 91 | 92 | std::cout << std::endl; 93 | std::cout << "Device Path : " << spiDemo.getPortName() << std::endl; 94 | std::cout << "Max Speed(Hz) : " << spiDemo.getMaximumSpeed() << std::endl; 95 | std::cout << "Bits Per Word : " << (int)spiDemo.getBitsPerWord() << std::endl; 96 | std::cout << "Mode : " << (int)spiDemo.getMode() << std::endl << std::endl ; 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | /* 105 | * This part of the example code is about transfering data from/to uint8_t byte with 106 | * transfer() function and displaying result. Displaying part is unnecessery. 107 | */ 108 | 109 | spiTiming.startMeasure("3. BlackSPI::transfer(uint8_t, uint16_t)"); 110 | readByte = spiDemo.transfer(writeByte,0); 111 | spiTiming.endMeasure("3. BlackSPI::transfer(uint8_t, uint16_t)"); 112 | 113 | std::cout << std::setw(43) << "ONESHOT TRANSFER DEMO WITH ONE BYTE" << std::endl; 114 | std::cout << std::setw(15) << "SENT" << std::setw(26) << "RECEIVED" << std::endl; 115 | std::cout << std::string(50,'-'); 116 | 117 | std::cout << "\n\t " << std::hex << (int)writeByte; 118 | std::cout << "\t\t\t " << std::hex << (int)readByte << std::endl << std::endl << std::endl; 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | /* 127 | * This part of the example code is about transfering datas from/to arrays with 128 | * transfer() function and displaying results. Displaying part is unnecessery. 129 | */ 130 | 131 | std::cout << std::setw(43) << "ONESHOT TRANSFER DEMO WITH ARRAYS" << std::endl; 132 | std::cout << std::setw(15) << "SENT" << std::setw(26) << "RECEIVED" << std::endl; 133 | std::cout << std::string(50,'-'); 134 | 135 | memset(readArr,0,sizeof(readArr)); 136 | 137 | spiTiming.startMeasure("4. BlackSPI::transfer(uint8_t*, uint8_t*, size_t, uint16_t)"); 138 | spiDemo.transfer(writeArr, readArr, sizeof readArr); 139 | spiTiming.endMeasure("4. BlackSPI::transfer(uint8_t*, uint8_t*, size_t, uint16_t)"); 140 | 141 | std::cout << "\n\t" << std::hex << (int)writeArr[0] << " " << (int)writeArr[1] 142 | << " " << (int)writeArr[2] << " " << (int)writeArr[3]; 143 | 144 | std::cout << "\t\t" << std::hex << (int)readArr[0] << " " << (int)readArr[1] 145 | << " " << (int)readArr[2] << " " << (int)readArr[3] << std::endl << std::endl << std::endl; 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | /* 159 | * This part of the example code is about changing properties of SPI and displaying results. 160 | * This can be 2 ways. Second method is faster than the first one. Displaying part is unnecessery. 161 | */ 162 | 163 | spiDemo.setBitsPerWord(16); 164 | spiDemo.setMaximumSpeed(2000000); 165 | spiDemo.setMode(BlackLib::SpiMode2); 166 | 167 | std::cout << std::setw(42) << "PROPERTIES AFTER FIRST UPDATE" << std::endl; 168 | std::cout << std::string(50,'-'); 169 | std::cout << "\nMax Speed(Hz) : " << std::dec << spiDemo.getMaximumSpeed() << std::endl; 170 | std::cout << "Bits Per Word : " << std::dec << (int)spiDemo.getBitsPerWord() << std::endl; 171 | std::cout << "Mode : " << std::dec << (int)spiDemo.getMode() << std::endl << std::endl ; 172 | 173 | 174 | 175 | BlackLib::BlackSpiProperties newProperties(14, (BlackLib::SpiPhase|BlackLib::SpiPolarity) , 24000000); 176 | spiDemo.setProperties( newProperties ); 177 | BlackLib::BlackSpiProperties updatedProperties = spiDemo.getProperties(); 178 | 179 | std::cout << std::setw(42) << "PROPERTIES AFTER SECOND UPDATE" << std::endl; 180 | std::cout << std::string(50,'-'); 181 | std::cout << "\nMax Speed(Hz) : " << std::dec << updatedProperties.spiSpeed << std::endl; 182 | std::cout << "Bits Per Word : " << std::dec << (int)updatedProperties.spiBitsPerWord << std::endl; 183 | std::cout << "Mode : " << std::dec << (int)updatedProperties.spiMode << std::endl << std::endl ; 184 | 185 | 186 | std::cout << spiTiming.getAllMeasureTable(); 187 | spiTiming.saveToFile("BlackSPI_timing_results.out"); 188 | 189 | 190 | } 191 | 192 | #endif /* EXAMPLEANDTIMING_SPI_H_ */ 193 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/results/BlackADC_timing_results.out: -------------------------------------------------------------------------------- 1 | 2 | Filename: BlackADC_timing_results.out 3 | 4 | ------------------------------------------------------------- 5 | | LABEL | SEC | mSEC | uSEC | 6 | ------------------------------------------------------------- 7 | | 1. Constructor | 0 | 44 | 984 | 8 | ------------------------------------------------------------- 9 | | 2. BlackADC::getValue() | 0 | 1 | 939 | 10 | ------------------------------------------------------------- 11 | | 3. BlackADC::getNumericValue() | 0 | 1 | 702 | 12 | ------------------------------------------------------------- 13 | | 4. BlackADC::getConvertedValue() | 0 | 1 | 595 | 14 | ------------------------------------------------------------- 15 | | 5. BlackADC::operator>>(std::string) | 0 | 1 | 795 | 16 | ------------------------------------------------------------- 17 | | 6. BlackADC::operator>>(int) | 0 | 1 | 417 | 18 | ------------------------------------------------------------- 19 | | 7. BlackADC::operator>>(float) | 0 | 1 | 421 | 20 | ------------------------------------------------------------- 21 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/results/BlackGPIO_timing_results.out: -------------------------------------------------------------------------------- 1 | 2 | Filename: BlackGPIO_timing_results.out 3 | 4 | ----------------------------------------------------------------------------- 5 | | LABEL | SEC | mSEC | uSEC | 6 | ----------------------------------------------------------------------------- 7 | | 1. Constructor | 0 | 7 | 645 | 8 | ----------------------------------------------------------------------------- 9 | | 2.1. (SecureMode) BlackGPIO::setValue() | 0 | 5 | 556 | 10 | ----------------------------------------------------------------------------- 11 | | 2.2. (FastMode) BlackGPIO::setValue() | 0 | 0 | 509 | 12 | ----------------------------------------------------------------------------- 13 | | 3.1. (SecureMode,InputType) BlackGPIO::getValue() | 0 | 3 | 306 | 14 | ----------------------------------------------------------------------------- 15 | | 3.2. (FastMode,InputType) BlackGPIO::getValue() | 0 | 0 | 420 | 16 | ----------------------------------------------------------------------------- 17 | | 3.3. (SecureMode,OutputType) BlackGPIO::getValue() | 0 | 2 | 177 | 18 | ----------------------------------------------------------------------------- 19 | | 3.4. (FastMode,OutputType) BlackGPIO::getValue() | 0 | 0 | 383 | 20 | ----------------------------------------------------------------------------- 21 | | 4.1. BlackGPIO::toggleValue() (SecureMode) | 0 | 2 | 583 | 22 | ----------------------------------------------------------------------------- 23 | | 4.2. BlackGPIO::toggleValue() (FastMode) | 0 | 0 | 669 | 24 | ----------------------------------------------------------------------------- 25 | | 5.1. (SecureMode) BlackGPIO::operator>>(std::string) | 0 | 1 | 22 | 26 | ----------------------------------------------------------------------------- 27 | | 5.2. (FastMode) BlackGPIO::operator>>(std::string) | 0 | 0 | 522 | 28 | ----------------------------------------------------------------------------- 29 | | 6.1. (SecureMode) BlackGPIO::operator>>(int) | 0 | 0 | 945 | 30 | ----------------------------------------------------------------------------- 31 | | 6.2. (FastMode) BlackGPIO::operator>>(int) | 0 | 0 | 339 | 32 | ----------------------------------------------------------------------------- 33 | | 7.1. (SecureMode) BlackGPIO::operator<<() | 0 | 1 | 140 | 34 | ----------------------------------------------------------------------------- 35 | | 7.2. (FastMode) BlackGPIO::operator<<() | 0 | 0 | 374 | 36 | ----------------------------------------------------------------------------- 37 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/results/BlackI2C_timing_results.out: -------------------------------------------------------------------------------- 1 | 2 | Filename: BlackI2C_timing_results.out 3 | 4 | ------------------------------------------------------------------- 5 | | LABEL | SEC | mSEC | uSEC | 6 | ------------------------------------------------------------------- 7 | | 1. Constructor | 0 | 1 | 686 | 8 | ------------------------------------------------------------------- 9 | | 2. BlackI2C::open() | 0 | 0 | 226 | 10 | ------------------------------------------------------------------- 11 | | 3.1. BlackI2C::readByte() | 0 | 0 | 642 | 12 | ------------------------------------------------------------------- 13 | | 3.2. BlackI2C::writeByte() | 0 | 0 | 628 | 14 | ------------------------------------------------------------------- 15 | | 4.1. BlackI2C::readWord() | 0 | 0 | 874 | 16 | ------------------------------------------------------------------- 17 | | 4.2. BlackI2C::writeWord() | 0 | 0 | 578 | 18 | ------------------------------------------------------------------- 19 | | 5.1. (Block Size:3) BlackI2C::readBlock() | 0 | 0 | 898 | 20 | ------------------------------------------------------------------- 21 | | 5.2. (Block Size:3) BlackI2C::writeBlock() | 0 | 0 | 731 | 22 | ------------------------------------------------------------------- 23 | | 6.1. (Block Size:3) BlackI2C::readLine() | 0 | 0 | 592 | 24 | ------------------------------------------------------------------- 25 | | 6.2. (Block Size:3) BlackI2C::writeLine() | 0 | 0 | 687 | 26 | ------------------------------------------------------------------- 27 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/results/BlackPWM_timing_results.out: -------------------------------------------------------------------------------- 1 | 2 | Filename: BlackPWM_timing_results.out 3 | 4 | --------------------------------------------------------------- 5 | | LABEL | SEC | mSEC | uSEC | 6 | --------------------------------------------------------------- 7 | | 1. Constructor | 0 | 42 | 959 | 8 | --------------------------------------------------------------- 9 | | 2. BlackPWM::setSpaceRatioTime() | 0 | 0 | 866 | 10 | --------------------------------------------------------------- 11 | | 3. BlackPWM::setPeriodTime() | 0 | 0 | 911 | 12 | --------------------------------------------------------------- 13 | | 4. BlackPWM::setLoadRatioTime() | 0 | 1 | 66 | 14 | --------------------------------------------------------------- 15 | | 5. BlackPWM::setDutyPercent() | 0 | 0 | 749 | 16 | --------------------------------------------------------------- 17 | | 6_1. BlackPWM::getDutyValue() | 0 | 0 | 377 | 18 | --------------------------------------------------------------- 19 | | 6_2. BlackPWM::getNumericDutyValue() | 0 | 0 | 289 | 20 | --------------------------------------------------------------- 21 | | 7_1. BlackPWM::getPeriodValue() | 0 | 0 | 497 | 22 | --------------------------------------------------------------- 23 | | 7_2. BlackPWM::getNumericPeriodValue() | 0 | 0 | 277 | 24 | --------------------------------------------------------------- 25 | | 8_1. BlackPWM::getValue() | 0 | 1 | 738 | 26 | --------------------------------------------------------------- 27 | | 8_2. BlackPWM::getNumericValue() | 0 | 0 | 567 | 28 | --------------------------------------------------------------- 29 | | 9_1. BlackPWM::getPolarityValue() | 0 | 0 | 277 | 30 | --------------------------------------------------------------- 31 | | 9_2. BlackPWM::getRunValue() | 0 | 0 | 264 | 32 | --------------------------------------------------------------- 33 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/results/BlackSPI_timing_results.out: -------------------------------------------------------------------------------- 1 | 2 | Filename: BlackSPI_timing_results.out 3 | 4 | ------------------------------------------------------------------------------------ 5 | | LABEL | SEC | mSEC | uSEC | 6 | ------------------------------------------------------------------------------------ 7 | | 1. Constructor | 0 | 28 | 275 | 8 | ------------------------------------------------------------------------------------ 9 | | 2. BlackSPI::open() | 0 | 0 | 257 | 10 | ------------------------------------------------------------------------------------ 11 | | 3. BlackSPI::transfer(uint8_t, uint16_t) | 0 | 0 | 193 | 12 | ------------------------------------------------------------------------------------ 13 | | 4. BlackSPI::transfer(uint8_t*, uint8_t*, size_t, uint16_t) | 0 | 0 | 263 | 14 | ------------------------------------------------------------------------------------ 15 | -------------------------------------------------------------------------------- /v2_0/exampleAndTiming/results/BlackUART_timing_results.out: -------------------------------------------------------------------------------- 1 | 2 | Filename: BlackUART_timing_results.out 3 | 4 | ---------------------------------------------------------------------- 5 | | LABEL | SEC | mSEC | uSEC | 6 | ---------------------------------------------------------------------- 7 | | 1. Constructor | 0 | 24 | 414 | 8 | ---------------------------------------------------------------------- 9 | | 2. BlackUART::open() | 0 | 2 | 239 | 10 | ---------------------------------------------------------------------- 11 | | 3. BlackUART::transfer(std::string, uint32_t) | 0 | 0 | 422 | 12 | ---------------------------------------------------------------------- 13 | | 4. BlackUART::write(char*, size_t) | 0 | 0 | 57 | 14 | ---------------------------------------------------------------------- 15 | | 5. BlackUART::read(char*, size_t) | 0 | 0 | 83 | 16 | ---------------------------------------------------------------------- 17 | | 6. BlackUART::write(std::string) | 0 | 0 | 95 | 18 | ---------------------------------------------------------------------- 19 | | 7. BlackUART::read() | 0 | 0 | 106 | 20 | ---------------------------------------------------------------------- 21 | | 8. BlackUART::operator<<(std::string) | 0 | 0 | 100 | 22 | ---------------------------------------------------------------------- 23 | | 9. BlackUART::operator>>(std::string) | 0 | 0 | 165 | 24 | ---------------------------------------------------------------------- 25 | -------------------------------------------------------------------------------- /v3_0/BlackCore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 "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 | -------------------------------------------------------------------------------- /v3_0/BlackDef.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 | 32 | #ifndef BLACKDEF_H_ 33 | #define BLACKDEF_H_ 34 | 35 | 36 | #include 37 | 38 | namespace BlackLib 39 | { 40 | 41 | /*! 42 | * This enum is used for selecting direction. 43 | */ 44 | enum direction { input = 1, 45 | output = 2, 46 | bothDirection = (input|output) 47 | }; 48 | 49 | 50 | /*! 51 | * This enum is used for setting run state (like PWM). 52 | */ 53 | enum runValue { stop = 0, 54 | run = 1 55 | }; 56 | 57 | 58 | /*! 59 | * This enum is used for selecting time type (like BlackPWM::setPeriodTime() function). 60 | */ 61 | enum timeType { picosecond = -12, 62 | nanosecond = -9, 63 | microsecond = -6, 64 | milisecond = -3, 65 | second = 1 66 | }; 67 | 68 | 69 | /*! 70 | * This enum is used for selecting file open mode. 71 | */ 72 | enum openMode { ReadOnly = 0, 73 | WriteOnly = 1, 74 | ReadWrite = 2, 75 | Append = 4, 76 | Truncate = 8, 77 | NonBlock = 16 78 | }; 79 | 80 | 81 | 82 | 83 | 84 | const std::string DEFAULT_CAPE_MGR_NUMBER = "8"; //!< If @b capemgr finding fails, it uses this number 85 | const std::string DEFAULT_OCP_NUMBER = "2"; //!< If @b ocp finding fails, it uses this number 86 | const std::string DEFAULT_HELPER_NUMBER = "14"; //!< If @b helper finding fails, it uses this number 87 | const std::string DEFAULT_PWM_TEST_NUMBER = "15"; //!< If @b pwm_test finding fails, it uses this number 88 | const std::string DEFAULT_SPI0_PINMUX = "48030000"; //!< SPI0 pinmux number 89 | const std::string DEFAULT_SPI1_PINMUX = "481a0000"; //!< SPI1 pinmux number 90 | const unsigned int DEFAULT_OPEN_MODE = (ReadWrite); //!< Default open mode 91 | const std::string PWM_TEST_NAME_NOT_FOUND = "PwmTestNameError"; //!< If pwm test name could not find, function returns this string 92 | const std::string GPIO_PIN_NOT_READY_STRING = "Gpio Pin Isn\'t Ready"; //!< If gpio pin is not ready, function returns this string 93 | const int GPIO_PIN_NOT_READY_INT = -2; //!< If gpio pin is not ready, function returns this integer 94 | const std::string UART_READ_FAILED = "UartReadError"; //!< If uart read is failed, function returns this string 95 | const std::string UART_WRITE_FAILED = "UartWriteError"; //!< If uart write is failed, function returns this string 96 | const std::string SEARCH_DIR_NOT_FOUND = "Not Found"; //!< If directory searching fails, function returns this string 97 | const std::string FILE_COULD_NOT_OPEN_STRING = "File Couldn\'t Open"; //!< If file could not open, function returns this string 98 | const int FILE_COULD_NOT_OPEN_INT = -1; //!< If file could not open, function returns this integer 99 | const float FILE_COULD_NOT_OPEN_FLOAT = -1.0; //!< If file could not open, function returns this float value 100 | 101 | } /* namespace BlackLib */ 102 | 103 | #endif /* BLACKDEF_H_ */ 104 | -------------------------------------------------------------------------------- /v3_0/BlackDirectory/BlackDirectory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BlackDirectory.cpp 3 | * 4 | * Created on: 21 Eki 2014 5 | * Author: yigityuce 6 | */ 7 | 8 | #include "BlackDirectory.h" 9 | 10 | namespace BlackLib 11 | { 12 | 13 | BlackDirectory::BlackDirectory() 14 | { 15 | this->applicationDirectory = BlackDirectory::getCurrentDirectoryPath(); 16 | } 17 | 18 | BlackDirectory::BlackDirectory(std::string path) 19 | { 20 | this->applicationDirectory = BlackDirectory::getCurrentDirectoryPath(); 21 | BlackDirectory::cd(path); 22 | } 23 | 24 | BlackDirectory::~BlackDirectory() 25 | { 26 | 27 | } 28 | 29 | 30 | std::string BlackDirectory::getHomeDirectoryPath() 31 | { 32 | passwd *pw = getpwuid(getuid()); 33 | std::string homeDir( pw ? pw->pw_dir : ""); 34 | 35 | return homeDir; 36 | } 37 | 38 | std::string BlackDirectory::getCurrentUserName() 39 | { 40 | passwd *pw = getpwuid(getuid()); 41 | std::string username( pw ? pw->pw_name : ""); 42 | 43 | return username; 44 | } 45 | 46 | std::string BlackDirectory::getCurrentDirectoryPath() 47 | { 48 | std::string pwd; 49 | pwd.resize(1000,'\t'); 50 | 51 | bool isFound = ( getcwd(&(pwd[0]), pwd.size()) != NULL ); 52 | 53 | 54 | if ( isFound ) 55 | { 56 | size_t first = pwd.find_first_of('\t',0); 57 | pwd.resize(first); 58 | } 59 | else 60 | { 61 | pwd = BlackLib::CURRENT_DIRECTORY_NOT_FOUND; 62 | } 63 | 64 | return pwd; 65 | 66 | } 67 | 68 | std::string BlackDirectory::getCurrentDirectoryName() 69 | { 70 | std::string pwd = BlackDirectory::getCurrentDirectoryPath(); 71 | std::string dirName = ""; 72 | 73 | if( pwd != BlackLib::CURRENT_DIRECTORY_NOT_FOUND and pwd != "/" ) 74 | { 75 | if( pwd[pwd.size()-1] == '/' ) { pwd.resize(pwd.size()-1); } 76 | 77 | dirName = pwd.substr(pwd.find_last_of('/')+1); 78 | } 79 | 80 | return dirName; 81 | 82 | } 83 | 84 | 85 | 86 | long int BlackDirectory::getCurrentDirectorySize() 87 | { 88 | return BlackDirectory::getDirectorySize(BlackDirectory::getCurrentDirectoryPath()); 89 | } 90 | 91 | 92 | long int BlackDirectory::getDirectorySize(std::string directoryPath) 93 | { 94 | struct stat sb; 95 | if ( stat(&directoryPath[0],&sb) == 0 ) 96 | { 97 | return sb.st_size; 98 | } 99 | return 0; 100 | } 101 | 102 | bool BlackDirectory::exists(std::string directoryPath) 103 | { 104 | struct stat sb; 105 | return ( stat(&directoryPath[0],&sb) == 0 ); 106 | } 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | bool BlackDirectory::cd(std::string path) 119 | { 120 | if ( BlackDirectory::exists(path) ) 121 | { 122 | return (chdir(&path[0]) == 0); 123 | } 124 | return false; 125 | } 126 | 127 | bool BlackDirectory::cdUp() 128 | { 129 | return BlackDirectory::cd(".."); 130 | } 131 | 132 | bool BlackDirectory::isRoot() 133 | { 134 | return (BlackDirectory::getCurrentDirectoryPath() == "/" ); 135 | } 136 | 137 | 138 | 139 | 140 | 141 | std::vector BlackDirectory::getEntryList(std::string directoryPath, BlackDirectory::hiddenFormat hf, BlackDirectory::componentFormat cf, bool sortAlphabetically) 142 | { 143 | std::vector directoryList; 144 | directoryList.clear(); 145 | 146 | if ( BlackDirectory::exists(directoryPath) ) 147 | { 148 | DIR *dp; 149 | dirent *dirp; 150 | 151 | if( (dp = opendir(directoryPath.c_str())) != NULL) 152 | { 153 | while( (dirp = readdir(dp)) != NULL ) 154 | { 155 | std::string fname(dirp->d_name); 156 | 157 | if( fname == "." ) continue; 158 | if( fname == ".." ) continue; 159 | if( hf == BlackDirectory::ExcludeHiddens and fname[0] == '.' ) continue; 160 | 161 | 162 | struct stat sb; 163 | if( stat(&fname[0],&sb) == 0 ) 164 | { 165 | if( (cf & BlackDirectory::Directory) == BlackDirectory::Directory and S_ISDIR(sb.st_mode)) { directoryList.push_back(fname); } 166 | if( (cf & BlackDirectory::File) == BlackDirectory::File and S_ISREG(sb.st_mode)) { directoryList.push_back(fname); } 167 | if( (cf & BlackDirectory::SymbolicLink) == BlackDirectory::SymbolicLink and S_ISLNK(sb.st_mode)) { directoryList.push_back(fname); } 168 | } 169 | 170 | } 171 | closedir(dp); 172 | } 173 | } 174 | 175 | if ( sortAlphabetically ) { std::sort(directoryList.begin(), directoryList.end()); } 176 | return directoryList; 177 | } 178 | 179 | unsigned int BlackDirectory::getEntryCount(std::string directoryPath, BlackDirectory::hiddenFormat hf, BlackDirectory::componentFormat cf) 180 | { 181 | return BlackDirectory::getEntryList(directoryPath,hf,cf,false).size(); 182 | } 183 | 184 | 185 | std::vector BlackDirectory::getEntryList(BlackDirectory::hiddenFormat hf, BlackDirectory::componentFormat cf, bool sortAlphabetically) 186 | { 187 | return BlackDirectory::getEntryList(BlackDirectory::getCurrentDirectoryPath(),hf,cf,sortAlphabetically); 188 | } 189 | 190 | unsigned int BlackDirectory::getEntryCount(BlackDirectory::hiddenFormat hf, BlackDirectory::componentFormat cf) 191 | { 192 | return BlackDirectory::getEntryList(BlackDirectory::getCurrentDirectoryPath(),hf,cf,false).size(); 193 | } 194 | 195 | 196 | 197 | 198 | std::string BlackDirectory::getApplicationDirectoryPath() 199 | { 200 | return this->applicationDirectory; 201 | } 202 | 203 | std::string BlackDirectory::getApplicationDirectoryName() 204 | { 205 | std::string pwd = this->applicationDirectory; 206 | std::string dirName = ""; 207 | 208 | if( pwd != BlackLib::CURRENT_DIRECTORY_NOT_FOUND and pwd != "/" ) 209 | { 210 | if( pwd[pwd.size()-1] == '/' ) { pwd.resize(pwd.size()-1); } 211 | 212 | dirName = pwd.substr(pwd.find_last_of('/')+1); 213 | } 214 | 215 | return dirName; 216 | } 217 | 218 | 219 | 220 | 221 | bool BlackDirectory::makeDirectory(std::string directoryPath) 222 | { 223 | if( ! BlackDirectory::exists(directoryPath) ) 224 | { 225 | return ( mkdir(&directoryPath[0], 0777) == 0); 226 | } 227 | 228 | return true; 229 | } 230 | 231 | bool BlackDirectory::removeDirectory(std::string directoryPath, bool rmRecursively) 232 | { 233 | struct stat sb; 234 | 235 | if( stat(&directoryPath[0],&sb) == 0 ) 236 | { 237 | if( !rmRecursively ){ return (rmdir(directoryPath.c_str()) == 0); } 238 | 239 | 240 | if( S_ISDIR(sb.st_mode) ) 241 | { 242 | std::vector directoryList; 243 | directoryList.clear(); 244 | DIR *dp; 245 | dirent *dirp; 246 | 247 | if( (dp = opendir(directoryPath.c_str())) != NULL) 248 | { 249 | while( (dirp = readdir(dp)) != NULL ) 250 | { 251 | std::string fname(dirp->d_name); 252 | 253 | if( fname == "." ) continue; 254 | if( fname == ".." ) continue; 255 | directoryList.push_back(fname); 256 | } 257 | closedir(dp); 258 | } 259 | 260 | if( directoryList.empty() ) 261 | { 262 | return (std::remove(directoryPath.c_str()) == 0); 263 | } 264 | 265 | for( unsigned 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 | 31 | #ifndef BLACKLIB_H_ 32 | #define BLACKLIB_H_ 33 | 34 | #include "BlackCore.h" 35 | #include "BlackADC/BlackADC.h" 36 | #include "BlackPWM/BlackPWM.h" 37 | #include "BlackGPIO/BlackGPIO.h" 38 | #include "BlackUART/BlackUART.h" 39 | #include "BlackSPI/BlackSPI.h" 40 | #include "BlackI2C/BlackI2C.h" 41 | #include "BlackThread/BlackThread.h" 42 | #include "BlackMutex/BlackMutex.h" 43 | #include "BlackDirectory/BlackDirectory.h" 44 | #include "BlackTime/BlackTime.h" 45 | 46 | 47 | #endif /* BLACKLIB_H_ */ 48 | -------------------------------------------------------------------------------- /v3_0/BlackMutex/BlackMutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BlackMutex.cpp 3 | * 4 | * Created on: 10 Eki 2014 5 | * Author: yigityuce 6 | */ 7 | 8 | #include "BlackMutex.h" 9 | 10 | namespace BlackLib 11 | { 12 | 13 | BlackMutex::BlackMutex(BlackMutex::mutexMode mm) 14 | { 15 | this->lockCount = 0; 16 | this->mode = mm; 17 | 18 | pthread_mutexattr_t tempMutexAttr; 19 | pthread_mutexattr_init(&tempMutexAttr); 20 | 21 | if( mm == BlackMutex::Recursive ) 22 | { 23 | pthread_mutexattr_settype(&tempMutexAttr, PTHREAD_MUTEX_RECURSIVE); 24 | } 25 | else 26 | { 27 | pthread_mutexattr_settype(&tempMutexAttr, PTHREAD_MUTEX_ERRORCHECK); 28 | } 29 | 30 | pthread_mutexattr_setpshared(&tempMutexAttr, PTHREAD_PROCESS_PRIVATE); 31 | 32 | pthread_mutex_init( &(this->mutex), &tempMutexAttr); 33 | pthread_mutexattr_destroy(&tempMutexAttr); 34 | } 35 | 36 | 37 | BlackMutex::~BlackMutex() 38 | { 39 | pthread_mutex_destroy( &(this->mutex) ); 40 | } 41 | 42 | bool BlackMutex::lock() 43 | { 44 | bool isSuccess = ( pthread_mutex_lock( &(this->mutex) ) == 0); 45 | 46 | if( isSuccess ){ ++(this->lockCount); } 47 | 48 | return isSuccess; 49 | } 50 | 51 | bool BlackMutex::timedLock(unsigned int sec) 52 | { 53 | timespec until; 54 | until.tv_sec = sec; 55 | until.tv_nsec = 0; 56 | 57 | bool isSuccess = ( pthread_mutex_timedlock( &(this->mutex), &until) == 0); 58 | 59 | if( isSuccess ){ ++(this->lockCount); } 60 | 61 | return isSuccess; 62 | } 63 | 64 | bool BlackMutex::tryLock() 65 | { 66 | bool isSuccess = ( pthread_mutex_trylock( &(this->mutex) ) == 0); 67 | 68 | if( isSuccess ){ ++(this->lockCount); } 69 | 70 | return isSuccess; 71 | } 72 | 73 | bool BlackMutex::unlock() 74 | { 75 | bool isSuccess = ( pthread_mutex_unlock( &(this->mutex) ) == 0); 76 | 77 | if( isSuccess ){ --(this->lockCount); } 78 | 79 | return isSuccess; 80 | } 81 | 82 | 83 | bool BlackMutex::isLocked() 84 | { 85 | return (this->lockCount > 0); 86 | } 87 | 88 | bool BlackMutex::isRecursive() 89 | { 90 | return (this->mode == BlackMutex::Recursive ); 91 | } 92 | 93 | unsigned int BlackMutex::getLockedCount() 94 | { 95 | return this->lockCount; 96 | } 97 | 98 | 99 | } /* namespace BlackLib */ 100 | -------------------------------------------------------------------------------- /v3_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 | -------------------------------------------------------------------------------- /v3_0/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 | -------------------------------------------------------------------------------- /v3_0/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 | -------------------------------------------------------------------------------- /v3_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 | -------------------------------------------------------------------------------- /v3_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 | -------------------------------------------------------------------------------- /v3_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 | -------------------------------------------------------------------------------- /v3_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 | -------------------------------------------------------------------------------- /v3_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 | -------------------------------------------------------------------------------- /v3_0/examples.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 "examples/example_GPIO.h" 34 | #include "examples/example_ADC.h" 35 | #include "examples/example_PWM.h" 36 | #include "examples/example_SPI.h" 37 | #include "examples/example_UART.h" 38 | #include "examples/example_I2C.h" 39 | #include "examples/example_directory.h" 40 | #include "examples/example_threadAndMutex.h" 41 | #include "examples/example_time.h" 42 | 43 | 44 | 45 | 46 | int main() 47 | { 48 | 49 | example_GPIO(); 50 | example_ADC(); 51 | example_PWM(); 52 | example_SPI(); 53 | example_UART(); 54 | example_I2C(); 55 | example_directory(); 56 | example_threadAndMutex(); 57 | example_time(); 58 | 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /v3_0/examples/example_ADC.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 | 32 | 33 | 34 | #ifndef EXAMPLE_ADC_H_ 35 | #define EXAMPLE_ADC_H_ 36 | 37 | 38 | #include "../BlackADC/BlackADC.h" 39 | #include 40 | #include 41 | 42 | 43 | 44 | 45 | 46 | 47 | void example_ADC() 48 | { 49 | 50 | BlackLib::BlackADC analog(BlackLib::AIN4 ); // initialization analog input 51 | 52 | 53 | std::string valueStr; 54 | int valueInt; 55 | float valueFloat; 56 | 57 | 58 | valueStr = analog.getValue(); 59 | 60 | 61 | usleep(1000); 62 | 63 | 64 | valueInt = analog.getNumericValue(); 65 | 66 | 67 | usleep(1000); 68 | 69 | 70 | valueFloat = analog.getConvertedValue( BlackLib::dap2 ); 71 | 72 | std::cout << "AIN_str: " << valueStr << std::endl; 73 | std::cout << "AIN_int: " << valueInt << std::endl; 74 | std::cout << "AIN_flt: " << valueFloat << std::endl; 75 | 76 | 77 | 78 | 79 | 80 | 81 | valueStr.clear(); 82 | valueInt = 0; 83 | valueFloat = 0.0; 84 | 85 | analog >> valueStr; 86 | 87 | 88 | usleep(1000); 89 | 90 | 91 | analog >> valueInt; 92 | 93 | 94 | usleep(1000); 95 | 96 | 97 | analog >> valueFloat; 98 | 99 | std::cout << "AIN_str_operator: " << valueStr << std::endl; 100 | std::cout << "AIN_int_operator: " << valueInt << std::endl; 101 | std::cout << "AIN_flt_operator: " << valueFloat << std::endl; 102 | 103 | } 104 | 105 | 106 | 107 | #endif /* EXAMPLE_ADC_H_ */ 108 | -------------------------------------------------------------------------------- /v3_0/examples/example_GPIO.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 | 32 | 33 | 34 | #ifndef EXAMPLE_GPIO_H_ 35 | #define EXAMPLE_GPIO_H_ 36 | 37 | 38 | 39 | 40 | #include "../BlackGPIO/BlackGPIO.h" 41 | #include 42 | #include 43 | 44 | 45 | 46 | 47 | void example_GPIO() 48 | { 49 | 50 | BlackLib::BlackGPIO led1(BlackLib::GPIO_51,BlackLib::output, BlackLib::SecureMode); // initialization first output, secure mode 51 | 52 | BlackLib::BlackGPIO led2(BlackLib::GPIO_22,BlackLib::output, BlackLib::FastMode); // initialization second output, fast mode 53 | BlackLib::BlackGPIO button1(BlackLib::GPIO_60,BlackLib::input); // initialization first input, secure mode 54 | BlackLib::BlackGPIO button2(BlackLib::GPIO_48,BlackLib::input, BlackLib::FastMode); // initialization second input, fast mode 55 | 56 | 57 | 58 | led1.setValue(BlackLib::high); // turn on the led1 59 | 60 | led2.setValue(BlackLib::high); 61 | 62 | 63 | 64 | 65 | std::string button1value; 66 | std::string button2value; 67 | std::string led1value; 68 | std::string led2value; 69 | 70 | 71 | button1value = button1.getValue(); 72 | 73 | button2value = button2.getValue(); 74 | 75 | 76 | 77 | led1value = led1.getValue(); 78 | 79 | led2value = led2.getValue(); 80 | 81 | sleep(1); 82 | 83 | 84 | 85 | 86 | led1.toggleValue(); 87 | 88 | led2.toggleValue(); 89 | 90 | sleep(1); 91 | 92 | 93 | 94 | 95 | 96 | std::string led1value_operator; 97 | int led1NumericValue_operator; 98 | 99 | led1 >> led1value_operator; 100 | 101 | led1 << BlackLib::high; 102 | 103 | led1 >> led1NumericValue_operator; 104 | 105 | 106 | 107 | 108 | 109 | std::string led2value_operator; 110 | int led2NumericValue_operator; 111 | 112 | led2 >> led2value_operator; 113 | 114 | led2 << BlackLib::high; 115 | 116 | led2 >> led2NumericValue_operator; 117 | 118 | sleep(1); 119 | 120 | } 121 | 122 | 123 | 124 | #endif /* EXAMPLE_GPIO_H_ */ 125 | -------------------------------------------------------------------------------- /v3_0/examples/example_PWM.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 | 32 | 33 | #ifndef EXAMPLE_PWM_H_ 34 | #define EXAMPLE_PWM_H_ 35 | 36 | 37 | 38 | 39 | #include "../BlackPWM/BlackPWM.h" 40 | #include 41 | #include 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | void example_PWM() 53 | { 54 | 55 | float percent = 5.0; 56 | std::string currentDuty; 57 | std::string currentPeriod; 58 | std::string currentPercentValue; 59 | std::string currentPolarity; 60 | std::string currentRun; 61 | 62 | int64_t currentDuty_numeric; 63 | int64_t currentPeriod_numeric; 64 | float currentPercentValue_numeric; 65 | 66 | 67 | 68 | 69 | 70 | BlackLib::BlackPWM pwmLed(BlackLib::EHRPWM2A); 71 | 72 | 73 | // if new period value is less than the current duty value, the new period value setting 74 | // operation couldn't execute. So firstly duty value is set to zero for safe steps. 75 | pwmLed.setDutyPercent(0.0); 76 | pwmLed.setPeriodTime(100000); 77 | sleep(1); 78 | 79 | 80 | 81 | 82 | pwmLed.setSpaceRatioTime(67, BlackLib::microsecond); 83 | 84 | std::cout << "DUTY after setting space time: \t\t" << pwmLed.getDutyValue() << std::endl; 85 | 86 | 87 | 88 | 89 | 90 | pwmLed.setPeriodTime(300000000, BlackLib::picosecond); 91 | 92 | std::cout << "PERIOD after setting period time: \t" << pwmLed.getPeriodValue() << std::endl; 93 | 94 | 95 | 96 | 97 | 98 | pwmLed.setLoadRatioTime(15000, BlackLib::nanosecond); 99 | 100 | std::cout << "DUTY after setting load time: \t\t" << pwmLed.getDutyValue() << std::endl; 101 | 102 | 103 | 104 | 105 | 106 | pwmLed.setDutyPercent(11.75); 107 | 108 | std::cout << "DUTY after setting percent: \t\t" << pwmLed.getDutyValue() << std::endl; 109 | 110 | 111 | 112 | 113 | 114 | currentDuty = pwmLed.getDutyValue(); 115 | 116 | currentDuty_numeric = pwmLed.getNumericDutyValue(); 117 | 118 | 119 | 120 | currentPeriod = pwmLed.getPeriodValue(); 121 | 122 | currentPeriod_numeric = pwmLed.getNumericPeriodValue(); 123 | 124 | 125 | 126 | 127 | currentPercentValue = pwmLed.getValue(); 128 | 129 | currentPercentValue_numeric = pwmLed.getNumericValue(); 130 | 131 | 132 | 133 | 134 | currentPolarity = pwmLed.getPolarityValue(); 135 | 136 | currentRun = pwmLed.getRunValue(); 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | std::cout << "Duty_str: \t" << currentDuty << std::endl; 150 | std::cout << "Duty_num: \t" << currentDuty_numeric << std::endl; 151 | std::cout << "Period_str: \t" << currentPeriod << std::endl; 152 | std::cout << "Period_num: \t" << currentPeriod_numeric << std::endl; 153 | std::cout << "Percent_str: \t" << currentPercentValue << std::endl; 154 | std::cout << "Percent_num: \t" << currentPercentValue_numeric << std::endl; 155 | std::cout << "Polarity_str: \t" << currentPolarity << std::endl; 156 | std::cout << "Run_str: \t" << currentRun << std::endl; 157 | 158 | 159 | 160 | while( ! pwmLed.fail(BlackLib::BlackPWM::outOfRangeErr) ) 161 | { 162 | pwmLed.setDutyPercent(percent); 163 | 164 | std::cout << std::endl << "New percent value: " << percent << std::endl; 165 | 166 | percent += 25.0; 167 | usleep(500000); 168 | } 169 | 170 | std::cout << std::endl << "Percent value is out of range." << std::endl; 171 | 172 | 173 | } 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | #endif /* EXAMPLE_PWM_H_ */ 182 | -------------------------------------------------------------------------------- /v3_0/examples/example_SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 | 32 | 33 | #ifndef EXAMPLE_SPI_H_ 34 | #define EXAMPLE_SPI_H_ 35 | 36 | 37 | #include "../BlackSPI/BlackSPI.h" 38 | #include 39 | #include 40 | #include 41 | 42 | 43 | 44 | 45 | void example_SPI() 46 | { 47 | 48 | /* 49 | * This part of the example code is about BlackSPI class, write/read buffer and write/read 50 | * byte initialization. 51 | * 52 | * BlackSPI class also can be use like below: 53 | * 1) BlackSPI(enum spiName spi); 54 | * 2) BlackSPI(enum spiName spi, struct BlackSpiProperties spiProperties); 55 | * 3) BlackSPI(enum spiName spi, uint8_t spiBitsPerWord, uint8_t spiMode, uint32_t spiSpeed); 56 | */ 57 | 58 | BlackLib::BlackSPI spiDemo(BlackLib::SPI0_0, 8, BlackLib::SpiDefault , 2400000); 59 | 60 | uint8_t writeByte = 0xb1; 61 | uint8_t readByte; 62 | 63 | uint8_t writeArr[4] = { 0x55, 0xaa, 0xf0, 0x0c } ; 64 | uint8_t readArr[4]; 65 | 66 | 67 | 68 | 69 | 70 | 71 | /* 72 | * This part of the example code is about spi device connection openning with 73 | * BlackLib::openMode enums and getting information about current spi connection. 74 | */ 75 | 76 | bool isOpened = spiDemo.open(BlackLib::ReadWrite|BlackLib::NonBlock); 77 | 78 | if( !isOpened ) 79 | { 80 | std::cout << "SPI DEVICE CAN\'T OPEN.;" << std::endl; 81 | exit(1); 82 | } 83 | 84 | std::cout << std::endl; 85 | std::cout << "Device Path : " << spiDemo.getPortName() << std::endl; 86 | std::cout << "Max Speed(Hz) : " << spiDemo.getMaximumSpeed() << std::endl; 87 | std::cout << "Bits Per Word : " << (int)spiDemo.getBitsPerWord() << std::endl; 88 | std::cout << "Mode : " << (int)spiDemo.getMode() << std::endl << std::endl ; 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | /* 97 | * This part of the example code is about transfering data from/to uint8_t byte with 98 | * transfer() function and displaying result. Displaying part is unnecessery. 99 | */ 100 | 101 | readByte = spiDemo.transfer(writeByte,0); 102 | 103 | std::cout << std::setw(43) << "ONESHOT TRANSFER DEMO WITH ONE BYTE" << std::endl; 104 | std::cout << std::setw(15) << "SENT" << std::setw(26) << "RECEIVED" << std::endl; 105 | std::cout << std::string(50,'-'); 106 | 107 | std::cout << "\n\t " << std::hex << (int)writeByte; 108 | std::cout << "\t\t\t " << std::hex << (int)readByte << std::endl << std::endl << std::endl; 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | /* 117 | * This part of the example code is about transfering datas from/to arrays with 118 | * transfer() function and displaying results. Displaying part is unnecessery. 119 | */ 120 | 121 | std::cout << std::setw(43) << "ONESHOT TRANSFER DEMO WITH ARRAYS" << std::endl; 122 | std::cout << std::setw(15) << "SENT" << std::setw(26) << "RECEIVED" << std::endl; 123 | std::cout << std::string(50,'-'); 124 | 125 | memset(readArr,0,sizeof(readArr)); 126 | 127 | spiDemo.transfer(writeArr, readArr, sizeof readArr); 128 | 129 | std::cout << "\n\t" << std::hex << (int)writeArr[0] << " " << (int)writeArr[1] 130 | << " " << (int)writeArr[2] << " " << (int)writeArr[3]; 131 | 132 | std::cout << "\t\t" << std::hex << (int)readArr[0] << " " << (int)readArr[1] 133 | << " " << (int)readArr[2] << " " << (int)readArr[3] << std::endl << std::endl << std::endl; 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | /* 147 | * This part of the example code is about changing properties of SPI and displaying results. 148 | * This can be 2 ways. Second method is faster than the first one. Displaying part is unnecessery. 149 | */ 150 | 151 | spiDemo.setBitsPerWord(16); 152 | spiDemo.setMaximumSpeed(2000000); 153 | spiDemo.setMode(BlackLib::SpiMode2); 154 | 155 | std::cout << std::setw(42) << "PROPERTIES AFTER FIRST UPDATE" << std::endl; 156 | std::cout << std::string(50,'-'); 157 | std::cout << "\nMax Speed(Hz) : " << std::dec << spiDemo.getMaximumSpeed() << std::endl; 158 | std::cout << "Bits Per Word : " << std::dec << (int)spiDemo.getBitsPerWord() << std::endl; 159 | std::cout << "Mode : " << std::dec << (int)spiDemo.getMode() << std::endl << std::endl ; 160 | 161 | 162 | 163 | BlackLib::BlackSpiProperties newProperties(14, (BlackLib::SpiPhase|BlackLib::SpiPolarity) , 24000000); 164 | spiDemo.setProperties( newProperties ); 165 | BlackLib::BlackSpiProperties updatedProperties = spiDemo.getProperties(); 166 | 167 | std::cout << std::setw(42) << "PROPERTIES AFTER SECOND UPDATE" << std::endl; 168 | std::cout << std::string(50,'-'); 169 | std::cout << "\nMax Speed(Hz) : " << std::dec << updatedProperties.spiSpeed << std::endl; 170 | std::cout << "Bits Per Word : " << std::dec << (int)updatedProperties.spiBitsPerWord << std::endl; 171 | std::cout << "Mode : " << std::dec << (int)updatedProperties.spiMode << std::endl << std::endl ; 172 | 173 | 174 | } 175 | 176 | #endif /* EXAMPLE_SPI_H_ */ 177 | -------------------------------------------------------------------------------- /v3_0/examples/example_directory.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 EXAMPLE_DIRECTORY_H_ 32 | #define EXAMPLE_DIRECTORY_H_ 33 | 34 | #include "../BlackDirectory/BlackDirectory.h" 35 | #include 36 | #include 37 | 38 | 39 | 40 | 41 | 42 | 43 | void example_directory() 44 | { 45 | std::cout << "Current Directory Path: " << BlackLib::BlackDirectory::getCurrentDirectoryPath() << std::endl; 46 | std::cout << "Home Directory Path : " << BlackLib::BlackDirectory::getHomeDirectoryPath() << std::endl; 47 | std::cout << "Current User Name : " << BlackLib::BlackDirectory::getCurrentUserName() << std::endl; 48 | 49 | 50 | 51 | BlackLib::BlackDirectory *myDir = new BlackLib::BlackDirectory("/home/root/Desktop/"); 52 | 53 | std::cout << "Application Directory Path: " << myDir->getApplicationDirectoryPath() << std::endl; 54 | std::cout << "Application Directory Name: " << myDir->getApplicationDirectoryName() << std::endl; 55 | std::cout << "Current Directory Path : " << myDir->getCurrentDirectoryPath() << std::endl; 56 | std::cout << "Current Directory Name : " << myDir->getCurrentDirectoryName() << std::endl; 57 | 58 | 59 | 60 | myDir->cd("/home/"); 61 | std::cout << "Current Directory Path: " << myDir->getCurrentDirectoryPath() << std::endl; 62 | 63 | 64 | 65 | myDir->cdUp(); 66 | std::cout << "Current Directory Path: " << myDir->getCurrentDirectoryPath() << std::endl; 67 | 68 | 69 | 70 | myDir->cd("/home/root"); 71 | std::cout << "Current Directory Path: " << myDir->getCurrentDirectoryPath() << std::endl; 72 | 73 | 74 | 75 | // create file tree 76 | // |->dir1 77 | // |->dir1 78 | // |->dir2 79 | // |->dir3 80 | // |->dir1 81 | // |->dir2 82 | // |->dir4 83 | // |->dir2 84 | // |->dir3 85 | // |->dir4 86 | myDir->makeDirectory("dir1"); 87 | myDir->makeDirectory("dir1/dir1"); 88 | myDir->makeDirectory("dir1/dir2"); 89 | myDir->makeDirectory("dir1/dir3"); 90 | myDir->makeDirectory("dir1/dir3/dir1"); 91 | myDir->makeDirectory("dir1/dir3/dir2"); 92 | myDir->makeDirectory("dir1/dir4"); 93 | myDir->makeDirectory("dir2"); 94 | myDir->makeDirectory("dir3"); 95 | myDir->makeDirectory("dir4"); 96 | 97 | 98 | std::vector ls = myDir->getEntryList(BlackLib::BlackDirectory::IncludeHiddens, 99 | BlackLib::BlackDirectory::Directory, 100 | true); 101 | 102 | 103 | std::cout << "\n\nls after mkdir: " << std::endl; 104 | for( unsigned int i = 0 ; i removeDirectory("dir1",true); 112 | myDir->removeDirectory("dir2"); 113 | myDir->removeDirectory("dir3"); 114 | 115 | 116 | 117 | ls = myDir->getEntryList(BlackLib::BlackDirectory::IncludeHiddens, 118 | BlackLib::BlackDirectory::Directory, 119 | true); 120 | 121 | 122 | std::cout << "\n\nls after rmdir: " << std::endl; 123 | for( unsigned int i = 0 ; i exists("dir4") ) 130 | { 131 | myDir->renameDirectory("dir4","dir1"); 132 | } 133 | 134 | } 135 | 136 | 137 | 138 | #endif /* EXAMPLE_DIRECTORY_H_ */ 139 | -------------------------------------------------------------------------------- /v3_0/examples/example_threadAndMutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 EXAMPLE_THREADANDMUTEX_H_ 31 | #define EXAMPLE_THREADANDMUTEX_H_ 32 | 33 | 34 | 35 | #include "../BlackThread/BlackThread.h" 36 | #include "../BlackMutex/BlackMutex.h" 37 | #include 38 | #include 39 | 40 | 41 | int number; 42 | BlackLib::BlackMutex *myMutex; 43 | 44 | 45 | 46 | class Task1 : public BlackLib::BlackThread 47 | { 48 | public: 49 | void onStartHandler() 50 | { 51 | myMutex->lock(); 52 | std::cout << "Task1 doing the following operations: \n"; 53 | std::cout << "Global variable(number)\'s current value: \n"; 54 | for( int i = 0 ; i < 10 ; i++) 55 | { 56 | std::cout << ++number << " "; 57 | BlackLib::BlackThread::sleep(1); 58 | } 59 | std::cout << std::endl; 60 | myMutex->unlock(); 61 | } 62 | }; 63 | 64 | class Task2 : public BlackLib::BlackThread 65 | { 66 | public: 67 | void onStartHandler() 68 | { 69 | BlackLib::BlackThread::sleep(3); 70 | if( myMutex->tryLock() ) 71 | { 72 | std::cout << "Task2 doing the following operations: \n"; 73 | std::cout << "Global variable(number)\'s current value: \n"; 74 | for( int i = 0 ; i < 15 ; i++) 75 | { 76 | std::cout << --number << " "; 77 | BlackLib::BlackThread::sleep(1); 78 | } 79 | std::cout << std::endl; 80 | myMutex->unlock(); 81 | } 82 | else 83 | { 84 | std::cout << "Task2 couldn\'t lock the mutex. "; 85 | } 86 | } 87 | }; 88 | 89 | 90 | class Task3 : public BlackLib::BlackThread 91 | { 92 | public: 93 | void onStartHandler() 94 | { 95 | if( myMutex->timedLock(20) ) 96 | { 97 | std::cout << "Task3 doing the following operations: \n"; 98 | std::cout << "Global variable(number)\'s current value: \n"; 99 | for( int i = 0 ; i < 15 ; i++) 100 | { 101 | std::cout << ++number << " "; 102 | } 103 | std::cout << std::endl; 104 | myMutex->unlock(); 105 | } 106 | else 107 | { 108 | std::cout << "Task3 couldn\'t lock the mutex. "; 109 | } 110 | } 111 | }; 112 | 113 | 114 | class Task4 : public BlackLib::BlackThread 115 | { 116 | 117 | private: 118 | std::string myString; 119 | unsigned int tickTack; 120 | unsigned int currentLoop; 121 | bool goAhead; 122 | 123 | 124 | public: 125 | 126 | Task4(unsigned int tt) 127 | { 128 | this->tickTack = tt; 129 | this->myString = ""; 130 | this->currentLoop = 0; 131 | this->goAhead = true; 132 | } 133 | 134 | void onStartHandler() 135 | { 136 | while( this->goAhead ) 137 | { 138 | this->myString += "current loop is: " + BlackLib::tostr(this->currentLoop) + "\n"; 139 | this->currentLoop++; 140 | BlackLib::BlackThread::sleep(this->tickTack); 141 | } 142 | } 143 | 144 | void onPauseHandler() 145 | { 146 | this->goAhead = false; // exit from the while loop 147 | } 148 | 149 | void onResumeHandler() 150 | { 151 | this->myString += "my while loop is paused a short time ago.\n"; 152 | } 153 | 154 | void onStopHandler() 155 | { 156 | this->myString += "i am exitting from thread.\n"; 157 | } 158 | 159 | std::string getMessage() 160 | { 161 | return this->myString; 162 | } 163 | }; 164 | 165 | 166 | 167 | void example_threadAndMutex() 168 | { 169 | myMutex = new BlackLib::BlackMutex(); 170 | number = 0; 171 | 172 | Task1 *t1 = new Task1(); 173 | Task2 *t2 = new Task2(); 174 | Task3 *t3 = new Task3(); 175 | Task4 *t4 = new Task4(1); 176 | 177 | t1->run(); 178 | t2->run(); 179 | t3->run(); 180 | t4->run(); 181 | 182 | 183 | BlackLib::BlackThread::sleep(20); 184 | t4->pause(); 185 | 186 | 187 | bool conditionVariable = true; 188 | while( conditionVariable ) 189 | { 190 | if( t4->isFinished() ) 191 | { 192 | conditionVariable = false; 193 | std::cout << t4->getMessage(); 194 | } 195 | else 196 | { 197 | sleep(2); 198 | } 199 | } 200 | 201 | 202 | 203 | WAIT_THREAD_FINISH(t1) 204 | WAIT_THREAD_FINISH(t2) 205 | t3->waitUntilFinish(); 206 | t4->waitUntilFinish(); 207 | } 208 | 209 | #endif /* EXAMPLE_THREADANDMUTEX_H_ */ 210 | -------------------------------------------------------------------------------- /v3_0/examples/example_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | #################################################################################### 4 | # BlackLib Library controls Beaglebone Black's inputs and outputs. # 5 | # Copyright (C) 2013-2015 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 EXAMPLE_TIME_H_ 31 | #define EXAMPLE_TIME_H_ 32 | 33 | #include "../BlackTime/BlackTime.h" 34 | #include 35 | #include 36 | 37 | 38 | 39 | 40 | 41 | 42 | void example_time() 43 | { 44 | BlackLib::BlackTime *myTime = new BlackLib::BlackTime(10,20,30); 45 | 46 | std::cout << "Hour : " << myTime->getHour() << std::endl 47 | << "Minute: " << myTime->getMinute() << std::endl 48 | << "Second: " << myTime->getSecond() << std::endl; 49 | 50 | std::cout << myTime->toString("'Formatted myTime: ' hh:mm:ss") << std::endl; 51 | 52 | 53 | myTime->setTime(16,41,34); 54 | std::cout << myTime->toString("'Formatted myTime: ' hh:mm:ss") << std::endl << std::endl; 55 | 56 | 57 | 58 | myTime->addHour(5); 59 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl; 60 | 61 | myTime->addHour(-28); 62 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl; 63 | 64 | myTime->addHour(17); 65 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl << std::endl; 66 | 67 | 68 | 69 | 70 | 71 | myTime->setTime(16,41,34); 72 | 73 | 74 | 75 | myTime->addMinute(5); 76 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl; 77 | 78 | myTime->addMinute(-65); 79 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl; 80 | 81 | myTime->addMinute(20); 82 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl << std::endl; 83 | 84 | 85 | 86 | 87 | 88 | myTime->setTime(16,41,34); 89 | 90 | 91 | 92 | 93 | myTime->addSecond(5); 94 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl; 95 | 96 | myTime->addSecond( -1*(1*3600 + 10*60 + 9) ); 97 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl; 98 | 99 | myTime->addSecond(50); 100 | std::cout << myTime->toString("'Formatted time: 'hh:mm:ss") << std::endl << std::endl; 101 | 102 | 103 | 104 | 105 | 106 | myTime->setTime(16,41,34); 107 | 108 | 109 | 110 | std::cout << myTime->toString("'Formatted time : 'h:m:s") << std::endl; 111 | 112 | std::cout << myTime->toString("'12-hours system: 'hh-mm/ss ap") << std::endl; 113 | 114 | std::cout << myTime->toString("hh 'hours,' mm 'minutes, 'ss' seconds elapsed.\n'"); 115 | 116 | 117 | 118 | 119 | 120 | 121 | std::cout << "Current time: " << myTime->getCurrentTime().toString("hh.mm.ss") << std::endl; 122 | 123 | 124 | 125 | 126 | 127 | 128 | std::cout << "Example elapsed time in BlackTime: " 129 | << BlackLib::BlackTime::fromSecondToTime(37230).toString("hh 'hours, 'mm 'minutes, 'ss 'seconds.\n'"); 130 | 131 | std::cout << "Example elapsed time in seconds: " 132 | << BlackLib::BlackTime::fromTimeToSecond(*myTime); 133 | 134 | 135 | 136 | 137 | 138 | BlackLib::BlackTime myTime1(10,20,30); 139 | BlackLib::BlackTime myTime2(3,6,9); 140 | 141 | std::cout << "\nDifference1: " 142 | << (myTime1-myTime2).toString("hh 'hours, 'mm 'minutes, 'ss 'seconds.'"); 143 | std::cout << "\nDifference2: " 144 | << (myTime2-myTime1).toString("hh 'hours, 'mm 'minutes, 'ss 'seconds.'"); 145 | 146 | 147 | 148 | 149 | BlackLib::BlackTime tm; 150 | tm.start(); 151 | 152 | for( int i = 0 ; i <5000 ; i++ ) 153 | { 154 | usleep(100); 155 | } 156 | 157 | 158 | BlackLib::BlackTimeElapsed et = tm.restart(); 159 | 160 | std::cout << "\nelapsed hour :" << et.hour << std::endl 161 | << "elapsed minute :" << et.minute << std::endl 162 | << "elapsed second :" << et.second << std::endl 163 | << "elapsed msecond:" << et.miliSecond << std::endl 164 | << "elapsed usecond:" << et.microSecond << std::endl << std::endl; 165 | 166 | 167 | for( int i = 0 ; i <1000 ; i++ ) 168 | { 169 | usleep(100); 170 | } 171 | 172 | et = tm.elapsed(); 173 | 174 | std::cout << "elapsed hour :" << et.hour << std::endl 175 | << "elapsed minute :" << et.minute << std::endl 176 | << "elapsed second :" << et.second << std::endl 177 | << "elapsed msecond:" << et.miliSecond << std::endl 178 | << "elapsed usecond:" << et.microSecond << std::endl; 179 | 180 | 181 | 182 | } 183 | 184 | 185 | 186 | #endif /* EXAMPLE_TIME_H_ */ 187 | -------------------------------------------------------------------------------- /v3_0/makefile: -------------------------------------------------------------------------------- 1 | CXX=arm-linux-gnueabi-g++ 2 | 3 | INCLUDES=-I/usr/arm-linux-gnueabi/include/c++/4.6.3 4 | 5 | CPPFLAGS=-D__GXX_EXPERIMENTAL_CXX0X__ -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 6 | 7 | CXXFLAGS=-std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 -pthread $(CPPFLAGS) $(INCLUDES) 8 | 9 | LDFLAGS=-lpthread 10 | 11 | LDLIBS=-L/usr/arm-linux-gnueabi/lib 12 | 13 | RM=rm -f 14 | 15 | SOURCES=./BlackADC/BlackADC.cpp ./BlackDirectory/BlackDirectory.cpp ./BlackGPIO/BlackGPIO.cpp ./BlackI2C/BlackI2C.cpp ./BlackMutex/BlackMutex.cpp ./BlackPWM/BlackPWM.cpp ./BlackSPI/BlackSPI.cpp ./BlackThread/BlackThread.cpp ./BlackTime/BlackTime.cpp ./BlackUART/BlackUART.cpp ./BlackCore.cpp ./examples.cpp 16 | 17 | OBJECTS=$(SOURCES:.cpp=.o) 18 | 19 | EXECUTABLE=BlackLib-executable 20 | 21 | 22 | all: $(SOURCES) $(EXECUTABLE) 23 | 24 | $(EXECUTABLE): $(OBJECTS) 25 | $(CXX) $(LDLIBS) $(OBJECTS) $(LDFLAGS) -o $@ 26 | 27 | .cpp.o: 28 | $(CXX) $(CXXFLAGS) $< -o $@ 29 | 30 | clean: 31 | $(RM) $(OBJECTS) 32 | 33 | --------------------------------------------------------------------------------