From: Jeremy Tan Date: Sun, 6 Oct 2013 03:58:54 +0000 (+0800) Subject: Bugfix for pin code and remove unused luts X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=66df642416e00b7f5a84e14c001ce03dfd1930ea;p=matches%2FMCTX3420.git Bugfix for pin code and remove unused luts --- diff --git a/server/Makefile b/server/Makefile index 244490b..f3992c8 100644 --- a/server/Makefile +++ b/server/Makefile @@ -2,7 +2,7 @@ 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 diff --git a/server/bbb_pin.c b/server/bbb_pin.c index 7248c5a..7d500dd 100644 --- a/server/bbb_pin.c +++ b/server/bbb_pin.c @@ -55,6 +55,32 @@ static PWM_Pin g_pwm[PWM_NUM_PINS] = {{0}}; 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 diff --git a/server/bbb_pin_defines.c b/server/bbb_pin_defines.c deleted file mode 100644 index d558993..0000000 --- a/server/bbb_pin_defines.c +++ /dev/null @@ -1,55 +0,0 @@ -#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 diff --git a/server/bbb_pin_defines.h b/server/bbb_pin_defines.h index 868636b..2eb2d08 100644 --- a/server/bbb_pin_defines.h +++ b/server/bbb_pin_defines.h @@ -123,7 +123,6 @@ #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]; @@ -156,15 +155,9 @@ 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 diff --git a/server/pin_test.c b/server/pin_test.c index 2ef0612..b22cc13 100644 --- a/server/pin_test.c +++ b/server/pin_test.c @@ -175,7 +175,7 @@ void Pin_Handler(FCGIContext *context, char * params) } 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; @@ -201,7 +201,7 @@ void Pin_Handler(FCGIContext *context, char * params) 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); } diff --git a/testing/MCTXWeb/README.txt b/testing/MCTXWeb/README.txt new file mode 100644 index 0000000..a25342b --- /dev/null +++ b/testing/MCTXWeb/README.txt @@ -0,0 +1,7 @@ +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 diff --git a/testing/MCTXWeb/public_html/static/mctx.gui.js b/testing/MCTXWeb/public_html/static/mctx.gui.js index 8c6da7a..9d0270b 100644 --- a/testing/MCTXWeb/public_html/static/mctx.gui.js +++ b/testing/MCTXWeb/public_html/static/mctx.gui.js @@ -1,5 +1,11 @@ /** * 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 = {}; @@ -14,7 +20,7 @@ mctx.has_control = false; mctx.statusCodes = { STATUS_OK : 1 -} +}; mctx.statusCodesDescription = { "1" : "Ok", @@ -45,18 +51,28 @@ mctx.strain_gauges = {}; 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()); } @@ -143,6 +159,7 @@ $.fn.populateNavbar = function () { /** * Sets the camera autoupdater + * Obsolete? * @returns {$.fn} */ $.fn.setCamera = function () { @@ -172,6 +189,10 @@ $.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; @@ -204,6 +225,9 @@ $.fn.setStrainGraphs = function () { 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(); @@ -215,7 +239,7 @@ $.fn.login = function () { out.removeAttr("class"); out.text("Logging in..."); - $.ajax({ + return $.ajax({ url : mctx.api + "bind", data : {user: username, pass : password} }).done(function (data) { @@ -237,16 +261,25 @@ $.fn.login = function () { }); }; +/** + * 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; @@ -257,16 +290,17 @@ $.fn.setErrorLog = function () { 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) {