embedded linux PWM – device or resource busy via /r/learnprogramming


embedded linux PWM – device or resource busy

Hello

I am trying to write software to generate a PWM-signal on the Jetson tegra k1 by following those steps:

 echo 57 > /sys/class/gpio/export echo 57 > /sys/class/gpio/unexport echo 1 > /sys/class/pwm/pwmchip0/export echo <period in ns> > /sys/class/pwm/pwmchip0/pwm1/period echo <period in ns> > /sys/class/pwm/pwmchip0/pwm1/duty_cycle echo 1 > echo <period in ns> > /sys/class/pwm/pwmchip0/pwm1/enable 

which are described here: http://ift.tt/2rVv9dY

But when I try to execute "echo 1 > /sys/class/pwm/pwmchip0/export" it returns

 bash: echo: write error: Device or resource busy 

I can see that in the .config file is activated: CONFIG_PWM_SYSFS=y

What am I doing incorrectly or missing?

Submitted May 31, 2017 at 07:05PM by aCuriousMind22
via reddit http://ift.tt/2qHtBzJ

Changing Coding for Fun via /r/learnprogramming


Changing Coding for Fun

Hi,

I'm very excited about everything in regards of programming, computers, design, videogames and else.

Since kid, I have been and I'm still being very interested. When I discover web developing, HTML, CSS, JS and more, I was so much into that. I started to learn everything I could. I stopped for a while because I had to learn some VB for Excel when I started to work, anyway everything was fun.

Now, I'm trying to push myself to do an hour of coding every day, or every week, or sometimes. No luck. I ended watching movies or playing videogames. Even though I have all the resources I need, I always find an excuse.

How do I avoid those things? I'm usually drinking or whatever. Is it like coding is not for me?

Submitted May 31, 2017 at 07:32PM by gniosdb
via reddit http://ift.tt/2rcSQ0g

CMakelists OpenCV via /r/learnprogramming


CMakelists OpenCV

cmake_minimum_required (VERSION 2.6) cmake_policy(SET CMP0012 NEW) PROJECT(gray_scale) FIND_PACKAGE(OpenCV 3.0.0 REQUIRED) MESSAGE("OpenCV version: ${OpenCV_Version}") include_directories(${OpenCV_INCLUDE_DIRS}) link_directories(${OpenCV_LIB_DIRS}) SET(SRC main.cpp) ADD_EXECUTABLE(${PROJECT_NAME} hello_world.cpp) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS}) 

I have a question about CMake because ite seems like a lot of magic is happening.

the variables ${OpenCV_INCLUDE_DIRS} ${OpenCV_LIB_DIRS} ${OpenCV_LIBS}

where do these come from?

Submitted May 31, 2017 at 07:33PM by HalcyonAbraham
via reddit http://ift.tt/2qHnc7I

Applying physics equations to Java object? via /r/learnprogramming


Applying physics equations to Java object?

I'm using a game-making program (which has an "act" method it executes each frame of your game) and want a flying object to thrust from side to side across the screen. It's initial speed is very high and then slows to normal, as the object turns to face its usual path (forwards). The object is accompanied by air resistance, so it overpowers the normal speed eventually if the object doesn't accelerate for a while.

My question is: how do I model these forces in the "act" method? If force is measured in Newtons, how do I set the movement to be based on Newtons in each frame? With a timer? By varying the amount of displacement?

TL;DR: how do I make physics forces act on an object (covert Newtons to programming language)?

Submitted May 31, 2017 at 06:50PM by thatwasdifficult
via reddit http://ift.tt/2rVGdaS

Are these two good times to use try/catch? (Java) via /r/learnprogramming


Are these two good times to use try/catch? (Java)

I have two assignments, and I thought it was appropriate to use try/catch. They both worked, but I heard it was bad practice to use it, so I was wondering if there's a better way to go about this.

The first one:

try{ int buttonValue = Integer.parseInt(temp.getText()); /* some code*/ } catch(NumberFormatException e1){ /* some more code */ } 

Basically I want to turn a String into an int, and if it doesn't work, then do something else.

The second one:

private void placeShip() { int r = (int) (Math.random() * 10); int c = (int) (Math.random() * 10); int direction = (int)(Math.random() * 4); try { if (direction == 0) generateNorth(r, c); else if (direction == 1) generateSouth(r, c); else if (direction == 2) generateEast(r, c); else generateWest(r, c); } catch (IndexOutOfBoundsException e) { for(int i = 0; i < matrix.length; i++) for(int k = 0; k < matrix[0].length; k++) matrix[i][k] = 0; placeShip(); } } 

Basically the assignment was a Battleship program, and I wrote this method to place the ship. If it places the ship out of bounds, then it just does it again until it works.

Using try/catch made these easier than I thought they would be, but I was wondering if there's a better way to do it.

Submitted May 31, 2017 at 05:57PM by Popopopper123
via reddit http://ift.tt/2rGkmVp