HomePage RecentChanges Rainbow House 4 TalkNotes

Misc

#!C
LightuinoSourceDriver src(SRC_CLOCK, SRC_DATA, SRC_STROBE, SRC_ENABLE);
LightuinoSink sinks(LU_CLOCK, LU_DATA1, LU_DATA2, LU_BRIGHT);
unsigned char 		light_status[11];

void deviceUpdate() {
	src.set( (unsigned int) light_status[10]);
	sinks.set(light_status);
}



void processTimeouts() {
	for (unsigned char i = 0; i < LIGHTS_NUM; i++) {
		if (lights_on[i] > 0 && (lights_on[i] < now())) {
			deviceOff(i);
		}
	}
	deviceDepends();
	deviceUpdate();
}




void doAction(unsigned char task, unsigned char *localGroup) {
	for (unsigned char groupPos = 1; groupPos <= localGroup[0]; groupPos++) {
		unsigned char device_id = localGroup[groupPos];
		switch(task) {
			case TASK_OFF:
				deviceOff(device_id); break; 
			case TASK_ON:
				deviceOn(device_id); break;
			case TASK_SWAP:
				deviceSwap(device_id); break;
			case TASK_OFF10:
				deviceFutureOff(device_id, now() + 10); break;
		};
	}
	deviceDepends();	deviceUpdate();
}

1


#include <Bounce.h>
#define HW_BUTTON_ALL_ON 9
#define HW_BUTTON_DELAY 50
Bounce buttonAllOn = Bounce( HW_BUTTON_ALL_ON, HW_BUTTON_DELAY ); 

void processButtons () {
	// Buttons pressed ?
	if (buttonAllOn.update() && buttonAllOn.read() == LOW) {
		for (unsigned char i = 0; i < LIGHTS_NUM; i++) 
			deviceSwap(i);
		deviceDepends();
		deviceUpdate();
	}
}


void processKeyboard () {
	if (keyboard.available()) {
		char c = keyboard.read();
		unsigned char pos = c;
		unsigned char thing_id = pgm_read_byte(&(configInputDevice[pos]));
		unsigned char singleGroup[2];
		unsigned char *localGroup;
		switch(pgm_read_byte(&(configInputThing[pos]))) {
			case TYPE_GROUP:
				localGroup = (unsigned char*)configGroup[thing_id];
				break;
			case TYPE_DEVICE:
				singleGroup[0] = 1;
				singleGroup[1] = thing_id;
				localGroup = singleGroup;
				break;
			default:
				singleGroup[0] = 0;
				localGroup = singleGroup;
				break;
		};
		doAction(pgm_read_byte(&(configInputTask[pos])), localGroup);
	}
}

Block

#!C
void loop() {
  if (processTime()) {
    if (now() % 10 == 0)  debugStatus();
    processTimeouts();
  }
  processButtons();
  processKeyboard();
  processServer();
}



Time

#!Perl
#!/usr/bin/perl
use LWP::Simple;
getprint "http://10.0.1.177/time/" . time;
#!C
#include <Time.h>
setTime(urlAction(URL, "/time/", client));
client.print(hour());
client.print(':');
client.print(minute());
client.print(':');
client.print(second());

Internet

#!C

#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 1, 177 };
Server server(80);

