Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Rewriting your code like this should help

Thank you...
That has given me confidence that I am going in the right direction :)

There's a definition issue on read_file but that is unused so I have commented it out to test it. As I expected, but cannot explain, your code works as expected provided the GPIO is already exported. Your export code doesn't work and fails with Could not open /sys/class/gpio/gpio20/direction: Permission denied at afoken.pl line 12.

The module I am creating has the same issue. In it's constructor I am exporting the two GPIO pins - except I cannot do it by writing to the psuedo files. The only way I have found thus far is a system call to the gpio utility.

package Curtains::Control; use strict; my $path = '/sys/class/gpio'; my $o_pin = 20; my $c_pin = 21; sub new { # open my $export, '>', "$path/export" or die("Unable to export the + control pins"); # print $export "$o_pin\n"; # print $export "$c_pin\n"; # close $export; system("gpio export $o_pin high"); system("gpio export $c_pin high"); my $state = { STATE => 'UNKNOWN', }; return bless $state; }
If I uncomment the four lines at the start of sub new, then it works if the GPIO pins are already exported. This bit of code does not export them although I do not get an error here. I get an error further down the line when I try to change them. Making the system calls works well because I can initialise the state at the same time but I was still wanting to avoid system if I could...
Perhaps that will be a later update to the software!


In reply to Re^13: Controlling USB on Raspberry Pi by Bod
in thread Controlling USB on Raspberry Pi by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found