- Timestamp:
- 07/03/12 09:44:13 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/InterlockArduino/src/webserver/webserver.ino
r14159 r14252 39 39 #include <SPI.h> 40 40 #include <Ethernet.h> 41 #define BUF_LEN 25642 41 43 42 // inputs 44 int IL_ON = 4; 45 int FL_OK = 5; 46 int FC_OK = 6; 47 int FP_EN = 7; 43 int FC_OK = 2; 44 int BP_ON = 3; 45 46 int IL_ON = 14; 47 int FL_OK = 15; 48 int FP_EN = 16; 49 int X_ON = 17; 50 int Y_ON = 18; 51 int Z_OK = 19; 52 53 int my_inputs[] = {FC_OK, BP_ON, IL_ON, FL_OK, FP_EN, X_ON, Y_ON, Z_OK}; 54 char * my_input_names[] = {"FC_OK", "BP_ON", "IL_ON", "FL_OK", "FP_EN", "X_ON", "Y_ON", "Z_OK"}; 55 48 56 // outputs 49 int FC_ON = 2; 50 int FC_OFF = 3; 57 int FC_ON = 4; 58 int FC_OFF = 5; 59 int X = 6; 60 int Y = 7; 61 51 62 52 63 unsigned long last_time = millis(); … … 55 66 unsigned int fc_off_time = 0;// time in ms, for FC_OFF to be HIGH 56 67 57 byte mac[] = { 0xFA, 0xC7, 0xFC, 0xB1, 0x00, 0x01 }; 58 IPAddress ip(129,217,160,65); 68 //byte mac[] = { 0xFA, 0xC7, 0x0F, 0xAD, 0x22, 0x01 }; // ETHZ 69 byte mac[] = { 0xFA, 0xC7, 0xFC, 0xB1, 0x00, 0x01 }; // TUDO 70 59 71 60 72 // Initialize the Ethernet server library … … 63 75 EthernetServer server(80); 64 76 65 // ethernet receive buffer 66 67 char eth_rx_buf[BUF_LEN]; 68 unsigned int eth_rd = 0; 69 unsigned int eth_wr = 0; 70 byte eth_buff_full = false; 71 77 78 boolean x_signal = false; 79 boolean y_signal = false; 72 80 73 81 … … 82 90 83 91 // start the Ethernet connection and the server: 84 Ethernet.begin(mac , ip);92 Ethernet.begin(mac); 85 93 server.begin(); 86 94 Serial.print("server is at "); 87 95 Serial.println(Ethernet.localIP()); 88 96 89 pinMode( IL_ON, INPUT ); 90 pinMode( FL_OK, INPUT ); 91 pinMode( FC_OK, INPUT ); 92 pinMode( FP_EN, INPUT ); 97 // Enable ATmega Pullups 98 for (int i = 0 ; i<8; i++) 99 { 100 digitalWrite(my_inputs[i], HIGH); 101 } 102 103 93 104 94 105 pinMode( FC_ON, OUTPUT ); 95 106 pinMode( FC_OFF,OUTPUT ); 107 pinMode( X, OUTPUT ); 108 pinMode( Y,OUTPUT ); 96 109 97 110 } … … 139 152 get_http_found = true; 140 153 if (eth.indexOf(String("D2on=")) !=-1){ 141 Serial.println(" found D2on");142 digitalWrite( 2, HIGH);154 Serial.println("User request: Enable Pump"); 155 digitalWrite( FC_ON, HIGH); 143 156 fc_on_time = 3000; 144 157 } 145 146 if (eth.indexOf(String("D2off=")) !=-1) 158 else if (eth.indexOf(String("D2off=")) !=-1) 147 159 { 148 Serial.println(" found D2off");149 digitalWrite( 3, HIGH);160 Serial.println("User request: Disable Pump"); 161 digitalWrite( FC_OFF, HIGH); 150 162 fc_off_time = 500; 151 163 } 164 else if (eth.indexOf(String("toggle_x=")) !=-1) 165 { 166 Serial.println("User request: Toggle X"); 167 x_signal = !x_signal; 168 digitalWrite( X, x_signal ); 169 } 170 else if (eth.indexOf(String("toggle_y=")) !=-1) 171 { 172 Serial.println("User request: Toggle Y"); 173 y_signal = !y_signal; 174 digitalWrite( Y, y_signal ); 175 } 176 else 177 { 178 Serial.println("No User request - just sending webpage"); 179 } 152 180 153 Serial.println("found it");181 //Serial.println("found it"); 154 182 } 155 183 } … … 198 226 199 227 // add a meta refresh tag, so the browser pulls again every 5 seconds: 200 client->print("<meta http-equiv=\"refresh\" content=\" 5\">");228 client->print("<meta http-equiv=\"refresh\" content=\"1 URL=index.html\">"); 201 229 202 230 client->println("<title>FACT camera power interlock control</title></head><body>"); … … 239 267 } 240 268 269 270 271 void send_my_inputs( EthernetClient *client) 272 { 273 for (int ch = 0; ch < 8; ch++) 274 { 275 client->print(my_input_names[ch]); 276 client->print(" :"); 277 client->print(my_inputs[ch]); 278 client->print(" is "); 279 if ( digitalRead(my_inputs[ch]) ) 280 { 281 client->print("<font color=\"green\" size=20>HIGH</font>"); 282 } 283 else 284 { 285 client->print("<font color=\"red\" size=20>LOW</font>"); 286 } 287 client->println("<br />"); 288 } 289 } 290 291 292 241 293 void html_page( EthernetClient *client) 242 294 { 243 client->println("<P><INPUT TYPE=SUBMIT NAME=\"D2on\" VALUE=\"Enable Pump\"></P> Switches D2 HIGH for 3 seconds <br />"); 244 client->println("<P><INPUT TYPE=SUBMIT NAME=\"D2off\" VALUE=\"Disable Pump\"></P> Switches D3 HIGH for 0.5 seconds <br />"); 245 246 send_dig_ins( client ); 295 client->println("<P><INPUT TYPE=SUBMIT NAME=\"D2on\" VALUE=\"Enable Pump\"> --> FC_ON HIGH for 3 seconds <br />"); 296 client->println("<P><INPUT TYPE=SUBMIT NAME=\"D2off\" VALUE=\"Disable Pump\">--> FC_OFF HIGH for 0.5 seconds <br />"); 297 client->println("<P><INPUT TYPE=SUBMIT NAME=\"toggle_x\" VALUE=\"Toggle X\">--> ... well it toggles X <br />"); 298 client->println("<P><INPUT TYPE=SUBMIT NAME=\"toggle_y\" VALUE=\"Toggle Y\">--> ... well it toggles Y <br />"); 299 300 // send_dig_ins( client ); 301 send_my_inputs( client ); 247 302 248 303 //send_ana_outs_example( client ); … … 260 315 Check_n_Set_FC_ON_OFF() 261 316 { 262 Serial.print("FC ON TIME");263 Serial.println(fc_on_time);264 Serial.print("FC OFF TIME");265 Serial.println(fc_off_time);317 // Serial.print("FC ON TIME"); 318 // Serial.println(fc_on_time); 319 // Serial.print("FC OFF TIME"); 320 // Serial.println(fc_off_time); 266 321 267 322 unsigned long since_last = millis() - last_time; … … 321 376 ///////////////////////////////////////////////////////////////////////////////////////////// 322 377 323 324 ///////////////Ethernet input buffer////////////////////////////////////////////////////////325 int eth_buf_add(char c)326 {327 if (!eth_buff_full)328 {329 eth_rx_buf[eth_wr] = c;330 eth_wr = (eth_wr+1)%BUF_LEN;331 if (eth_wr == eth_rd) // buffer full332 {333 eth_buff_full = true;334 }335 return true;336 }337 else338 {339 return false;340 }341 }342 343 inline int eth_len()344 {345 return (eth_wr-eth_rd) % BUF_LEN;346 }347 348 char * buf[16];349 350 351 352 353 354 /////////////////////////////////////////////////////////////////////////////////////////////355
Note:
See TracChangeset
for help on using the changeset viewer.