/*
* Web Server - for the FACT lid slow control
* Need an Ethernet Shield over Arduino.
*
* based on the work of
* Martyn Woerner
* Alessandro Calzavara, alessandro(dot)calzavara(at)gmail(dot)com
* and Alberto Capponi, bebbo(at)fast-labs net
* for Arduino community! :-)
*
*
*/
#include
#include
#include
#include "ShutterController.h"
#define USE_DHCP_FOR_IP_ADDRESS
#define ENABLE_ETHERNET
#define SAMPLES 100
// Define MAC and IP addresses
byte _mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x5C, 0x91 };
//byte _mac[] = { 0x80, 0x49, 0x71, 0x0f, 0x80, 0xd0 };
#if !defined USE_DHCP_FOR_IP_ADDRESS
// ip represents the fixed IP address to use if DHCP is disabled.
IPAddress _ip(10,0,100,36);
#endif
//
// Each value is the real current value in the motors;
// Define Current Limits in [A] - Offset is 0.5A for no load on the motors
// pushing coefficient ~100 Kg/A
const double _ZeroCurrent PROGMEM = 0.25; // [A]
const double _CurrentPushingLimit PROGMEM = 0.75; // 0.7-0.5 = 0.2 -> 20 +/- 5 kg
const double _OverCurrent PROGMEM = 1.50; // 1.5-0.5 = 1 -> 100 +/- 5 kg
const int _StartPoint = 0;
const int _StartPointLimit = 70;
const int _EndPoint = 1024;
const int _EndPointLimit = 775; // This must me 740 for the mockup and >770 for the FACT shutter
// Define Lid Status levels and labels
const int _UNKNOWN = 0;
const int _CLOSED = 1;
const int _OPEN = 2;
const int _STEADY = 3;
const int _MOVING = 4;
const int _CLOSING = 5;
const int _OPENING = 6;
const int _JAMMED = 7;
const int _MOTOR_FAULT = 8;
const int _POWER_PROBLEM = 9;
const int _OVER_CURRENT = 10;
const char* _StatusLabel[] = {"Unknown",
"Closed",
"Open",
"Steady",
"Moving",
"Closing",
"Opening",
"Jammed",
"Motor Fault",
"Power Problem",
"Overcurrent"};
// Define Arduino pins
const int _pinPWM[2] = {5, 6};
const int _pinDA[2] = {2, 7};
const int _pinDB[2] = {3, 8};
//unsigned char _ENDIAG[2] = {A4, A5};
// Define conversion coefficients
double _ADC2V = 5. / 1024. ; // ADC channel to Volt
double _V2A = 0.140; // 140 mV/A conversion factor for the
// Define sensor value and lid status variables
double _sensorValue[2] = {0,0};
double _currentValue[2] = {0,0};
uint8_t _LidStatus[2] = {0,0};
extern int __bss_end;
extern void *__brkval;
// Http header token delimiters
char *pSpDelimiters = " \r\n";
char *pStxDelimiter = "\002"; // STX - ASCII start of text character
/**********************************************************************************************************************
* Strings stored in flash of the HTML we will be transmitting
***********************************************************************************************************************/
// HTTP Request message
prog_char content_404[] PROGMEM = "HTTP/1.1 404 Not Found\nServer: arduino\nContent-Type: text/html\n\n"
"Arduino Web Server - Error 404"
"Error 404: Sorry, that page cannot be found!
";
PROGMEM const char *page_404[] = { content_404 }; // table with 404 page
// HTML Header for pages
const prog_char content_main_header[] PROGMEM= "HTTP/1.0 200 OK\nServer: arduino\nCache-Control: no-store, no-cache, must-revalidate\n"
"Pragma: no-cache\nConnection: close\nContent-Type: text/html\n";
const prog_char content_main_top[] PROGMEM = "Arduino Web Server"
""
"Arduino Web Server
";
const prog_char content_main_menu[] PROGMEM = "";
const prog_char content_main_footer[] PROGMEM = "";
PGM_P contents_main[] PROGMEM = { content_main_header, content_main_top, content_main_menu, content_main_footer }; // table with 404 page
#define CONT_HEADER 0
#define CONT_TOP 1
#define CONT_MENU 2
#define CONT_FOOTER 3
// Page 1
const PROGMEM prog_char http_uri1[] = "/";
const PROGMEM prog_char content_title1[] = "Shutter Lid Control - Beta
";
#ifdef DEBUG
// To Be Fixed
const PROGMEM prog_char content_page1[] = "
";
#else
const PROGMEM prog_char content_page1[] = "
";
//