CXX = gcc
FLAGS = -std=c99 -Wall -pedantic -g -I/usr/include/opencv -I/usr/include/opencv2/highgui -L/usr/lib
LIB = -lfcgi -lssl -lcrypto -lpthread -lm -lopencv_highgui -lopencv_core -lopencv_ml -lopencv_imgproc -lldap -lcrypt
-OBJ = log.o control.o data.o fastcgi.o main.o sensor.o actuator.o image.o bbb_pin.o bbb_pin_defines.o pin_test.o login.o
+OBJ = log.o control.o data.o fastcgi.o main.o sensor.o actuator.o image.o bbb_pin.o pin_test.o login.o
RM = rm -f
BIN = server
static char g_buffer[BUFSIZ] = {0};
+/**
+ * Maps a GPIO number to an index into g_gpio (only for use in bbb_pin.c)
+ * If there is no index for that GPIO number, 128 is returned.
+ */
+const unsigned char g_pin_gpio_to_index[GPIO_MAX_NUMBER+1] = {
+ 128, 128, 128, 128, 0, 1, 128, 128, 2, 3, 4, 5, 128, 128,
+ 6, 7, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 8, 9,
+ 128, 128, 10, 11, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 12, 13, 14, 15, 16, 17, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 18, 19, 128, 128, 128, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 128, 128,
+ 128, 128, 37, 38, 39, 40, 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+ 41, 128, 128, 42
+};
+
+/**
+ * Maps an index in g_gpio to the corresponding GPIO number.
+ */
+const unsigned char g_pin_index_to_gpio[GPIO_NUM_PINS] = {
+ 4, 5, 8, 9, 10, 11, 14, 15, 26, 27, 30, 31, 44, 45,
+ 46, 47, 48, 49, 60, 61, 65, 66, 67, 68, 69, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, 81, 86, 87, 88, 89, 112,
+ 115
+};
+
/**
* Export a GPIO pin and open the file descriptors
* @param pin The GPIO number to be exported
+++ /dev/null
-#include "bbb_pin_defines.h"
-
-/* Luts and stuff. Yay magic numbers **/
-
-/**
- * A lookup table from the actual pin number to GPIO number.
- * e.g P8_13 is g_pin_real_to_gpio[0*46+13] = g_pin_real_to_gpio[13]
- * e.g P9_13 is g_pin_real_to_gpio[1*46+13] = g_pin_real_to_gpio[59]
- *
- * Where the returned value is 0, there is no GPIO pin
- * at that location.
- */
-const unsigned char g_pin_real_to_gpio[BBB_PIN_COUNT+1] = {
- 0, 0, 0, 0, 0, 0, 0, 66, 67, 69, 68, 45, 44, 0,
- 26, 47, 46, 27, 65, 0, 0, 0, 0, 0, 0, 0, 61, 86,
- 88, 87, 89, 10, 11, 9, 81, 8, 80, 78, 79, 76, 77, 74,
- 75, 72, 73, 70, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 30, 60, 31, 0, 48, 0, 5, 4, 0, 0, 0, 0, 49,
- 15, 0, 14, 115, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/**
- * Maps a GPIO number to an index into g_gpio (only for use in bbb_pin.c)
- * If there is no index for that GPIO number, 128 is returned.
- */
-const unsigned char g_pin_gpio_to_index[GPIO_MAX_NUMBER+1] = {
- 128, 128, 128, 128, 0, 1, 128, 128, 2, 3, 4, 5, 128, 128,
- 6, 7, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 8, 9,
- 128, 128, 10, 11, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 12, 13, 14, 15, 16, 17, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 18, 19, 128, 128, 128, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 128, 128,
- 128, 128, 37, 38, 39, 40, 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
- 41, 128, 128, 42
-};
-
-/**
- * Maps an index in g_gpio to the corresponding GPIO number.
- */
-const unsigned char g_pin_index_to_gpio[GPIO_NUM_PINS] = {
- 4, 5, 8, 9, 10, 11, 14, 15, 26, 27, 30, 31, 44, 45,
- 46, 47, 48, 49, 60, 61, 65, 66, 67, 68, 69, 70, 71, 72,
- 73, 74, 75, 76, 77, 78, 79, 80, 81, 86, 87, 88, 89, 112,
- 115
-};
-
-/**
- * Converts PWM index to PWM number
- * e.g index 3 becomes 6 for /sys/class/pwm/pwm6
- */
-const unsigned char g_pin_safe_pwm[PWM_NUM_SAFE_PINS] = {
- 0, 2, 4, 6, 7
-}; //blergh
\ No newline at end of file
#define GPIO_MAX_NUMBER 115
/* Luts */
-extern const unsigned char g_pin_real_to_gpio[BBB_PIN_COUNT+1];
extern const unsigned char g_pin_gpio_to_index[GPIO_MAX_NUMBER+1];
extern const unsigned char g_pin_index_to_gpio[GPIO_NUM_PINS];
/** Number of PWM pins **/
#define PWM_NUM_PINS 8
-/** Number of PWM pins which are guaranteed not to interfere with one another **/
-#define PWM_NUM_SAFE_PINS 5
-
/** Path to PWM sysfs **/
#define PWM_DEVICE_PATH "/sys/class/pwm"
-/** Maps internal pin number to safe 'pwmX' number **/
-extern const unsigned char g_pin_safe_pwm[PWM_NUM_SAFE_PINS];
-
#endif //_BBB_PIN_DEFINES_H
}
else if (strcmp(type, "pwm") == 0)
{
- if (num < 0 || num >= PWM_NUM_SAFE_PINS)
+ if (num < 0 || num >= PWM_NUM_PINS)
{
FCGI_RejectJSON(context, "Invalid PWM pin");
return;
else
{
Log(LOGDEBUG, "Stopping PWM%d",num);
- PWM_Stop(g_pin_safe_pwm[num]);
+ PWM_Stop(num);
FCGI_PrintRaw("Content-type: text/plain\r\n\r\n");
FCGI_PrintRaw("PWM%d stopped",num);
}
--- /dev/null
+Uncomment the line with:
+
+mctx.debug = true
+
+In mctx.gui.js to prevent browser redirects and to enable debug messages.
+
+Debug messages are printed to the browser console. (Ctrl+Shift+K in Firefox)
\ No newline at end of file
<link rel="stylesheet" type="text/css" href="static/style.css">
<link rel="stylesheet" type="text/css" href="static/nav-menu.css">
<script type="text/javascript">
- runBeforeLoad().always(function () {
+ runBeforeLoad().done(function () {
$(document).ready(function () {
//Show the content!
$("#content").css("display", "block");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
- <title>BeagleBone Black Pin Test</title>
+ <title>MCTX3420 Web Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--[if lte IE 8]>
<script language="javascript" type="text/javascript" src="static/excanvas.min.js"></script>
<link rel="stylesheet" type="text/css" href="static/style.css">
<link rel="stylesheet" type="text/css" href="static/nav-menu.css">
<script type="text/javascript">
- $(document).ready(function () {
- $("#errorlog").setErrorLog();
- $("#gpio-menu").populateDropdown(mctx.pintest.gpios, "GPIO ");
- $("#pwm-menu").populateDropdown(mctx.pintest.pwms, "PWM ");
-
- $("#gpio-go").click(function () {
- if ($("#gpio-menu").val()) {
- $("#gpio-container").exportGPIO($("#gpio-menu"));
- }
- });
- $("#pwm-go").click(function () {
- if ($("#pwm-menu").val()) {
- $("#pwm-container").exportPWM($("#pwm-menu"));
- }
+ runBeforeLoad().done(function () {
+ //Ensure stuff is unloaded before leaving the page
+ $(window).unload(function(){
+ $("#adc-controls").find("input[type='checkbox']")
+ .each(function () {
+ if ($(this).is(":checked")) {
+ $(this).trigger("click");
+ }
+ });
+ $("#gpio-container").find("input[name='unexport']")
+ .each(function () {
+ $(this).trigger("click");
+ });
+ $("#pwm-container").find("input[name='unexport']")
+ .each(function () {
+ $(this).trigger("click");
+ });
});
- $("#adc-controls").trigger("reset").setADCControl();
- });
+
+ $(document).ready(function () {
+ //Set the welcome bar
+ var name = " " + (mctx.friendlyName ? mctx.friendlyName : "");
+ $("#welcome-container").text("Welcome"+ name + "!");
+ $("#content").css("display", "block");
+
+ $("#logout").click(function () {
+ $("#logout").logout();
+ });
+
+ $("#gpio-menu").populateDropdown(mctx.pintest.gpios, "GPIO ");
+ $("#pwm-menu").populateDropdown(mctx.pintest.pwms, "PWM ");
+
+ $("#gpio-go").click(function () {
+ if ($("#gpio-menu").val()) {
+ $(this).attr("disabled", true);
+ $("#gpio-container").exportGPIO($("#gpio-menu")).always(function () {
+ $("#gpio-go").attr("disabled", false);
+ });
+ }
+ });
+ $("#pwm-go").click(function () {
+ if ($("#pwm-menu").val()) {
+ $(this).attr("disabled", true);
+ $("#pwm-container").exportPWM($("#pwm-menu")).always(function () {
+ $("#pwm-go").attr("disabled", false);
+ });
+ }
+ });
+ $("#adc-controls").trigger("reset").setADCControl();
+
+ $("#errorlog").setErrorLog();
+ });
+ })
+
</script>
</head>
<img alt = "The University of Western Australia"
src="static/uwacrest-text.png">
</a>
- <span id="title">BBB pin test</span>
+ <span id="title">BBB Pin test (debug only)</span>
</div>
<div id="rightnav">
<div id="menu-container" class="nav-menu">
</div>
+ <span id="welcome-container">
+ </span>
<span id="date">
<script type="text/javascript">getDate();</script>
</span>
+ <div id="logout-container">
+ <form action="#">
+ <div>
+ <input type="button" id="logout" value="Logout">
+ </div>
+ </form>
+ </div>
</div>
<div class="clear"></div>
</div>
/**
* MCTX3420 2013 GUI stuff.
+ * Coding style:
+ * - Always end statements with semicolons
+ * - Egyptian brackets are highly recommended (*cough*).
+ * - Don't use synchronous stuff - hook events into callbacks
+ * - $.fn functions should return either themselves or some useful object
+ * to allow for chaining of method calls
*/
mctx = {};
mctx.statusCodes = {
STATUS_OK : 1
-}
+};
mctx.statusCodesDescription = {
"1" : "Ok",
mctx.strain_gauges.ids = [0, 1, 2, 3];
mctx.strain_gauges.time_limit = 20;
-function debugLog (msg) {
- if (typeof console === "undefined" || typeof console.log === "undefined") {
- alert(msg);
- } else {
- console.log(msg);
+/**
+ * Logs a message if mctx.debug is enabled. This function takes
+ * a variable number of arguments and passes them
+ * to alert or console.log (based on browser support).
+ * @returns {undefined}
+ */
+function debugLog () {
+ if (mctx.debug) {
+ if (typeof console === "undefined" || typeof console.log === "undefined") {
+ for (var i = 0; i < arguments.length; i++) {
+ alert(arguments[i]);
+ }
+ } else {
+ console.log.apply(this, arguments);
+ }
}
}
/**
* Writes the current date to wherever it's called.
*/
-function getDate(){
+function getDate() {
document.write((new Date()).toDateString());
}
/**
* Sets the camera autoupdater
+ * Obsolete?
* @returns {$.fn}
*/
$.fn.setCamera = function () {
return this;
};
+/**
+ * Sets the strain graphs to graph stuff. Obsolete?
+ * @returns {$.fn}
+ */
$.fn.setStrainGraphs = function () {
var sensor_url = mctx.api + "sensors";
var graphdiv = this;
return this;
};
+/**
+ * Performs a login attempt.
+ * @returns The AJAX object of the login request */
$.fn.login = function () {
var username = this.find("input[name='username']").val();
var password = this.find("input[name='pass']").val();
out.removeAttr("class");
out.text("Logging in...");
- $.ajax({
+ return $.ajax({
url : mctx.api + "bind",
data : {user: username, pass : password}
}).done(function (data) {
});
};
+/**
+ * Performs a logout request. The nameless cookie is
+ * always cleared and the browser redirected to the login page,
+ * independent of whether or not logout succeeded.
+ * @returns The AJAX object of the logout request.
+ */
$.fn.logout = function () {
- $.ajax({
+ return $.ajax({
url : mctx.api + "unbind"
}).always(function () {
//Note: this only clears the nameless cookie
document.cookie = "";
window.location = mctx.location + "login.html";
});
-}
+};
+/**
+ * Sets the error log to continuously update.
+ * @returns itself */
$.fn.setErrorLog = function () {
var url = mctx.api + "errorlog";
var outdiv = this;
outdiv.scrollTop(
outdiv[0].scrollHeight - outdiv.height()
);
- setTimeout(updater, 1000);
+ setTimeout(updater, 2000);
}).fail(function (jqXHR) {
if (jqXHR.status === 502 || jqXHR.status === 0) {
outdiv.text("Failed to retrieve the error log.");
}
- setTimeout(updater, 1500);
+ setTimeout(updater, 4000);
});
};
updater();
+ return this;
};
$(document).ajaxError(function (event, jqXHR) {
var number = menu.val();
var container = this;
- $.ajax({url : mctx.pintest.api, data : {type : "gpi", num : number, export : 1}})
+ return $.ajax({url : mctx.pintest.api, data : {type : "gpi", num : number, export : 1}})
.done(function () {
var form = $("<form/>", {"class" : "controls", action : "#", id : "gpio-" + number});
var title = $("<div/>", {"class" : "centre bold", text : "GPIO " + number});
alert("Failed to export GPIO " + number + ". Is the server running?\n" +
"Error code: " + jqXHR.status);
});
- return this;
};
$.fn.exportPWM = function(menu) {
var number = menu.val();
var container = this;
- $.ajax({url : mctx.pintest.api, data : {type : "pwm", num : number, export : "1"}})
+ return $.ajax({url : mctx.pintest.api, data : {type : "pwm", num : number, export : "1"}})
.done(function () {
var form = $("<form/>", {"class" : "controls", action : "#", id : "pwm-" + number});
var title = $("<div/>", {"class" : "centre bold", text : "PWM " + number});
alert("Failed to export PWM " + number + ". Is the server running?\n" +
"Error code: " + jqXHR.status);
});
- return this;
};
$.fn.setGPIOControl = function (number, menu) {
#content {
padding: 1em 2em;
- /* display: none; Enable in non-debug mode*/
+ /*display: none; Enable in non-debug mode*/
}
#sidebar{