Skip to content

Commit

Permalink
cgi scripts added
Browse files Browse the repository at this point in the history
  • Loading branch information
derekmolloy committed Jul 7, 2018
1 parent d7ea616 commit 89b99cc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
Binary file modified chp09/dcmotor/DCApp
Binary file not shown.
3 changes: 2 additions & 1 deletion chp09/dcmotor/DCMotorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* directory for copyright and GNU GPLv3 license information. */

#include <iostream>
#include <unistd.h>
#include "motor/DCMotor.h"
using namespace std;
using namespace exploringBB;

int main(){
cout << "Starting EBB DC Motor Example" << endl;
DCMotor dcm(new PWM("pwm_test_P9_42.12"), 116); //will export GPIO116
DCMotor dcm(new PWM("pwmchip0/pwm-0:0/"), 116); //will export GPIO116
dcm.setDirection(DCMotor::ANTICLOCKWISE);
dcm.setSpeedPercent(50.0f); //make it clear that a float is passed
dcm.go();
Expand Down
10 changes: 10 additions & 0 deletions chp11/cgi-bin/temperature.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
printf "Content-type: text/html\n\n"
printf "<html><head>"
printf "<meta charset=\"UTF-8\">"
printf "<title>Beagle Board Temperature</title></head>"
printf "<body><h1>Beagle Board Temperature</h1><para>"
printf "The temperature in the room is "
/usr/local/bin/tmp36raw
printf " degrees Celsius</para></html>"

11 changes: 11 additions & 0 deletions chp11/cgi-bin/test.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
printf "Content-type: text/html\n\n"
printf "<html><head>"
printf "<meta charset=\"UTF-8\">"
printf "<title>Hello Beagle Board</title></head>"
printf "<body><h1>Hello Beagle Board</h1><para>"
hostname
printf " has been up "
uptime
printf "</para></html>"

Binary file added chp11/tmp36adc/tmp36raw
Binary file not shown.
33 changes: 33 additions & 0 deletions chp11/tmp36adc/tmp36raw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;

#define ADC_PATH "/sys/bus/iio/devices/iio:device0/in_voltage"
#define ADC 0

float getTemperature(int adc_value) { // from the TMP36 datasheet
float cur_voltage = adc_value * (1.80f/4096.0f); // Vcc = 1.8V, 12-bit
float diff_degreesC = (cur_voltage-0.75f)/0.01f;
return (25.0f + diff_degreesC);
}

int readAnalog(int number){
stringstream ss;
ss << ADC_PATH << number << "_raw";
fstream fs;
fs.open(ss.str().c_str(), fstream::in);
fs >> number;
fs.close();
return number;
}

int main(){
//std::cout << "Starting the TMP36 example" << std::endl;
//std::cout << "The ADC value input is: " << readAnalog(ADC) << endl;
float temp = getTemperature(readAnalog(ADC));
float fahr = 32 + ((temp * 9)/5); // convert deg. C to deg. F
//cout << "Temperature is " << temp << "°C (" << fahr << "°F)" << endl;
cout << temp;
}

0 comments on commit 89b99cc

Please sign in to comment.