initial upload
This commit is contained in:
parent
c2f9c584b9
commit
fce1b561da
16
examples/osd/arduino-ledstrip/LEDStripDriver/README.txt
Normal file
16
examples/osd/arduino-ledstrip/LEDStripDriver/README.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
//***********************************************************************
|
||||
//
|
||||
// Name:LEDStripDriver liararies v0.9b for Grove - LED Strip Driver v0.9b
|
||||
// Author:Frankie.Chu at Seeed Studio.
|
||||
// Date:March 9,2012
|
||||
// Version:0.9b
|
||||
// Software platform:Arduino-1.0
|
||||
// Hardware platform:Arduino UNO/Seeeduino/Arduino Mega +
|
||||
// Grove - LED Strip Driver v0.9b
|
||||
// Demo code:
|
||||
// DualLEDStrip:Light the two LED strips with two driver.
|
||||
// SingleLEDStrip:Light the single LED strip.
|
||||
// DemoForWhiteLEDStrip:Light the White LED Flexi-Strip.
|
||||
// Default:"-"pin of it is connected to "B" of the driver.
|
||||
//
|
||||
//***********************************************************************
|
107
examples/osd/arduino-ledstrip/LEDStripDriver/RGBdriver.cpp
Normal file
107
examples/osd/arduino-ledstrip/LEDStripDriver/RGBdriver.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
// Modified Record:
|
||||
/***************************************************************************/
|
||||
#include "RGBdriver.h"
|
||||
RGBdriver::RGBdriver(uint8_t Clk, uint8_t Data)
|
||||
{
|
||||
Clkpin = Clk;
|
||||
Datapin = Data;
|
||||
pinMode(Datapin, OUTPUT);
|
||||
pinMode(Clkpin, OUTPUT);
|
||||
}
|
||||
|
||||
void RGBdriver::begin(void)
|
||||
{
|
||||
Send32Zero();
|
||||
}
|
||||
|
||||
void RGBdriver::end(void)
|
||||
{
|
||||
Send32Zero();
|
||||
}
|
||||
|
||||
void RGBdriver::ClkRise(void)
|
||||
{
|
||||
digitalWrite(Clkpin, LOW);
|
||||
delayMicroseconds(20);
|
||||
digitalWrite(Clkpin, HIGH);
|
||||
delayMicroseconds(20);
|
||||
}
|
||||
|
||||
void RGBdriver::Send32Zero(void)
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
for (i=0; i<32; i++)
|
||||
{
|
||||
digitalWrite(Datapin, LOW);
|
||||
ClkRise();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t RGBdriver::TakeAntiCode(uint8_t dat)
|
||||
{
|
||||
uint8_t tmp = 0;
|
||||
|
||||
if ((dat & 0x80) == 0)
|
||||
{
|
||||
tmp |= 0x02;
|
||||
}
|
||||
|
||||
if ((dat & 0x40) == 0)
|
||||
{
|
||||
tmp |= 0x01;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// gray data
|
||||
void RGBdriver::DatSend(uint32_t dx)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i=0; i<32; i++)
|
||||
{
|
||||
if ((dx & 0x80000000) != 0)
|
||||
{
|
||||
digitalWrite(Datapin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(Datapin, LOW);
|
||||
}
|
||||
|
||||
dx <<= 1;
|
||||
ClkRise();
|
||||
}
|
||||
}
|
||||
|
||||
// Set color
|
||||
void RGBdriver::SetColor(uint8_t Red,uint8_t Green,uint8_t Blue)
|
||||
{
|
||||
uint32_t dx = 0;
|
||||
|
||||
dx |= (uint32_t)0x03 << 30; // highest two bits 1,flag bits
|
||||
dx |= (uint32_t)TakeAntiCode(Blue) << 28;
|
||||
dx |= (uint32_t)TakeAntiCode(Green) << 26;
|
||||
dx |= (uint32_t)TakeAntiCode(Red) << 24;
|
||||
|
||||
dx |= (uint32_t)Blue << 16;
|
||||
dx |= (uint32_t)Green << 8;
|
||||
dx |= Red;
|
||||
|
||||
DatSend(dx);
|
||||
}
|
20
examples/osd/arduino-ledstrip/LEDStripDriver/RGBdriver.h
Normal file
20
examples/osd/arduino-ledstrip/LEDStripDriver/RGBdriver.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef RGB_DRIVER_H
|
||||
#define RGB_DRIVER_H
|
||||
#include <inttypes.h>
|
||||
#include <Arduino.h>
|
||||
class RGBdriver
|
||||
{
|
||||
public:
|
||||
RGBdriver(uint8_t, uint8_t);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void ClkRise(void);
|
||||
void Send32Zero(void);
|
||||
uint8_t TakeAntiCode(uint8_t dat);
|
||||
void DatSend(uint32_t dx);
|
||||
void SetColor(uint8_t Red,uint8_t Green,uint8_t Blue);
|
||||
private:
|
||||
uint8_t Clkpin;
|
||||
uint8_t Datapin;
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
// Author:Frankie.Chu
|
||||
// Date:March 9,2012
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/***************************************************************************/
|
||||
#include "RGBdriver.h"
|
||||
#define CLK 2//pins definitions for the driver
|
||||
#define DIO 3
|
||||
RGBdriver Driver(CLK,DIO);
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
unsigned int i;
|
||||
while(1){
|
||||
for(i = 0;i < 256;i ++)
|
||||
{
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(0,0,i); //Blue. First node data. SetColor(R,G,B)
|
||||
Driver.end();
|
||||
delay(10);
|
||||
}
|
||||
for(i = 255;i > 0;i --)
|
||||
{
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(0,0,i); //Blue. first node data
|
||||
Driver.end();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// Author:Frankie.Chu
|
||||
// Date:March 9,2012
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/***************************************************************************/
|
||||
#include "RGBdriver.h"
|
||||
#define CLK 2//pins definitions for the driver
|
||||
#define DIO 3
|
||||
RGBdriver Driver(CLK,DIO);
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(255, 0, 0); //Red. first node data
|
||||
Driver.SetColor(0, 0, 255); //Blue. second node data
|
||||
Driver.end();
|
||||
delay(500);
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(0, 0, 255); //Blue. first node data
|
||||
Driver.SetColor(0, 255, 0); //Green. second node data
|
||||
Driver.end();
|
||||
delay(500);
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(0, 255, 0); //Green. first node data
|
||||
Driver.SetColor(255, 0, 0); //Red. second node data
|
||||
Driver.end();
|
||||
delay(500);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// Author:Frankie.Chu
|
||||
// Date:March 9,2012
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
/***************************************************************************/
|
||||
#include "RGBdriver.h"
|
||||
#define CLK 2//pins definitions for the driver
|
||||
#define DIO 3
|
||||
RGBdriver Driver(CLK,DIO);
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(255, 0, 0); //Red. first node data
|
||||
Driver.end();
|
||||
delay(500);
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(0, 255, 0); //Green. first node data
|
||||
Driver.end();
|
||||
delay(500);
|
||||
Driver.begin(); // begin
|
||||
Driver.SetColor(0, 0, 255);//Blue. first node data
|
||||
Driver.end();
|
||||
delay(500);
|
||||
}
|
86
examples/osd/arduino-ledstrip/Makefile
Normal file
86
examples/osd/arduino-ledstrip/Makefile
Normal file
|
@ -0,0 +1,86 @@
|
|||
# Set this to the name of your sketch (without extension .pde)
|
||||
SKETCH=sketch
|
||||
|
||||
ifeq ($(TARGET), osd-merkur)
|
||||
PLATFORM_FILES= avr-size arduino-example.osd-merkur.hex \
|
||||
arduino-example.osd-merkur.eep
|
||||
endif
|
||||
|
||||
all: arduino-example $(PLATFORM_FILES)
|
||||
|
||||
CONTIKI=../../..
|
||||
|
||||
# Contiki IPv6 configuration
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
PROJECT_SOURCEFILES += ${SKETCH}.cpp
|
||||
|
||||
# automatically build RESTful resources
|
||||
REST_RESOURCES_DIR = ./resources
|
||||
REST_RESOURCES_DIR_COMMON = ../resources-common
|
||||
REST_RESOURCES_FILES= $(notdir \
|
||||
$(shell find $(REST_RESOURCES_DIR) -name '*.c') \
|
||||
$(shell find $(REST_RESOURCES_DIR_COMMON) -name '*.c') \
|
||||
)
|
||||
|
||||
PROJECTDIRS += $(REST_RESOURCES_DIR) $(REST_RESOURCES_DIR_COMMON)
|
||||
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
|
||||
|
||||
# variable for Makefile.include
|
||||
ifneq ($(TARGET), minimal-net)
|
||||
CFLAGS += -DUIP_CONF_IPV6_RPL=1
|
||||
else
|
||||
# minimal-net does not support RPL under Linux and is mostly used to test CoAP only
|
||||
${info INFO: compiling without RPL}
|
||||
CFLAGS += -DUIP_CONF_IPV6_RPL=0
|
||||
CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\"
|
||||
${info INFO: compiling with large buffers}
|
||||
CFLAGS += -DUIP_CONF_BUFFER_SIZE=2048
|
||||
CFLAGS += -DREST_MAX_CHUNK_SIZE=1024
|
||||
CFLAGS += -DCOAP_MAX_HEADER_SIZE=640
|
||||
endif
|
||||
|
||||
# linker optimizations
|
||||
SMALL=1
|
||||
|
||||
|
||||
# REST Engine shall use Erbium CoAP implementation
|
||||
APPS += er-coap
|
||||
APPS += rest-engine
|
||||
APPS += arduino
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
include $(CONTIKI)/apps/arduino/Makefile.include
|
||||
|
||||
avr-size: arduino-example.osd-merkur
|
||||
avr-size -C --mcu=MCU=atmega128rfa1 arduino-example.osd-merkur
|
||||
|
||||
arduino-example.osd-merkur.hex: arduino-example.osd-merkur
|
||||
avr-objcopy -j .text -j .data -O ihex arduino-example.osd-merkur \
|
||||
arduino-example.osd-merkur.hex
|
||||
|
||||
arduino-example.osd-merkur.eep: arduino-example.osd-merkur
|
||||
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||
--change-section-lma .eeprom=0 -O ihex \
|
||||
arduino-example.osd-merkur arduino-example.osd-merkur.eep
|
||||
|
||||
flash: arduino-example.osd-merkur.hex arduino-example.osd-merkur.eep
|
||||
avrdude -pm128rfa1 -c arduino -P/dev/ttyUSB0 -b57600 -e -U \
|
||||
flash:w:arduino-example.osd-merkur.hex:a -U \
|
||||
eeprom:w:arduino-example.osd-merkur.eep:a
|
||||
|
||||
.PHONY: flash avr-size
|
||||
|
||||
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||
|
||||
connect-router: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64
|
||||
|
||||
connect-router-cooja: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 aaaa::1/64
|
||||
|
||||
connect-minimal:
|
||||
sudo ip address add fdfd::1/64 dev tap0
|
11
examples/osd/arduino-ledstrip/README.md
Normal file
11
examples/osd/arduino-ledstrip/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Arduino compatibility example
|
||||
=============================
|
||||
|
||||
This example shows that it is now possible to re-use arduino sketches in
|
||||
Contiki. This example documents the necessary magic. Arduino specifies
|
||||
two routines, `setup` and `loop`. Before `setup` is called, the
|
||||
framework initializes hardware. In original Arduino, all this is done in
|
||||
a `main` function (in C). For contiki we define a process that does the
|
||||
same.
|
||||
|
||||
See the documentation file in apps/contiki-compat/README.md
|
16
examples/osd/arduino-ledstrip/README.txt
Normal file
16
examples/osd/arduino-ledstrip/README.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
//***********************************************************************
|
||||
//
|
||||
// Name:LEDStripDriver liararies v0.9b for Grove - LED Strip Driver v0.9b
|
||||
// Author:Frankie.Chu at Seeed Studio.
|
||||
// Date:March 9,2012
|
||||
// Version:0.9b
|
||||
// Software platform:Arduino-1.0
|
||||
// Hardware platform:Arduino UNO/Seeeduino/Arduino Mega +
|
||||
// Grove - LED Strip Driver v0.9b
|
||||
// Demo code:
|
||||
// DualLEDStrip:Light the two LED strips with two driver.
|
||||
// SingleLEDStrip:Light the single LED strip.
|
||||
// DemoForWhiteLEDStrip:Light the White LED Flexi-Strip.
|
||||
// Default:"-"pin of it is connected to "B" of the driver.
|
||||
//
|
||||
//***********************************************************************
|
107
examples/osd/arduino-ledstrip/RGBdriver.cpp
Normal file
107
examples/osd/arduino-ledstrip/RGBdriver.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
// Modified Record:
|
||||
/***************************************************************************/
|
||||
#include "RGBdriver.h"
|
||||
RGBdriver::RGBdriver(uint8_t Clk, uint8_t Data)
|
||||
{
|
||||
Clkpin = Clk;
|
||||
Datapin = Data;
|
||||
pinMode(Datapin, OUTPUT);
|
||||
pinMode(Clkpin, OUTPUT);
|
||||
}
|
||||
|
||||
void RGBdriver::begin(void)
|
||||
{
|
||||
Send32Zero();
|
||||
}
|
||||
|
||||
void RGBdriver::end(void)
|
||||
{
|
||||
Send32Zero();
|
||||
}
|
||||
|
||||
void RGBdriver::ClkRise(void)
|
||||
{
|
||||
digitalWrite(Clkpin, LOW);
|
||||
delayMicroseconds(20);
|
||||
digitalWrite(Clkpin, HIGH);
|
||||
delayMicroseconds(20);
|
||||
}
|
||||
|
||||
void RGBdriver::Send32Zero(void)
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
for (i=0; i<32; i++)
|
||||
{
|
||||
digitalWrite(Datapin, LOW);
|
||||
ClkRise();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t RGBdriver::TakeAntiCode(uint8_t dat)
|
||||
{
|
||||
uint8_t tmp = 0;
|
||||
|
||||
if ((dat & 0x80) == 0)
|
||||
{
|
||||
tmp |= 0x02;
|
||||
}
|
||||
|
||||
if ((dat & 0x40) == 0)
|
||||
{
|
||||
tmp |= 0x01;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// gray data
|
||||
void RGBdriver::DatSend(uint32_t dx)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i=0; i<32; i++)
|
||||
{
|
||||
if ((dx & 0x80000000) != 0)
|
||||
{
|
||||
digitalWrite(Datapin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(Datapin, LOW);
|
||||
}
|
||||
|
||||
dx <<= 1;
|
||||
ClkRise();
|
||||
}
|
||||
}
|
||||
|
||||
// Set color
|
||||
void RGBdriver::SetColor(uint8_t Red,uint8_t Green,uint8_t Blue)
|
||||
{
|
||||
uint32_t dx = 0;
|
||||
|
||||
dx |= (uint32_t)0x03 << 30; // highest two bits 1,flag bits
|
||||
dx |= (uint32_t)TakeAntiCode(Blue) << 28;
|
||||
dx |= (uint32_t)TakeAntiCode(Green) << 26;
|
||||
dx |= (uint32_t)TakeAntiCode(Red) << 24;
|
||||
|
||||
dx |= (uint32_t)Blue << 16;
|
||||
dx |= (uint32_t)Green << 8;
|
||||
dx |= Red;
|
||||
|
||||
DatSend(dx);
|
||||
}
|
20
examples/osd/arduino-ledstrip/RGBdriver.h
Normal file
20
examples/osd/arduino-ledstrip/RGBdriver.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef RGB_DRIVER_H
|
||||
#define RGB_DRIVER_H
|
||||
#include <inttypes.h>
|
||||
#include <Arduino.h>
|
||||
class RGBdriver
|
||||
{
|
||||
public:
|
||||
RGBdriver(uint8_t, uint8_t);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void ClkRise(void);
|
||||
void Send32Zero(void);
|
||||
uint8_t TakeAntiCode(uint8_t dat);
|
||||
void DatSend(uint32_t dx);
|
||||
void SetColor(uint8_t Red,uint8_t Green,uint8_t Blue);
|
||||
private:
|
||||
uint8_t Clkpin;
|
||||
uint8_t Datapin;
|
||||
};
|
||||
#endif
|
2
examples/osd/arduino-ledstrip/arduino-example.c
Normal file
2
examples/osd/arduino-ledstrip/arduino-example.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <arduino-process.h>
|
||||
AUTOSTART_PROCESSES(&arduino_sketch);
|
2
examples/osd/arduino-ledstrip/flash.sh
Executable file
2
examples/osd/arduino-ledstrip/flash.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
make TARGET=osd-merkur flash
|
101
examples/osd/arduino-ledstrip/project-conf.h
Normal file
101
examples/osd/arduino-ledstrip/project-conf.h
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_RPL_WEB_CONF_H_
|
||||
#define PROJECT_RPL_WEB_CONF_H_
|
||||
|
||||
#define PLATFORM_HAS_LEDS 1
|
||||
//#define PLATFORM_HAS_BUTTON 1
|
||||
#define PLATFORM_HAS_BATTERY 1
|
||||
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
|
||||
/* For Debug: Dont allow MCU sleeping between channel checks */
|
||||
//#undef RDC_CONF_MCU_SLEEP
|
||||
//#define RDC_CONF_MCU_SLEEP 0
|
||||
|
||||
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
||||
/* For projects, optimize memory and enable RDC again. */
|
||||
// #undef NETSTACK_CONF_RDC
|
||||
//#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
/* Increase rpl-border-router IP-buffer when using more than 64. */
|
||||
#undef REST_MAX_CHUNK_SIZE
|
||||
#define REST_MAX_CHUNK_SIZE 64
|
||||
|
||||
/* Estimate your header size, especially when using Proxy-Uri. */
|
||||
/*
|
||||
#undef COAP_MAX_HEADER_SIZE
|
||||
#define COAP_MAX_HEADER_SIZE 70
|
||||
*/
|
||||
|
||||
/* The IP buffer size must fit all other hops, in particular the border router. */
|
||||
|
||||
#undef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 256
|
||||
|
||||
|
||||
/* Multiplies with chunk size, be aware of memory constraints. */
|
||||
#undef COAP_MAX_OPEN_TRANSACTIONS
|
||||
#define COAP_MAX_OPEN_TRANSACTIONS 4
|
||||
|
||||
/* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
|
||||
/*
|
||||
#undef COAP_MAX_OBSERVERS
|
||||
#define COAP_MAX_OBSERVERS 2
|
||||
*/
|
||||
|
||||
/* Filtering .well-known/core per query can be disabled to save space. */
|
||||
/*
|
||||
#undef COAP_LINK_FORMAT_FILTERING
|
||||
#define COAP_LINK_FORMAT_FILTERING 0
|
||||
*/
|
||||
|
||||
/* Save some memory for the sky platform. */
|
||||
/*
|
||||
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 10
|
||||
#undef UIP_CONF_MAX_ROUTES
|
||||
#define UIP_CONF_MAX_ROUTES 10
|
||||
*/
|
||||
|
||||
/* Reduce 802.15.4 frame queue to save RAM. */
|
||||
/*
|
||||
#undef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 4
|
||||
*/
|
||||
|
||||
/*
|
||||
#undef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
*/
|
||||
|
||||
#endif /* PROJECT_RPL_WEB_CONF_H_ */
|
82
examples/osd/arduino-ledstrip/resources/res-door.c
Normal file
82
examples/osd/arduino-ledstrip/resources/res-door.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Door resource
|
||||
* \author
|
||||
* Harald Pichler <harald@the-develop.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "rest-engine.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
/* A simple getter example. Returns the reading from the sensor with a simple etag */
|
||||
RESOURCE(res_door,
|
||||
"title=\"Moisture status\";rt=\"Moisture\"",
|
||||
res_get_handler,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
extern uint8_t door_pin;
|
||||
extern uint8_t door_status;
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
||||
door_status = digitalRead(door_pin);
|
||||
|
||||
unsigned int accept = -1;
|
||||
REST.get_header_accept(request, &accept);
|
||||
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", door_status);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'door':%d}", door_status);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
const char *msg = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
5
examples/osd/arduino-ledstrip/run.sh
Executable file
5
examples/osd/arduino-ledstrip/run.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
# For the new bootloader (using a jump-table) you want to use
|
||||
# BOOTLOADER_GET_MAC=0x0001ff80 (which is the current default)
|
||||
make clean TARGET=osd-merkur
|
||||
make TARGET=osd-merkur BOOTLOADER_GET_MAC=0x0001f3a0
|
37
examples/osd/arduino-ledstrip/sketch.pde
Normal file
37
examples/osd/arduino-ledstrip/sketch.pde
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Sample arduino sketch using contiki features.
|
||||
* We turn the LED off
|
||||
* We allow read the moisture sensor
|
||||
* Unfortunately sleeping for long times in loop() isn't currently
|
||||
* possible, something turns off the CPU (including PWM outputs) if a
|
||||
* Proto-Thread is taking too long. We need to find out how to sleep in
|
||||
* a Contiki-compatible way.
|
||||
* Note that for a normal arduino sketch you won't have to include any
|
||||
* of the contiki-specific files here, the sketch should just work.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "rest-engine.h"
|
||||
|
||||
extern resource_t res_door, res_battery;
|
||||
uint8_t door_pin = 3;
|
||||
uint8_t door_status = 0;
|
||||
|
||||
#define LED_PIN 4
|
||||
}
|
||||
|
||||
void setup (void)
|
||||
{
|
||||
// switch off the led
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
// init coap resourcen
|
||||
rest_init_engine ();
|
||||
rest_activate_resource (&res_door, "s/door");
|
||||
rest_activate_resource (&res_battery, "s/battery");
|
||||
}
|
||||
|
||||
void loop (void)
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in a new issue