refactoring

This commit is contained in:
Romedius Weiss 2015-12-27 04:38:28 +01:00
parent 30ca356399
commit 145345a035
1 changed files with 18 additions and 67 deletions

85
ITS_Open_direct_2fb/ITS_Open_direct_2fb.ino Executable file → Normal file
View File

@ -1,27 +1,15 @@
/* /*
IT-Syndikat Open device Firmware for the wooden Device with two fat buttons
Arduino --> ThingTweet via Ethernet
The ThingTweet sketch is designed for the Arduino + Ethernet Shield.
This sketch updates a Twitter status via the ThingTweet App
(http://community.thingspeak.com/documentation/apps/thingtweet/) using HTTP POST.
ThingTweet is a Twitter proxy web application that handles the OAuth.
Getting Started with ThingSpeak and ThingTweet:
* Sign Up for a New User Account for ThingSpeak - https://www.thingspeak.com/users/new
* Link your Twitter account to the ThingTweet App - Apps / ThingTweet
* Enter the ThingTweet API Key in this sketch under "ThingSpeak Settings"
Arduino Requirements:
* Arduino with Ethernet Shield or Arduino Ethernet
* Arduino 1.0 IDE
* Twitter account linked to your ThingSpeak account
Network Requirements: Network Requirements:
* Ethernet port on Router * Ethernet port on Router
* DHCP enabled on Router * DHCP enabled on Router
* Unique MAC Address for Arduino * Unique MAC Address for Arduino
Created: October 17, 2011 by Hans Scharler (http://www.iamshadowlord.com)
Updated: December 7, 2012 by Hans Scharler (http://www.iamshadowlord.com)
Additional Credits: Additional Credits:
Example sketches from Arduino team, Ethernet by Adrian McEwen Example sketches from Arduino team, Ethernet by Adrian McEwen
Based on the Ethernet to Thingspeak exaple by Hans Scharler
*/ */
#include <SPI.h> #include <SPI.h>
@ -29,23 +17,20 @@ Example sketches from Arduino team, Ethernet by Adrian McEwen
#include "APIKey.h" #include "APIKey.h"
// Local Network Settings byte mac[] = { 0xD4, 0xBA, 0xD9, 0x9A, 0x7C, 0x95 }; // Must be unique on local network
//byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network
byte mac[] = { 0xD4, 0xBE, 0xD9, 0x9A, 0x7C, 0x95 }; // Must be unique on local network
// Initialize Arduino Ethernet Client // Initialize Arduino Ethernet Client
EthernetClient client; EthernetClient client;
// Twitter response variables // Twitter response variables
char serverName[] = "it-syndikat.org"; // twitter URL char serverName[] = "it-syndikat.org"; // URL
String currentLine = ""; // string to hold the text from server String currentLine = ""; // string to hold the text from server
// Specific variables // Specific variables
// Status // Status
int hsopen =2; int hsopen;
int ethernetstatus = -1; int ethernetstatus;
//debug options //debug options
boolean debug = true; boolean debug = true;
@ -54,19 +39,6 @@ boolean debug = true;
const int glight = 5; const int glight = 5;
const int rlight = 6; const int rlight = 6;
/*
const int ropen=5;
const int rwait=6;
const int rclosed=7;
const int runknown=8;
const int eok=A0;
const int efail=A1;
const int eunknown=A2;
*/
const int topen = 2; const int topen = 2;
const int tclose = 3; const int tclose = 3;
@ -78,19 +50,7 @@ void setup()
pinMode(glight, OUTPUT); pinMode(glight, OUTPUT);
pinMode(rlight, OUTPUT); pinMode(rlight, OUTPUT);
// Buttons with pullup resistor
/*
pinMode(ropen, OUTPUT);
pinMode(rwait, OUTPUT);
pinMode(rclosed, OUTPUT);
pinMode(runknown, OUTPUT);
pinMode(eok, OUTPUT);
pinMode(efail, OUTPUT);
pinMode(eunknown, OUTPUT);
*/
// Taster
pinMode(topen, INPUT); pinMode(topen, INPUT);
pinMode(tclose, INPUT); pinMode(tclose, INPUT);
digitalWrite(topen,HIGH); digitalWrite(topen,HIGH);
@ -102,12 +62,12 @@ void setup()
} }
// Start Ethernet on Arduino // Start Ethernet on Arduino
setEth(-1); setEth(-1);
setRoom(hsopen); setRoom(2);
startEthernet(); startEthernet();
delay(1000); delay(1000);
// Update Twitter via ThingTweet // Get current Status
TriggerServerReq(); TriggerServerReq();
} }
@ -166,11 +126,13 @@ void startEthernet()
void setLeds(){ void setLeds(){
switch(ethernetstatus){ switch(ethernetstatus){
case 0:{ // ethernet fail case 0:{ // ethernet fail
// should become blink red
analogWrite(rlight, 63); analogWrite(rlight, 63);
analogWrite(glight, 0); analogWrite(glight, 0);
break; break;
} }
case -1:{ // ethernet unknown case -1:{ // ethernet unknown
// should become fade green
analogWrite(rlight, 0); analogWrite(rlight, 0);
analogWrite(glight, 63); analogWrite(glight, 63);
break; break;
@ -188,11 +150,13 @@ void setLeds(){
break; break;
} }
case 2:{ // wait case 2:{ // wait
// should become fade red and green
analogWrite(rlight, 127); analogWrite(rlight, 127);
analogWrite(glight, 127); analogWrite(glight, 127);
break; break;
} }
case -1:{ // unknown case -1:{ // unknown
// should become fade red
analogWrite(rlight, 63); analogWrite(rlight, 63);
analogWrite(glight, 63); analogWrite(glight, 63);
break; break;
@ -212,25 +176,15 @@ void setEth(int statuss){
Serial.println(statuss); Serial.println(statuss);
} }
setLeds(); setLeds();
/*
digitalWrite(eok,((statuss==1)?HIGH:LOW));
digitalWrite(efail,((statuss==0)?HIGH:LOW));
digitalWrite(eunknown,((statuss==-1)?HIGH:LOW));
*/
} }
void setRoom(int statuss){ void setRoom(int statuss){
hsopen= statuss;
if(debug){ if(debug){
Serial.print("Setting room "); Serial.print("Setting room ");
Serial.println(statuss); Serial.println(statuss);
} }
setLeds(); setLeds();
/*
digitalWrite(ropen,((statuss==1)?HIGH:LOW));
digitalWrite(rwait,((statuss==2)?HIGH:LOW));
digitalWrite(rclosed,((statuss==0)?HIGH:LOW));
digitalWrite(runknown,((statuss==-1)?HIGH:LOW));
*/
} }
@ -298,16 +252,14 @@ int readServerStatus() {
// you've reached the end of the tweet: // you've reached the end of the tweet:
if(currentLine.startsWith("true", 0)){ if(currentLine.startsWith("true", 0)){
if(debug){Serial.println("");} if(debug){Serial.println("");}
hsopen=1; setRoom(1);
setRoom(hsopen);
// close the connection to the server: // close the connection to the server:
client.stop(); client.stop();
return 0; return 0;
} }
if(currentLine.startsWith("false", 0)){ if(currentLine.startsWith("false", 0)){
if(debug){Serial.println("");} if(debug){Serial.println("");}
hsopen=0; setRoom(0);
setRoom(hsopen);
// close the connection to the server: // close the connection to the server:
client.stop(); client.stop();
return 0; return 0;
@ -318,8 +270,7 @@ int readServerStatus() {
} }
} }
} }
hsopen=-1; setRoom(-1);
setRoom(hsopen);
client.stop(); client.stop();
} }