4 Relay relay Cape 'c' code

Hey Sir,

Yep. I will test out this C source soon. I guess you are right. It boils down to what I want. I mean, if you wanted it and I did not, I guess I would be wasting my time using it. W/ that typed out, I would like to use your library.

Should I put where I got the library in my source if used?

Seth

P.S. For instance, should I reference each of your names from the github page or can I just put https://github.com/shabaz123/iobb in the source?

Hi Seth,

Exactly that, it’s just an option to consider or rule out, for this or a future project.
It’s pretty open, only limits liability. It can be used in commercial or open source projects, and can be distributed in binary or source form, provided the text below is placed somewhere.
As far as I know, it was used in a product, and it was used for an academic paper:

Copyright © 2015, Shabaz, VegetableAvenger
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

  • Neither the name of BBBIOlib, iobb, libiobb nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Snabaz,

If I want to simply control a relay 1. Tthis simple ‘c’ would work

–Start Code–
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
int fd = open( “/sys/class/gpio/gpio20/value”, O_RDWR | O_CLOEXEC ); // Relay 1
if( fd < 0 ) {
fprintf( stderr, “open: %m\n” );
exit(1);
}

char c = ‘0’; // 0 = off, 1 == on
write( fd, &c, 1 );
close( fd );

return 0;
}
–End Code–

Being away from ‘c’ for some time I would like to add 2
command line arguments. Example command 1 20
where as command 1 30 would fail.

  1. 0 or 1 for on or off
  2. gpio # 20, 7,112 and 115. And validate input was 20, 7, 112 or 115.

If you want more control on, off, state, label this bash script will do it

–Start Code–
#!/bin/bash

Hi Ken,

That code looks like it would work. If you want to have command line arguments, the
int main(void)
gets replaced by something like:
int main(int argc, char** argv)
and then you can inspect the argc value to see the number of arguments, and the text for each argument will be pointed to by the array of pointers argv.
However, personally I find that once you start wanting more than the most basic command line, then it’s sometimes better to bite the bullet and use a command line library, rather than manually try to read and parse the arguments.
An easy-to-use one is called argp. Others may have different favorites.
I’m curious what the reason is to use C though, if the bash script works. Python is preferable to C sometimes too.
Depending on how much lily-guilding is needed, another feature could be some mapping between friendly names and GPIO names, in (say) a JSON file.
So, then the command to switch on one relay could be: relay mylamp 1
That’s incidentally easier in Python, because it’s easy to read config files and write them, and so on. But if you’ve already got working code, it can be better to use that sometimes too.

shabaz,

To be honest during my working carrier I only used ‘C’, Basic, Fortran, Cobol and bash.

At this point in my life I don’t really want to learn something new like Perl or Python unless
I have to. My eyes are not what they used to be. Also, if you write in pure ‘C’ isn’t it more
portable without the need for libraries which some day may not be there. Perhaps some
day I will try and learn Python.

Hardware I worked on was DEC PDP-11/70’s, Tandem Non-Stop, Motorola Unix on
Mc68010 machines, HP 9000 servers and various versions of Linux, Ubuntu, Debian,
Linux Mint LMDE4 and Linux Light…

I have gotten to the point of making portable scripts to install all the required software
on my Linux platforms which I run under Oracle VirtualBox. They install the usual
applications, development tools and local code. They are written in bash.

My memory is “swelled” with all this stuff.

Ken

Hi Ken,

I can understand, that makes sense.

Also, that’s quite a variety of interesting machines.

shabaz,

All that old hardware is gone now… You or other users may find
the attached information useful. No copyright. Free to use.

If interested send me some feedback.

Thanks,
Ken

pdp8i-3p.jpg

RTL8188EUS-Realtek-2.pdf (422 KB)

ssh-to-beaglebone-black-over-usb.pdf (731 KB)

relay_cape_pins-2.txt (164 Bytes)

connmanctl - Connman CLI - man page _ ManKier (2020-02-10 11_32_13 AM).html (26.7 KB)

Relay_Cape_sch.pdf (115 KB)

RLYCPE-BBBCAPE_Web.pdf (69.9 KB)

pkgs (1.66 KB)

vnc-notes (1.32 KB)

wifi-notes (543 Bytes)

startvnc (195 Bytes)

relay (1.46 KB)

cal.sh (291 Bytes)

disablecloud9 (421 Bytes)

disablenodered (149 Bytes)

Banner2.c (6.49 KB)

Unified Install.txt (9.14 KB)