void setup() {
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
        Client client = server.available();
        if (client) {
                boolean current_line_is_blank = true;
                String URL(URL_LENGTH);
                while (client.connected()) {
                        if (client.available()) {
                                char c = client.read();
                                if (URL.length() < URL_LENGTH) 
                                        URL.append(c);

                                if (c == '\n' && current_line_is_blank) {
                                        client.println(getString(htmlData_head));
                                        client.println(getString(htmlData_htmlstart));

                                        // NOTE: Do no use getString here
                                        if (URL.contains("/on/")) {
                                                deviceOn(urlAction(URL, "/on/", client));
                                        }

                                        client.print(getString(htmlData_freemem));
                                        client.print(freeMemory(), DEC);
                                        client.println(getString(htmlData_end_p));

                                // TODO - Get the basic URL (GET ... HTTP/1.0\n)
                                if (c == '\n') {
                                        // we're starting a new line
                                        current_line_is_blank = true;
                                } else if (c != '\r') {
                                        // we've gotten a character on the current line
                                        current_line_is_blank = false;
                                }
                        }
                }
                // give the web browser time to receive the data
                delay(1);
                client.stop();
                URL = "";
        }
}

unsigned long urlAction(String URL, String find, Client client) {
        int istart = URL.indexOf(find);
        int iend = URL.indexOf(" HTTP");
        unsigned long r = atol(URL.substring(istart+find.length(), iend));
        client.print(getString(htmlData_request));
        client.print(find);
        client.print(getString(htmlData_pin));
        client.print(r, DEC);
        client.println(getString(htmlData_end_h1));
        return r;
}

#!C

client.println(getString(htmlData_head));
client.println(getString(htmlData_htmlstart));
client.print(getString(htmlData_freemem));
client.print(freeMemory(), DEC);
client.println(getString(htmlData_end_p));
for (int i = 0; i < LIGHTS_NUM; i++) {
  client.print(getString(htmlData_lipin));
  client.print(i);
  ...
}

Get string

#!C

#define MAX_STRING 60
char stringBuffer[MAX_STRING];
char* getString(const char* str) {
        strcpy_P(stringBuffer, (char*)str);
        return stringBuffer;
}

const char PROGMEM htmlData_head[] PROGMEM = "HTTP/1.1 200 OK\nContent-Type: text/html\n\n";
const char PROGMEM htmlData_status[] PROGMEM = "<h1>Status</h1>";

client.println(getString(htmlData_htmlstart));

#!HTML
HTTP/1.1 200 OK\nContent-Type: text/html

<html><head><title>Status</title></head><body>
<h1>Status</h1>
...
</body></html>

Serial

#!C

#ifdef ENABLE_SERIAL
  Serial.begin(9600);
  Serial.println(getString(helloText));
#endif

#ifdef ENABLE_SERIAL
  Serial.print(getString(deviceText_set_device));
  Serial.print(pos, DEC);
  Serial.println(getString(deviceText_on));
#endif

Data

"input_id","text","comment","task","thing","device"
0,"a","wardrobe top left","swap","device","wardrobe"
1,"b","wardrobe bottom left","swap","device","hall"
2,"c","wardrobe top right","swap","device","stairs"

"device_id","title","max","groups"
0,"kitchen",3600,"lights,upstairs"
1,"lounge",3600,"lights,upstairs"
#!Perl
my %device = ();
open (my $in, "device.txt");
while (<$in>) {
        chomp;
        my @arr = split(/,/, $_);
        if ($arr[0] =~ /^\d+$/) {
                $device{$arr[1]} = {
...
#!C

#define LIGHTS_NUM 88
// light_limit = how long to allow the light to be on
// const unsigned int configDeviceLimit[LIGHTS_NUM] = {
prog_uint16_t configDeviceLimit[LIGHTS_NUM] PROGMEM = {
    // 0..7
        20, 3600, 10, 3, 25, 25, 0, 0,
        // 8..15
        0, 0, 0, 0, 0, 0, 0, 0,
        // 16..23



const unsigned char configDep[DEP_NUM][DEP_SET] = {
        // Which device, How many to check
        {80, 3, 0, 1, 2},               // Turn on 80 if 0, 1 or 2 is enabled
        {81, 1, 0},                             // Turn on 81 if 0 is enabled



prog_uchar configInputTask[INPUT_NUM] PROGMEM = {
// 0..96
        TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, 
        TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, TASK_SWAP, 



prog_uchar configInputDevice[INPUT_NUM] PROGMEM = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,



PGM_P configDeviceName[] PROGMEM = {
        // 0..3
        configDeviceName_00, configDeviceName_01, configDeviceName_02, configDeviceName_03,
        // 4..7


Software error:

Can't locate object method "endform" via package "CGI" at /data/scott.dd.com.au/wiki/modules/search.pl line 15.

For help, please send mail to the webmaster (webmaster@dd.com.au), giving this error message and the time and date of the error.