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
/**
* 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) {