Commit d41368b8 authored by Julien Leduc's avatar Julien Leduc

Initial GPLv3 code base for the DCES project

parent 0017a3d0
--------------------
dces-dtrhf-ser1ch-v1
--------------------
Here is what the name stands for:
Data Center Environmental Sensor sensing Dust, Temperature, Relative Humidity and Fan speed sending results on SERial 1 CHannel - version 1.
This is a long name, but it precisely defines what is implemented in the project.
Compiling and flashing the firmware
-----------------------------------
Some prerequites, to compile this firmware, you need to install the ``arduino-core`` package, the full IDE is not needed, because it is simple an faster to build from the commandline:
::
$ yum instal arduino-core
Before going any further you need to adapt the configuration file to your setup: edit ``dces-dtrhf-ser1ch-v1.conf`` in ``dces-dtrhf-ser1ch-v1/arduino/``.
Then to build and flash the arduino board, simply run ``build.sh`` from command line:
::
$ cd dces-dtrhf-ser1ch-v1/arduino
$ ./build.sh
It is only going to build ``dces-dtrhf-ser1ch-v1/arduino/final/final.ino`` using ``dces-dtrhf-ser1ch-v1/arduino/final/Makefile``.
To clean the project, just ``make clean`` from ``dces-dtrhf-ser1ch-v1/arduino/final`` directory.
If ``UPLOAD=true`` in ``dces-dtrhf-ser1ch-v1.conf``, the firmware is going to be flashed on the arduino board.
Configuring the firmware
------------------------
Firmware configuration is done from the arduino serial port using ``SerialCommand`` library.
When the firmware starts it displays measured data by default:
::
$ picocom /dev/ttyACM0
port is : /dev/ttyACM0
flowcontrol : none
baudrate is : 9600
parity is : none
databits are : 8
escape is : C-a
local echo is : no
noinit is : no
noreset is : no
nolock is : no
send_cmd is : sz -vv
receive_cmd is : rz -vv
imap is :
omap is :
emap is : crcrlf,delbs,
Terminal ready
8471, 8384, 446, 26.69, 31.37, 196, 0, 960
8419, 8448, 163, 26.69, 31.44, 196, 0, 960
...
#!/bin/bash
##############################################################################
#
# This file is part of the DCES project.
# See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
#
# Copyright (C) 2016 CERN
# All rights not expressly granted are reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# This program 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 General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# @author DCES Dev team, dces-dev@cern.ch
#############################################################################
. ./dces-dtrhf-ser1ch-v1.conf 2>/dev/null
cd final
if [[ $UPLOAD = "true" ]]
then
echo "Compiling and upgrading arduino firmware"
make BOARD=$BOARD SERIALDEV=$DEVICE upload
else
echo "Compiling only"
make BOARD=$BOARD SERIALDEV=$DEVICE
fi
###
# Example configuration file for dust sensor firmware update
###
###
# Configuration section for firmware compilation/upgrade
###
[MAKE_SECTION]
# UPLOAD="true" automatically build and upload firmware upon rpm installation
UPLOAD="false"
# Arduino board type for dust sensor as specified in /usr/share/arduino/hardware/arduino/boards.txt
BOARD="mega2560"
# TTY device for serial communications
DEVICE="/dev/ttyACM0"
#_______________________________________________________________________________
#
# edam's Arduino makefile
#_______________________________________________________________________________
# version 0.5
#
# Copyright (C) 2011, 2012, 2013 Tim Marston <tim@ed.am>.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#_______________________________________________________________________________
#
#
# This is a general purpose makefile for use with Arduino hardware and
# software. It works with the arduino-1.0 and later software releases. It
# should work GNU/Linux and OS X. To download the latest version of this
# makefile visit the following website where you can also find documentation on
# it's use. (The following text can only really be considered a reference.)
#
# http://ed.am/dev/make/arduino-mk
#
# This makefile can be used as a drop-in replacement for the Arduino IDE's
# build system. To use it, just copy arduino.mk in to your project directory.
# Or, you could save it somewhere (I keep mine at ~/src/arduino.mk) and create
# a symlink to it in your project directory, named "Makefile". For example:
#
# $ ln -s ~/src/arduino.mk Makefile
#
# The Arduino software (version 1.0 or later) is required. On GNU/Linux you
# can probably install the software from your package manager. If you are
# using Debian (or a derivative), try `apt-get install arduino`. Otherwise,
# you can download the Arduino software manually from http://arduino.cc/. It
# is suggested that you install it at ~/opt/arduino (or /Applications on OS X)
# if you are unsure.
#
# If you downloaded the Arduino software manually and unpacked it somewhere
# other than ~/opt/arduino (or /Applications), you will need to set up the
# ARDUINODIR environment variable to be the path where you unpacked it. (If
# unset, ARDUINODIR defaults to some sensible places). You could set this in
# your ~/.profile by adding something like this:
#
# export ARDUINODIR=~/somewhere/arduino-1.0
#
# For each project, you will also need to set BOARD to the type of Arduino
# you're building for. Type `make boards` for a list of acceptable values.
# For example:
#
# $ export BOARD=uno
# $ make
#
# You may also need to set SERIALDEV if it is not detected correctly.
#
# The presence of a .ino (or .pde) file causes the arduino.mk to automatically
# determine values for SOURCES, TARGET and LIBRARIES. Any .c, .cc and .cpp
# files in the project directory (or any "util" or "utility" subdirectories)
# are automatically included in the build and are scanned for Arduino libraries
# that have been #included. Note, there can only be one .ino (or .pde) file in
# a project directory and if you want to be compatible with the Arduino IDE, it
# should be called the same as the directory name.
#
# Alternatively, if you want to manually specify build variables, create a
# Makefile that defines SOURCES and LIBRARIES and then includes arduino.mk.
# (There is no need to define TARGET). You can also specify the BOARD here, if
# the project has a specific one. Here is an example Makefile:
#
# SOURCES := main.cc other.cc
# LIBRARIES := EEPROM
# BOARD := pro5v
# include ~/src/arduino.mk
#
# Here is a complete list of configuration parameters:
#
# ARDUINODIR The path where the Arduino software is installed on your system.
#
# ARDUINOCONST The Arduino software version, as an integer, used to define the
# ARDUINO version constant. This defaults to 100 if undefined.
#
# AVRDUDECONF The avrdude.conf to use. If undefined, this defaults to a guess
# based on where avrdude is. If set empty, no avrdude.conf is
# passed to avrdude (so the system default is used).
#
# AVRDUDEFLAGS Specify any additional flags for avrdude. The usual flags,
# required to build the project, will be appended to this.
#
# AVRTOOLSPATH A space-separated list of directories that is searched in order
# when looking for the avr build tools. This defaults to PATH,
# followed by subdirectories in ARDUINODIR.
#
# BOARD Specify a target board type. Run `make boards` to see available
# board types.
#
# CPPFLAGS Specify any additional flags for the compiler. The usual flags,
# required to build the project, will be appended to this.
#
# LINKFLAGS Specify any additional flags for the linker. The usual flags,
# required to build the project, will be appended to this.
#
# LIBRARIES A list of Arduino libraries to build and include. This is set
# automatically if a .ino (or .pde) is found.
#
# LIBRARYPATH A space-separated list of directories that is searched in order
# when looking for Arduino libraries. This defaults to "libs",
# "libraries" (in the project directory), then your sketchbook
# "libraries" directory, then the Arduino libraries directory.
#
# SERIALDEV The POSIX device name of the serial device that is the Arduino.
# If unspecified, an attempt is made to guess the name of a
# connected Arduino's serial device, which may work in some cases.
#
# SOURCES A list of all source files of whatever language. The language
# type is determined by the file extension. This is set
# automatically if a .ino (or .pde) is found.
#
# TARGET The name of the target file. This is set automatically if a
# .ino (or .pde) is found, but it is not necessary to set it
# otherwise.
#
# This makefile also defines the following goals for use on the command line
# when you run make:
#
# all This is the default if no goal is specified. It builds the
# target.
#
# target Builds the target.
#
# upload Uploads the target (building it, as necessary) to an attached
# Arduino.
#
# clean Deletes files created during the build.
#
# boards Display a list of available board names, so that you can set the
# BOARD environment variable appropriately.
#
# monitor Start `screen` on the serial device. This is meant to be an
# equivalent to the Arduino serial monitor.
#
# size Displays size information about the built target.
#
# bootloader Burns the bootloader for your board to it.
#
# <file> Builds the specified file, either an object file or the target,
# from those that that would be built for the project.
#_______________________________________________________________________________
#
# project specific vars
PROJECTDIR := $(shell echo $(abspath $(lastword $(MAKEFILE_LIST))) |\
sed -Ee 's/^(.*dces-dtrhf-ser1ch-v1).*$$/\1/')
# default arduino software directory, check software exists
ifndef ARDUINODIR
ARDUINODIR := $(firstword $(wildcard ~/opt/arduino /usr/share/arduino \
/Applications/Arduino.app/Contents/Resources/Java \
$(HOME)/Applications/Arduino.app/Contents/Resources/Java))
endif
ifeq "$(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt)" ""
$(error ARDUINODIR is not set correctly; arduino software not found)
endif
# default arduino version
ARDUINOCONST ?= 100
# default path for avr tools
AVRTOOLSPATH ?= $(subst :, , $(PATH)) $(ARDUINODIR)/hardware/tools \
$(ARDUINODIR)/hardware/tools/avr/bin
# default path to find libraries
LIBRARYPATH ?= $(PROJECTDIR)/arduino/libraries libraries libs $(SKETCHBOOKDIR)/libraries $(ARDUINODIR)/libraries
# default serial device to a poor guess (something that might be an arduino)
SERIALDEVGUESS := 0
ifndef SERIALDEV
#SERIALDEV := $(firstword $(wildcard \
/dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem*))
SERIALDEVGUESS := 1
endif
# no board?
ifndef BOARD
ifneq "$(MAKECMDGOALS)" "boards"
ifneq "$(MAKECMDGOALS)" "clean"
$(error BOARD is unset. Type 'make boards' to see possible values)
endif
endif
endif
# obtain board parameters from the arduino boards.txt file
BOARDSFILE := $(ARDUINODIR)/hardware/arduino/boards.txt
readboardsparam = $(shell sed -ne "s/$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
BOARD_BUILD_MCU := $(call readboardsparam,build.mcu)
BOARD_BUILD_FCPU := $(call readboardsparam,build.f_cpu)
BOARD_BUILD_VARIANT := $(call readboardsparam,build.variant)
BOARD_UPLOAD_SPEED := $(call readboardsparam,upload.speed)
BOARD_UPLOAD_PROTOCOL := $(call readboardsparam,upload.protocol)
BOARD_USB_VID := $(call readboardsparam,build.vid)
BOARD_USB_PID := $(call readboardsparam,build.pid)
BOARD_BOOTLOADER_UNLOCK := $(call readboardsparam,bootloader.unlock_bits)
BOARD_BOOTLOADER_LOCK := $(call readboardsparam,bootloader.lock_bits)
BOARD_BOOTLOADER_LFUSES := $(call readboardsparam,bootloader.low_fuses)
BOARD_BOOTLOADER_HFUSES := $(call readboardsparam,bootloader.high_fuses)
BOARD_BOOTLOADER_EFUSES := $(call readboardsparam,bootloader.extended_fuses)
BOARD_BOOTLOADER_PATH := $(call readboardsparam,bootloader.path)
BOARD_BOOTLOADER_FILE := $(call readboardsparam,bootloader.file)
# obtain preferences from the IDE's preferences.txt
PREFERENCESFILE := $(firstword $(wildcard \
$(HOME)/.arduino/preferences.txt $(HOME)/Library/Arduino/preferences.txt))
ifneq "$(PREFERENCESFILE)" ""
readpreferencesparam = $(shell sed -ne "s/$(1)=\(.*\)/\1/p" $(PREFERENCESFILE))
SKETCHBOOKDIR := $(call readpreferencesparam,sketchbook.path)
endif
# invalid board?
ifeq "$(BOARD_BUILD_MCU)" ""
ifneq "$(MAKECMDGOALS)" "boards"
ifneq "$(MAKECMDGOALS)" "clean"
$(error BOARD is invalid. Type 'make boards' to see possible values)
endif
endif
endif
# auto mode?
INOFILE := $(wildcard *.ino *.pde)
ifdef INOFILE
ifneq "$(words $(INOFILE))" "1"
$(error There is more than one .pde or .ino file in this directory!)
endif
# automatically determine sources and targeet
TARGET := $(basename $(INOFILE))
SOURCES := $(INOFILE) \
$(wildcard *.c *.cc *.cpp *.C) \
$(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
$(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
# automatically determine included libraries
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
endif
# software
findsoftware = $(firstword $(wildcard $(addsuffix /$(1), $(AVRTOOLSPATH))))
CC := $(call findsoftware,avr-gcc)
CXX := $(call findsoftware,avr-g++)
LD := $(call findsoftware,avr-ld)
AR := $(call findsoftware,avr-ar)
OBJCOPY := $(call findsoftware,avr-objcopy)
AVRDUDE := $(call findsoftware,avrdude)
AVRSIZE := $(call findsoftware,avr-size)
# directories
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
$(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
# files
TARGET := $(if $(TARGET),$(TARGET),a.out)
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
ARDUINOLIB := .lib/arduino.a
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
BOOTLOADERHEX := $(addprefix \
$(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
$(BOARD_BOOTLOADER_FILE))
# avrdude confifuration
ifeq "$(AVRDUDECONF)" ""
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
else
AVRDUDECONF := $(wildcard $(AVRDUDE).conf)
endif
endif
# flags
CPPFLAGS += -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
CPPFLAGS += $(addprefix -I , $(LIBRARYDIRS))
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
STTYFARG := $(shell stty --help 2>&1 | \
grep -q 'illegal option' && echo -f || echo -F)
# include dependencies
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEPFILES)
endif
# default rule
.DEFAULT_GOAL := all
#_______________________________________________________________________________
# RULES
.PHONY: all target upload clean boards monitor size bootloader
all: target
target: $(TARGET).hex
upload: target
@echo "\nUploading to board..."
@test -n "$(SERIALDEV)" || { \
echo "error: SERIALDEV could not be determined automatically." >&2; \
exit 1; }
@test 0 -eq $(SERIALDEVGUESS) || { \
echo "*GUESSING* at serial device:" $(SERIALDEV); \
echo; }
ifeq "$(BOARD_BOOTLOADER_PATH)" "caterina"
stty $(STTYFARG) $(SERIALDEV) speed 1200
sleep 1
else
stty $(STTYFARG) $(SERIALDEV) hupcl
endif
stty $(STTYFARG) $(SERIALDEV) hupcl
sleep 0.1
stty $(STTYFARG) $(SERIALDEV) -hupcl
$(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
wait
clean:
rm -f $(OBJECTS)
rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
rm -rf .lib .dep
boards:
@echo "Available values for BOARD:"
@sed -nEe '/^#/d; /^[^.]+\.name=/p' $(BOARDSFILE) | \
sed -Ee 's/([^.]+)\.name=(.*)/\1 \2/' \
-e 's/(.{12}) *(.*)/\1 \2/'
monitor:
@test -n "$(SERIALDEV)" || { \
echo "error: SERIALDEV could not be determined automatically." >&2; \
exit 1; }
@test -n `which screen` || { \
echo "error: can't find GNU screen, you might need to install it." >&2 \
exit 1; }
@test 0 -eq $(SERIALDEVGUESS) || { \
echo "*GUESSING* at serial device:" $(SERIALDEV); \
echo; }
screen $(SERIALDEV)
size: $(TARGET).elf
echo && $(AVRSIZE) --format=avr --mcu=$(BOARD_BUILD_MCU) $(TARGET).elf
bootloader:
@echo "Burning bootloader to board..."
@test -n "$(SERIALDEV)" || { \
echo "error: SERIALDEV could not be determined automatically." >&2; \
exit 1; }
@test 0 -eq $(SERIALDEVGUESS) || { \
echo "*GUESSING* at serial device:" $(SERIALDEV); \
echo; }
stty $(STTYFARG) $(SERIALDEV) hupcl
$(AVRDUDE) $(AVRDUDEFLAGS) -U lock:w:$(BOARD_BOOTLOADER_UNLOCK):m
$(AVRDUDE) $(AVRDUDEFLAGS) -eU lfuse:w:$(BOARD_BOOTLOADER_LFUSES):m
$(AVRDUDE) $(AVRDUDEFLAGS) -U hfuse:w:$(BOARD_BOOTLOADER_HFUSES):m
ifneq "$(BOARD_BOOTLOADER_EFUSES)" ""
$(AVRDUDE) $(AVRDUDEFLAGS) -U efuse:w:$(BOARD_BOOTLOADER_EFUSES):m
endif
ifneq "$(BOOTLOADERHEX)" ""
$(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(BOOTLOADERHEX):i
endif
$(AVRDUDE) $(AVRDUDEFLAGS) -U lock:w:$(BOARD_BOOTLOADER_LOCK):m
# building the target
$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
.INTERMEDIATE: $(TARGET).elf
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
$(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
%.o: %.c
mkdir -p .dep/$(dir $<)
$(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
%.o: %.cpp
mkdir -p .dep/$(dir $<)
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
%.o: %.cc
mkdir -p .dep/$(dir $<)
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
%.o: %.C
mkdir -p .dep/$(dir $<)
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
%.o: %.ino
mkdir -p .dep/$(dir $<)
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
%.o: %.pde
mkdir -p .dep/$(dir $<)
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
# building the arduino library
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
$(AR) rcs $@ $?
.lib/%.c.o: %.c
mkdir -p $(dir $@)
$(COMPILE.c) -o $@ $<
.lib/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(COMPILE.cpp) -o $@ $<
.lib/%.cc.o: %.cc
mkdir -p $(dir $@)
$(COMPILE.cpp) -o $@ $<
.lib/%.C.o: %.C
mkdir -p $(dir $@)
$(COMPILE.cpp) -o $@ $<
# Local Variables:
# mode: makefile
# tab-width: 4
# End:
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <stdlib.h>
#include <EEPROM.h>
#include <string.h>
#include <lib_hih6120.h>
#include <lib_fan.h>
#include <lib_dust.h>
#include <lib_leds.h>
#include <SoftwareSerial.h>
#include <SerialCommand.h>
#define WAIT_TIME 2500 // Waiting time before restarting loop() in millis
#define NMEAS 1 // Number of dust measures between 2 humidity/temperature measures
#define FSR 0b11111111 // Full Scale Range
// ADDRESSES of config
#define DCYADDR 0
#define RPMTOADDR 2
#define NMEASADDR 4
#define WTIMEADDR 6
#define RPMMINADDR 8
#define RPMMAXADDR 10
// LENGTH of the different FIELDS:
#define TLENGTH 6 // Temperature
#define HLENGTH 6 // Humidity
#define DLENGTH 8 // Dust Level
#define TIMELENGTH 4 // Time
#define SLENGTH 2 // State
#define RPMLENGTH 5 // RPM
// PRECISION of the different FIELDS (change length if you change precision!):
#define TPREC 2 // Temperature
#define HPREC 2 // Humidity
#define VPREC 4 // Voltage
#define DPREC 2 // Dust (unused)
SerialCommand SCmd;
//FUNCTIONS:
void StrAppend(char* dest, char* source, int length, boolean strEnd); // Put string source at the end of string dest.
int readCmd(void);
void command(void);
void EEPROM_write_int(int addr, int val);
int EEPROM_read_int(int addr);
void SET_PWM(void);
void SET_MES(void);
void SET_RTO(void);
void SET_WTT(void);
void SET_RMN(void);
void SET_RMX(void);
void SET_DEF(void);
void GET_PWM(void);
void GET_MES(void);
void GET_RTO(void);
void GET_WTT(void);
void GET_RMN(void);
void GET_RMX(void);
void GET_ALL(void);
void GET_RPM(void);
void EEP_BRN(void);
void EEP_RST(void);
void EEP_PRT(void);
void RUN(void);
void STOP(void);
void HELP(void);
void unrecognized(void);
// COMMON:
unsigned int index=0; // Index of StrAppend() function to locate the position in the dest. string.
char s[16];
char dataStr[TLENGTH+HLENGTH+DLENGTH+DLENGTH+DLENGTH+TIMELENGTH+SLENGTH+RPMLENGTH+10];
unsigned int nMeasConf = NMEAS;
unsigned int nMeasure = nMeasConf-1; // Used to update humidity/temperature every NMEAS dust measures
unsigned int waitTime = WAIT_TIME;
bool bRun = true;
bool bErr = false;
// DUST INITIALIZATION PART:
float avgDust, medDust, stdevDust;
// HUMIDITY/TEMPERATURE INITIALIZATION PART:
float fTemp, fHumi; // Final values in Celsius degrees (temp) and in percent (humi)
float fTempPrev, fHumiPrev; // Save of the previous values
unsigned long deltaTime; // Duration of the humidity/temperature measure in micros
unsigned int hih_state; // HIH sensor state: 0 -> Ok, 1 -> Stale values
// FAN INITIALIZATION PART
unsigned int rpm;
unsigned int rpmTimeout = RPM_TIMEOUT;
unsigned int fanSpeed = FAN_SPEED;
unsigned int rpmMax = RPMMIN;
unsigned int rpmMin = RPMMAX;
//SETUP:
void setup(){
Serial.begin(9600);
initDust();
initI2C();
initFan();
initLEDs();
controlLED14(true);
controlLED15(true);
rpmMin = EEPROM_read_int(RPMMINADDR);
rpmMax = EEPROM_read_int(RPMMAXADDR);
SCmd.addCommand("SET_PWM",SET_PWM);
SCmd.addCommand("SET_MES",SET_MES);
SCmd.addCommand("SET_RTO",SET_RTO);
SCmd.addCommand("SET_WTT",SET_WTT);
SCmd.addCommand("SET_RMN",SET_RMN);
SCmd.addCommand("SET_RMX",SET_RMX);
SCmd.addCommand("SET_DEF",SET_DEF);
SCmd.addCommand("GET_PWM",GET_PWM);
SCmd.addCommand("GET_MES",GET_MES);
SCmd.addCommand("GET_RTO",GET_RTO);
SCmd.addCommand("GET_WTT",GET_WTT);
SCmd.addCommand("GET_RMN",GET_RMN);
SCmd.addCommand("GET_RMX",GET_RMX);
SCmd.addCommand("GET_ALL",GET_ALL);
SCmd.addCommand("GET_RPM",GET_RPM);
SCmd.addCommand("EEP_BRN",EEP_BRN);
SCmd.addCommand("EEP_RST",EEP_RST);
SCmd.addCommand("EEP_PRT",EEP_PRT);
SCmd.addCommand("RUN",RUN);
SCmd.addCommand("STOP",STOP);
SCmd.addCommand("HELP",HELP);
SCmd.addDefaultHandler(unrecognized);
EEP_RST();
delay(1000);
controlLED14(false);
controlLED15(false);
}
//LOOP:
void loop(){
SCmd.readSerial();
//controlLED14(bRun);
if(bRun==false){
controlLED14(false);
delay(400);
controlLED14(true);
delay(400);
}
if(bRun==true){
// Make HIH-6120 updates its values
updateTH();
controlLED14(true);
// Dust measurement
measureDust(avgDust, medDust, stdevDust);
nMeasure++;
// Temperature/humidity measurement
if(nMeasure == nMeasConf) {
fTempPrev = fTemp;
fHumiPrev = fHumi;
hih_state = getTH(&deltaTime);
fTemp = getTemp();
fHumi = getHumi();
nMeasure = 0;
}
// RPM measurement
rpm = getRPM();
// Test values to check if they are consistent
bErr = false;
if(rpm==0 || rpm>rpmMax || rpm<rpmMin){
rpm = 0;
bErr = true;
}
if(fTemp<0 || fTemp>90){
fTemp=fTempPrev;
bErr = true;
}
if(fHumi<0 || fHumi>100){
fHumi=fHumiPrev;
bErr = true;
}
if(hih_state==1){
bErr = true;
}
controlLED15(bErr);
// CONCATENING & SENDING (to the Raspberry Pi):
dataStr[0]='\0';
s[0]='\0';
dtostrf(avgDust, DLENGTH, 0, s);
StrAppend(dataStr, s, DLENGTH, false);
dtostrf(medDust, DLENGTH, 0, s);
StrAppend(dataStr, s, DLENGTH, false);
dtostrf(stdevDust, DLENGTH, 0, s);
StrAppend(dataStr, s, DLENGTH, false);
dtostrf(fTemp, TLENGTH, TPREC, s);
StrAppend(dataStr, s, TLENGTH, false);
dtostrf(fHumi, HLENGTH, HPREC, s);
StrAppend(dataStr, s, HLENGTH, false);
dtostrf(deltaTime, TIMELENGTH, 0, s);
StrAppend(dataStr, s, TIMELENGTH, false);
dtostrf(hih_state, SLENGTH, 0, s);
StrAppend(dataStr, s, SLENGTH, false);
dtostrf(rpm, RPMLENGTH, 0, s);
StrAppend(dataStr, s, RPMLENGTH, true);
Serial.println(dataStr);
// Wait 2.5 seconds before starting the next series of measurements
delay(waitTime);
}
}
// CONCATENATION OF THE RESULT
void StrAppend(char* strDest, char* strSource, int iLen, boolean bEnd){
int i;
for(i=0;i<=iLen && strSource[i]!='\0';i++){
strDest[index+i] = strSource[i];
}
if(bEnd == true){
strDest[index+i]='\0';
index = 0;
}
else{
strDest[index+i] =',';
strDest[index+i+1] = '\0';
index += iLen+1;
}
}
// READ AN INT VALUE TYPED BY THE USER (value from 0 to 9999)
int readCmd(char* com){
int s;
int m;
int c;
int d;
int u;
int r;
if(com[0]==0){
u = -1;
d = 0;
c = 0;
m = 0;
s = 0;
}
else if(com[1]==0){
u = com[0]-48;
d = 0;
c = 0;
m = 0;
s = 0;
}
else if(com[2]==0){
u = (com[1]-48);
d = (com[0]-48);
c = 0;
m = 0;
s = 0;
}
else if(com[3]==0){
u = (com[2]-48);
d = (com[1]-48);
c = (com[0]-48);
m = 0;
s = 0;
}
else if(com[4]==0){
u = (com[3]-48);
d = (com[2]-48);
c = (com[1]-48);
m = (com[0]-48);
s = 0;
}
else if(com[4]!=0){
u = (com[4]-48);
d = (com[3]-48);
c = (com[2]-48);
m = (com[1]-48);
s = (com[0]-48);
}
r = s*10000 + m*1000 + c*100 + d*10 + u;
return r;
}
void SET_PWM(void){
char* arg;
int tmp;
arg = SCmd.next();
tmp = readCmd(arg);
if(tmp>=0 && tmp<=100){
fanSpeed = tmp;
setRPM(fanSpeed);
Serial.print("OK:PWM=");
Serial.println(fanSpeed);
}
else{
Serial.println("INVALID VALUE");
}
}
void SET_MES(void){
char* arg;
int tmp;
arg = SCmd.next();
tmp = readCmd(arg);
if(tmp>=1 && tmp<=100){
nMeasConf = tmp;
nMeasure = nMeasConf - 1;
Serial.print("OK:MES=");
Serial.println(nMeasConf);
}
else{
Serial.println("INVALID VALUE");
}
}
void SET_RTO(void){
char* arg;
int tmp;
arg = SCmd.next();
tmp = readCmd(arg);
if(tmp>=1 && tmp<=1000){
rpmTimeout = tmp;
setRPMTimeout(rpmTimeout);
Serial.print("OK:RTO=");
Serial.println(rpmTimeout);
}
else{
Serial.println("INVALID VALUE");
}
}
void SET_WTT(void){
char* arg;
int tmp;
arg = SCmd.next();
tmp = readCmd(arg);
if(tmp>=100 && tmp<=20000){
waitTime = tmp;
Serial.print("OK:WTT=");
Serial.println(waitTime);
}
else{
Serial.println("INVALID VALUE");
}
}
void SET_RMN(void){
char* arg;
int tmp;
arg = SCmd.next();
tmp = readCmd(arg);
rpmMin = tmp;
Serial.print("OK:RMN=");
Serial.println(rpmMin);
}
void SET_RMX(void){
char* arg;
int tmp;
arg = SCmd.next();
tmp = readCmd(arg);
rpmMax = tmp;
Serial.print("OK:RMX=");
Serial.println(rpmMax);
}
void SET_DEF(void){
fanSpeed = FAN_SPEED;
setRPM(fanSpeed);
rpmTimeout = RPM_TIMEOUT;
setRPMTimeout(rpmTimeout);
nMeasConf = NMEAS;
nMeasure = NMEAS - 1;
waitTime = WAIT_TIME;
rpmMin = RPMMIN;
rpmMax = RPMMAX;
Serial.println("OK:DEFAULT CONFIG RESTORED");
}
void GET_PWM(void){
Serial.print("PWM=");
Serial.println(fanSpeed);
}
void GET_MES(void){
Serial.print("MES=");
Serial.println(nMeasConf);
}
void GET_RTO(void){
Serial.print("RTO=");
Serial.println(rpmTimeout);
}
void GET_WTT(void){
Serial.print("WTT=");
Serial.println(waitTime);
}
void GET_RMN(void){
Serial.print("RMN=");
Serial.println(rpmMin);
}
void GET_RMX(void){
Serial.print("RMX=");
Serial.println(rpmMax);
}
void GET_ALL(void){
Serial.print("PWM=");
Serial.println(fanSpeed);
Serial.print("MES=");
Serial.println(nMeasConf);
Serial.print("RTO=");
Serial.println(rpmTimeout);
Serial.print("WTT=");
Serial.println(waitTime);
Serial.print("RMN=");
Serial.println(rpmMin);
Serial.print("RMX=");
Serial.println(rpmMax);
}
void GET_RPM(void){
Serial.print("RPM=");
Serial.println(getRPM());
}
void EEP_BRN(void){
EEPROM_write_int(DCYADDR, fanSpeed);
EEPROM_write_int(RPMTOADDR, rpmTimeout);
EEPROM_write_int(NMEASADDR, nMeasConf);
EEPROM_write_int(WTIMEADDR, waitTime);
EEPROM_write_int(RPMMINADDR, rpmMin);
EEPROM_write_int(RPMMAXADDR, rpmMax);
Serial.println("CONFIG BURNED IN EEPROM");
}
void EEP_RST(void){
fanSpeed = EEPROM_read_int(DCYADDR);
setRPM(fanSpeed);
rpmTimeout = EEPROM_read_int(RPMTOADDR);
setRPMTimeout(rpmTimeout);
nMeasConf = EEPROM_read_int(NMEASADDR);
nMeasure = nMeasConf - 1;
waitTime = EEPROM_read_int(WTIMEADDR);
rpmMin = EEPROM_read_int(RPMMINADDR);
rpmMax = EEPROM_read_int(RPMMAXADDR);
Serial.println("OK:CONFIG RESTORED FROM EEPROM");
}
void EEP_PRT(void){
Serial.println("EEPROM CONFIG:");
Serial.print("PWM=");
Serial.println(EEPROM_read_int(DCYADDR));
Serial.print("MES=");
Serial.println(EEPROM_read_int(NMEASADDR));
Serial.print("RTO=");
Serial.println(EEPROM_read_int(RPMTOADDR));
Serial.print("WTT=");
Serial.println(EEPROM_read_int(WTIMEADDR));
Serial.print("RMN=");
Serial.println(EEPROM_read_int(RPMMINADDR));
Serial.print("RMX=");
Serial.println(EEPROM_read_int(RPMMAXADDR));
}
void RUN(void){
bRun = true;
Serial.println("OK:RUN");
}
void STOP(void){
bRun = false;
Serial.println("OK:STOP");
}
void HELP(void){
Serial.println("List of all commands. Please refer to commands.rst");
Serial.println("GET_ or SET_");
Serial.println("............PWM");
Serial.println("............MES");
Serial.println("............RTO");
Serial.println("............WTT");
Serial.println("............RMN/RMX");
Serial.println("............RPM");
Serial.println("GET_ALL");
Serial.println("SET_DEF");
Serial.println("EEP_");
Serial.println("....BRN");
Serial.println("....RST");
Serial.println("....PRT");
Serial.println("RUN");
Serial.println("STOP");
}
void unrecognized(){
Serial.println("UNKNOWN COMMAND, TYPE HELP TO GET COMMANDS");
}
// WRITES AN INTEGER ON 16 BITS (val) AT SPECIFIED ADDRESS (addr) in EEPROM MEMORY
// Caution: integers are written on 2 memory words (16 bits) which mean you have to space out
// addresses of 2. ie: addr1=0, addr2=2, addr3=4...
void EEPROM_write_int(int addr, int val){
uint8_t low=0;
uint8_t high=0;
low = val & FSR;
high = (val >> 8) & FSR;
EEPROM.write(addr,high);
EEPROM.write(addr+1,low);
}
// READS AN INTEGER ON 16 BITS AT THE SPECIFIED ADDRESS (addr) IN EEPROM MEMORY
int EEPROM_read_int(int addr){
uint8_t low=0;
uint8_t high=0;
int val=0;
high = EEPROM.read(addr);
low = EEPROM.read(addr+1);
val = low + (high << 8);
return val;
}
/*
I2C.cpp - I2C library
Copyright (c) 2011-2012 Wayne Truchsess. All right reserved.
Rev 5.0 - January 24th, 2012
- Removed the use of interrupts completely from the library
so TWI state changes are now polled.
- Added calls to lockup() function in most functions
to combat arbitration problems
- Fixed scan() procedure which left timeouts enabled
and set to 80msec after exiting procedure
- Changed scan() address range back to 0 - 0x7F
- Removed all Wire legacy functions from library
- A big thanks to Richard Baldwin for all the testing
and feedback with debugging bus lockups!
Rev 4.0 - January 14th, 2012
- Updated to make compatible with 8MHz clock frequency
Rev 3.0 - January 9th, 2012
- Modified library to be compatible with Arduino 1.0
- Changed argument type from boolean to uint8_t in pullUp(),
setSpeed() and receiveByte() functions for 1.0 compatability
- Modified return values for timeout feature to report
back where in the transmission the timeout occured.
- added function scan() to perform a bus scan to find devices
attached to the I2C bus. Similar to work done by Todbot
and Nick Gammon
Rev 2.0 - September 19th, 2011
- Added support for timeout function to prevent
and recover from bus lockup (thanks to PaulS
and CrossRoads on the Arduino forum)
- Changed return type for stop() from void to
uint8_t to handle timeOut function
Rev 1.0 - August 8th, 2011
This is a modified version of the Arduino Wire/TWI
library. Functions were rewritten to provide more functionality
and also the use of Repeated Start. Some I2C devices will not
function correctly without the use of a Repeated Start. The
initial version of this library only supports the Master.
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
*/
#if(ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <inttypes.h>
#include "I2C.h"
uint8_t I2C::bytesAvailable = 0;
uint8_t I2C::bufferIndex = 0;
uint8_t I2C::totalBytes = 0;
uint16_t I2C::timeOutDelay = 0;
I2C::I2C()
{
}
////////////// Public Methods ////////////////////////////////////////
void I2C::begin()
{
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
// activate internal pull-ups for twi
// as per note from atmega8 manual pg167
sbi(PORTC, 4);
sbi(PORTC, 5);
#else
// activate internal pull-ups for twi
// as per note from atmega128 manual pg204
sbi(PORTD, 0);
sbi(PORTD, 1);
#endif
// initialize twi prescaler and bit rate
cbi(TWSR, TWPS0);
cbi(TWSR, TWPS1);
TWBR = ((F_CPU / 100000) - 16) / 2;
// enable twi module and acks
TWCR = _BV(TWEN) | _BV(TWEA);
}
void I2C::end()
{
TWCR = 0;
}
void I2C::timeOut(uint16_t _timeOut)
{
timeOutDelay = _timeOut;
}
void I2C::setSpeed(uint8_t _fast)
{
if(!_fast)
{
TWBR = ((F_CPU / 100000) - 16) / 2;
}
else
{
TWBR = ((F_CPU / 400000) - 16) / 2;
}
}
void I2C::pullup(uint8_t activate)
{
if(activate)
{
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
// activate internal pull-ups for twi
// as per note from atmega8 manual pg167
sbi(PORTC, 4);
sbi(PORTC, 5);
#else
// activate internal pull-ups for twi
// as per note from atmega128 manual pg204
sbi(PORTD, 0);
sbi(PORTD, 1);
#endif
}
else
{
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
// deactivate internal pull-ups for twi
// as per note from atmega8 manual pg167
cbi(PORTC, 4);
cbi(PORTC, 5);
#else
// deactivate internal pull-ups for twi
// as per note from atmega128 manual pg204
cbi(PORTD, 0);
cbi(PORTD, 1);
#endif
}
}
void I2C::scan()
{
uint16_t tempTime = timeOutDelay;
timeOut(80);
uint8_t totalDevicesFound = 0;
Serial.println("Scanning for devices...please wait");
Serial.println();
for(uint8_t s = 0; s <= 0x7F; s++)
{
returnStatus = 0;
returnStatus = start();
if(!returnStatus)
{
returnStatus = sendAddress(SLA_W(s));
}
if(returnStatus)
{
if(returnStatus == 1)
{
Serial.println("There is a problem with the bus, could not complete scan");
timeOutDelay = tempTime;
return;
}
}
else
{
Serial.print("Found device at address - ");
Serial.print(" 0x");
Serial.println(s,HEX);
totalDevicesFound++;
}
stop();
}
if(!totalDevicesFound){Serial.println("No devices found");}
timeOutDelay = tempTime;
}
uint8_t I2C::available()
{
return(bytesAvailable);
}
uint8_t I2C::receive()
{
bufferIndex = totalBytes - bytesAvailable;
if(!bytesAvailable)
{
bufferIndex = 0;
return(0);
}
bytesAvailable--;
return(data[bufferIndex]);
}
/*return values for new functions that use the timeOut feature
will now return at what point in the transmission the timeout
occurred. Looking at a full communication sequence between a
master and slave (transmit data and then readback data) there
a total of 7 points in the sequence where a timeout can occur.
These are listed below and correspond to the returned value:
1 - Waiting for successful completion of a Start bit
2 - Waiting for ACK/NACK while addressing slave in transmit mode (MT)
3 - Waiting for ACK/NACK while sending data to the slave
4 - Waiting for successful completion of a Repeated Start
5 - Waiting for ACK/NACK while addressing slave in receiver mode (MR)
6 - Waiting for ACK/NACK while receiving data from the slave
7 - Waiting for successful completion of the Stop bit
All possible return values:
0 Function executed with no errors
1 - 7 Timeout occurred, see above list
8 - 0xFF See datasheet for exact meaning */
/////////////////////////////////////////////////////
uint8_t I2C::write(uint8_t address, uint8_t registerAddress)
{
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_W(address));
if(returnStatus)
{
if(returnStatus == 1){return(2);}
return(returnStatus);
}
returnStatus = sendByte(registerAddress);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
uint8_t I2C::write(int address, int registerAddress)
{
return(write((uint8_t) address, (uint8_t) registerAddress));
}
uint8_t I2C::write(uint8_t address, uint8_t registerAddress, uint8_t data)
{
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_W(address));
if(returnStatus)
{
if(returnStatus == 1){return(2);}
return(returnStatus);
}
returnStatus = sendByte(registerAddress);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
returnStatus = sendByte(data);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
uint8_t I2C::write(int address, int registerAddress, int data)
{
return(write((uint8_t) address, (uint8_t) registerAddress, (uint8_t) data));
}
uint8_t I2C::write(uint8_t address, uint8_t registerAddress, char *data)
{
uint8_t bufferLength = strlen(data);
returnStatus = 0;
returnStatus = write(address, registerAddress, (uint8_t*)data, bufferLength);
return(returnStatus);
}
uint8_t I2C::write(uint8_t address, uint8_t registerAddress, uint8_t *data, uint8_t numberBytes)
{
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_W(address));
if(returnStatus)
{
if(returnStatus == 1){return(2);}
return(returnStatus);
}
returnStatus = sendByte(registerAddress);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
for (uint8_t i = 0; i < numberBytes; i++)
{
returnStatus = sendByte(data[i]);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
uint8_t I2C::read(int address, int numberBytes)
{
return(read((uint8_t) address, (uint8_t) numberBytes));
}
uint8_t I2C::read(uint8_t address, uint8_t numberBytes)
{
bytesAvailable = 0;
bufferIndex = 0;
if(numberBytes == 0){numberBytes++;}
nack = numberBytes - 1;
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_R(address));
if(returnStatus)
{
if(returnStatus == 1){return(5);}
return(returnStatus);
}
for(uint8_t i = 0; i < numberBytes; i++)
{
if( i == nack )
{
returnStatus = receiveByte(0);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_NACK){return(returnStatus);}
}
else
{
returnStatus = receiveByte(1);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_ACK){return(returnStatus);}
}
data[i] = TWDR;
bytesAvailable = i+1;
totalBytes = i+1;
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
uint8_t I2C::read(int address, int registerAddress, int numberBytes)
{
return(read((uint8_t) address, (uint8_t) registerAddress, (uint8_t) numberBytes));
}
uint8_t I2C::read(uint8_t address, uint8_t registerAddress, uint8_t numberBytes)
{
bytesAvailable = 0;
bufferIndex = 0;
if(numberBytes == 0){numberBytes++;}
nack = numberBytes - 1;
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_W(address));
if(returnStatus)
{
if(returnStatus == 1){return(2);}
return(returnStatus);
}
returnStatus = sendByte(registerAddress);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
returnStatus = start();
if(returnStatus)
{
if(returnStatus == 1){return(4);}
return(returnStatus);
}
returnStatus = sendAddress(SLA_R(address));
if(returnStatus)
{
if(returnStatus == 1){return(5);}
return(returnStatus);
}
for(uint8_t i = 0; i < numberBytes; i++)
{
if( i == nack )
{
returnStatus = receiveByte(0);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_NACK){return(returnStatus);}
}
else
{
returnStatus = receiveByte(1);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_ACK){return(returnStatus);}
}
data[i] = TWDR;
bytesAvailable = i+1;
totalBytes = i+1;
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
uint8_t I2C::read(uint8_t address, uint8_t numberBytes, uint8_t *dataBuffer)
{
bytesAvailable = 0;
bufferIndex = 0;
if(numberBytes == 0){numberBytes++;}
nack = numberBytes - 1;
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_R(address));
if(returnStatus)
{
if(returnStatus == 1){return(5);}
return(returnStatus);
}
for(uint8_t i = 0; i < numberBytes; i++)
{
if( i == nack )
{
returnStatus = receiveByte(0);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_NACK){return(returnStatus);}
}
else
{
returnStatus = receiveByte(1);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_ACK){return(returnStatus);}
}
dataBuffer[i] = TWDR;
bytesAvailable = i+1;
totalBytes = i+1;
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
uint8_t I2C::read(uint8_t address, uint8_t registerAddress, uint8_t numberBytes, uint8_t *dataBuffer)
{
bytesAvailable = 0;
bufferIndex = 0;
if(numberBytes == 0){numberBytes++;}
nack = numberBytes - 1;
returnStatus = 0;
returnStatus = start();
if(returnStatus){return(returnStatus);}
returnStatus = sendAddress(SLA_W(address));
if(returnStatus)
{
if(returnStatus == 1){return(2);}
return(returnStatus);
}
returnStatus = sendByte(registerAddress);
if(returnStatus)
{
if(returnStatus == 1){return(3);}
return(returnStatus);
}
returnStatus = start();
if(returnStatus)
{
if(returnStatus == 1){return(4);}
return(returnStatus);
}
returnStatus = sendAddress(SLA_R(address));
if(returnStatus)
{
if(returnStatus == 1){return(5);}
return(returnStatus);
}
for(uint8_t i = 0; i < numberBytes; i++)
{
if( i == nack )
{
returnStatus = receiveByte(0);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_NACK){return(returnStatus);}
}
else
{
returnStatus = receiveByte(1);
if(returnStatus == 1){return(6);}
if(returnStatus != MR_DATA_ACK){return(returnStatus);}
}
dataBuffer[i] = TWDR;
bytesAvailable = i+1;
totalBytes = i+1;
}
returnStatus = stop();
if(returnStatus)
{
if(returnStatus == 1){return(7);}
return(returnStatus);
}
return(returnStatus);
}
/////////////// Private Methods ////////////////////////////////////////
uint8_t I2C::start()
{
unsigned long startingTime = millis();
TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
while (!(TWCR & (1<<TWINT)))
{
if(!timeOutDelay){continue;}
if((millis() - startingTime) >= timeOutDelay)
{
lockUp();
return(1);
}
}
if ((TWI_STATUS == START) || (TWI_STATUS == REPEATED_START))
{
return(0);
}
if (TWI_STATUS == LOST_ARBTRTN)
{
uint8_t bufferedStatus = TWI_STATUS;
lockUp();
return(bufferedStatus);
}
return(TWI_STATUS);
}
uint8_t I2C::sendAddress(uint8_t i2cAddress)
{
TWDR = i2cAddress;
unsigned long startingTime = millis();
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)))
{
if(!timeOutDelay){continue;}
if((millis() - startingTime) >= timeOutDelay)
{
lockUp();
return(1);
}
}
if ((TWI_STATUS == MT_SLA_ACK) || (TWI_STATUS == MR_SLA_ACK))
{
return(0);
}
uint8_t bufferedStatus = TWI_STATUS;
if ((TWI_STATUS == MT_SLA_NACK) || (TWI_STATUS == MR_SLA_NACK))
{
stop();
return(bufferedStatus);
}
else
{
lockUp();
return(bufferedStatus);
}
}
uint8_t I2C::sendByte(uint8_t i2cData)
{
TWDR = i2cData;
unsigned long startingTime = millis();
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)))
{
if(!timeOutDelay){continue;}
if((millis() - startingTime) >= timeOutDelay)
{
lockUp();
return(1);
}
}
if (TWI_STATUS == MT_DATA_ACK)
{
return(0);
}
uint8_t bufferedStatus = TWI_STATUS;
if (TWI_STATUS == MT_DATA_NACK)
{
stop();
return(bufferedStatus);
}
else
{
lockUp();
return(bufferedStatus);
}
}
uint8_t I2C::receiveByte(uint8_t ack)
{
unsigned long startingTime = millis();
if(ack)
{
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
}
else
{
TWCR = (1<<TWINT) | (1<<TWEN);
}
while (!(TWCR & (1<<TWINT)))
{
if(!timeOutDelay){continue;}
if((millis() - startingTime) >= timeOutDelay)
{
lockUp();
return(1);
}
}
if (TWI_STATUS == LOST_ARBTRTN)
{
uint8_t bufferedStatus = TWI_STATUS;
lockUp();
return(bufferedStatus);
}
return(TWI_STATUS);
}
uint8_t I2C::stop()
{
unsigned long startingTime = millis();
TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO);
while ((TWCR & (1<<TWSTO)))
{
if(!timeOutDelay){continue;}
if((millis() - startingTime) >= timeOutDelay)
{
lockUp();
return(1);
}
}
return(0);
}
void I2C::lockUp()
{
TWCR = 0; //releases SDA and SCL lines to high impedance
TWCR = _BV(TWEN) | _BV(TWEA); //reinitialize TWI
}
I2C I2c = I2C();
/*
I2C.h - I2C library
Copyright (c) 2011-2012 Wayne Truchsess. All right reserved.
Rev 5.0 - January 24th, 2012
- Removed the use of interrupts completely from the library
so TWI state changes are now polled.
- Added calls to lockup() function in most functions
to combat arbitration problems
- Fixed scan() procedure which left timeouts enabled
and set to 80msec after exiting procedure
- Changed scan() address range back to 0 - 0x7F
- Removed all Wire legacy functions from library
- A big thanks to Richard Baldwin for all the testing
and feedback with debugging bus lockups!
Rev 4.0 - January 14th, 2012
- Updated to make compatible with 8MHz clock frequency
Rev 3.0 - January 9th, 2012
- Modified library to be compatible with Arduino 1.0
- Changed argument type from boolean to uint8_t in pullUp(),
setSpeed() and receiveByte() functions for 1.0 compatability
- Modified return values for timeout feature to report
back where in the transmission the timeout occured.
- added function scan() to perform a bus scan to find devices
attached to the I2C bus. Similar to work done by Todbot
and Nick Gammon
Rev 2.0 - September 19th, 2011
- Added support for timeout function to prevent
and recover from bus lockup (thanks to PaulS
and CrossRoads on the Arduino forum)
- Changed return type for stop() from void to
uint8_t to handle timeOut function
Rev 1.0 - August 8th, 2011
This is a modified version of the Arduino Wire/TWI
library. Functions were rewritten to provide more functionality
and also the use of Repeated Start. Some I2C devices will not
function correctly without the use of a Repeated Start. The
initial version of this library only supports the Master.
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
*/
#if(ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <inttypes.h>
#ifndef I2C_h
#define I2C_h
#define START 0x08
#define REPEATED_START 0x10
#define MT_SLA_ACK 0x18
#define MT_SLA_NACK 0x20
#define MT_DATA_ACK 0x28
#define MT_DATA_NACK 0x30
#define MR_SLA_ACK 0x40
#define MR_SLA_NACK 0x48
#define MR_DATA_ACK 0x50
#define MR_DATA_NACK 0x58
#define LOST_ARBTRTN 0x38
#define TWI_STATUS (TWSR & 0xF8)
#define SLA_W(address) (address << 1)
#define SLA_R(address) ((address << 1) + 0x01)
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define MAX_BUFFER_SIZE 32
class I2C
{
public:
I2C();
void begin();
void end();
void timeOut(uint16_t);
void setSpeed(uint8_t);
void pullup(uint8_t);
void scan();
uint8_t available();
uint8_t receive();
uint8_t write(uint8_t, uint8_t);
uint8_t write(int, int);
uint8_t write(uint8_t, uint8_t, uint8_t);
uint8_t write(int, int, int);
uint8_t write(uint8_t, uint8_t, char*);
uint8_t write(uint8_t, uint8_t, uint8_t*, uint8_t);
uint8_t read(uint8_t, uint8_t);
uint8_t read(int, int);
uint8_t read(uint8_t, uint8_t, uint8_t);
uint8_t read(int, int, int);
uint8_t read(uint8_t, uint8_t, uint8_t*);
uint8_t read(uint8_t, uint8_t, uint8_t, uint8_t*);
private:
uint8_t start();
uint8_t sendAddress(uint8_t);
uint8_t sendByte(uint8_t);
uint8_t receiveByte(uint8_t);
uint8_t stop();
void lockUp();
uint8_t returnStatus;
uint8_t nack;
uint8_t data[MAX_BUFFER_SIZE];
static uint8_t bytesAvailable;
static uint8_t bufferIndex;
static uint8_t totalBytes;
static uint16_t timeOutDelay;
};
extern I2C I2c;
#endif
#######################################
# Syntax Coloring Map For I2C
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
I2C KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
timeOut KEYWORD2
setSpeed KEYWORD2
pullup KEYWORD2
scan KEYWORD2
write KEYWORD2
read KEYWORD2
available KEYWORD2
receive KEYWORD2
#######################################
# Instances (KEYWORD2)
#######################################
I2c KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
\ No newline at end of file
/*******************************************************************************
SerialCommand - An Arduino library to tokenize and parse commands received over
a serial port.
Copyright (C) 2011-2013 Steven Cogswell <steven.cogswell@gmail.com>
http://awtfy.com
See SerialCommand.h for version history.
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************************/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "SerialCommand.h"
#include <string.h>
#ifndef SERIALCOMMAND_HARDWAREONLY
#include <SoftwareSerial.h>
#endif
// Constructor makes sure some things are set.
SerialCommand::SerialCommand()
{
usingSoftwareSerial=0;
strncpy(delim," ",MAXDELIMETER); // strtok_r needs a null-terminated string
term='\r'; // return character, default terminator for commands
numCommand=0; // Number of callback handlers installed
clearBuffer();
}
#ifndef SERIALCOMMAND_HARDWAREONLY
// Constructor to use a SoftwareSerial object
SerialCommand::SerialCommand(SoftwareSerial &_SoftSer)
{
usingSoftwareSerial=1;
SoftSerial = &_SoftSer;
strncpy(delim," ",MAXDELIMETER); // strtok_r needs a null-terminated string
term='\r'; // return character, default terminator for commands
numCommand=0; // Number of callback handlers installed
clearBuffer();
}
#endif
//
// Initialize the command buffer being processed to all null characters
//
void SerialCommand::clearBuffer()
{
for (int i=0; i<SERIALCOMMANDBUFFER; i++)
{
buffer[i]='\0';
}
bufPos=0;
}
// Retrieve the next token ("word" or "argument") from the Command buffer.
// returns a NULL if no more tokens exist.
char *SerialCommand::next()
{
char *nextToken;
nextToken = strtok_r(NULL, delim, &last);
return nextToken;
}
// This checks the Serial stream for characters, and assembles them into a buffer.
// When the terminator character (default '\r') is seen, it starts parsing the
// buffer for a prefix command, and calls handlers setup by addCommand() member
void SerialCommand::readSerial()
{
// If we're using the Hardware port, check it. Otherwise check the user-created SoftwareSerial Port
#ifdef SERIALCOMMAND_HARDWAREONLY
while (Serial.available() > 0)
#else
while ((usingSoftwareSerial==0 && Serial.available() > 0) || (usingSoftwareSerial==1 && SoftSerial->available() > 0) )
#endif
{
int i;
boolean matched;
if (usingSoftwareSerial==0) {
// Hardware serial port
inChar=Serial.read(); // Read single available character, there may be more waiting
} else {
#ifndef SERIALCOMMAND_HARDWAREONLY
// SoftwareSerial port
inChar = SoftSerial->read(); // Read single available character, there may be more waiting
#endif
}
#ifdef SERIALCOMMANDDEBUG
Serial.print(inChar); // Echo back to serial stream
#endif
if (inChar==term) { // Check for the terminator (default '\r') meaning end of command
#ifdef SERIALCOMMANDDEBUG
Serial.print("Received: ");
Serial.println(buffer);
#endif
bufPos=0; // Reset to start of buffer
token = strtok_r(buffer,delim,&last); // Search for command at start of buffer
if (token == NULL) return;
matched=false;
for (i=0; i<numCommand; i++) {
#ifdef SERIALCOMMANDDEBUG
Serial.print("Comparing [");
Serial.print(token);
Serial.print("] to [");
Serial.print(CommandList[i].command);
Serial.println("]");
#endif
// Compare the found command against the list of known commands for a match
if (strncmp(token,CommandList[i].command,SERIALCOMMANDBUFFER) == 0)
{
#ifdef SERIALCOMMANDDEBUG
Serial.print("Matched Command: ");
Serial.println(token);
#endif
// Execute the stored handler function for the command
(*CommandList[i].function)();
clearBuffer();
matched=true;
break;
}
}
if (matched==false) {
(*defaultHandler)();
clearBuffer();
}
}
if (isprint(inChar)) // Only printable characters into the buffer
{
buffer[bufPos++]=inChar; // Put character into buffer
buffer[bufPos]='\0'; // Null terminate
if (bufPos > SERIALCOMMANDBUFFER-1) bufPos=0; // wrap buffer around if full
}
}
}
// Adds a "command" and a handler function to the list of available commands.
// This is used for matching a found token in the buffer, and gives the pointer
// to the handler function to deal with it.
void SerialCommand::addCommand(const char *command, void (*function)())
{
if (numCommand < 30) {
#ifdef SERIALCOMMANDDEBUG
Serial.print(numCommand);
Serial.print("-");
Serial.print("Adding command for ");
Serial.println(command);
#endif
strncpy(CommandList[numCommand].command,command,SERIALCOMMANDBUFFER);
CommandList[numCommand].function = function;
numCommand++;
} else {
// In this case, you tried to push more commands into the buffer than it is compiled to hold.
// Not much we can do since there is no real visible error assertion, we just ignore adding
// the command
#ifdef SERIALCOMMANDDEBUG
Serial.println("Too many handlers - recompile changing MAXSERIALCOMMANDS");
#endif
}
}
// This sets up a handler to be called in the event that the receveived command string
// isn't in the list of things with handlers.
void SerialCommand::addDefaultHandler(void (*function)())
{
defaultHandler = function;
}
/*******************************************************************************
SerialCommand - An Arduino library to tokenize and parse commands received over
a serial port.
Copyright (C) 2011-2013 Steven Cogswell <steven.cogswell@gmail.com>
http://awtfy.com
Version 20131021A.
Version History:
May 11 2011 - Initial version
May 13 2011 - Prevent overwriting bounds of SerialCommandCallback[] array in addCommand()
defaultHandler() for non-matching commands
Mar 2012 - Some const char * changes to make compiler happier about deprecated warnings.
Arduino 1.0 compatibility (Arduino.h header)
Oct 2013 - SerialCommand object can be created using a SoftwareSerial object, for SoftwareSerial
support. Requires #include <SoftwareSerial.h> in your sketch even if you don't use
a SoftwareSerial port in the project. sigh. See Example Sketch for usage.
Oct 2013 - Conditional compilation for the SoftwareSerial support, in case you really, really
hate it and want it removed.
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************************/
#ifndef SerialCommand_h
#define SerialCommand_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
// If you want to use SerialCommand with the hardware serial port only, and want to disable
// SoftwareSerial support, and thus don't have to use "#include <SoftwareSerial.h>" in your
// sketches, then uncomment this define for SERIALCOMMAND_HARDWAREONLY, and comment out the
// corresponding #undef line.
//
// You don't have to use SoftwareSerial features if this is not defined, you can still only use
// the Hardware serial port, just that this way lets you get out of having to include
// the SoftwareSerial.h header.
//#define SERIALCOMMAND_HARDWAREONLY 1
#undef SERIALCOMMAND_HARDWAREONLY
#ifdef SERIALCOMMAND_HARDWAREONLY
#warning "Warning: Building SerialCommand without SoftwareSerial Support"
#endif
#ifndef SERIALCOMMAND_HARDWAREONLY
#include <SoftwareSerial.h>
#endif
#include <string.h>
#define SERIALCOMMANDBUFFER 16
#define MAXSERIALCOMMANDS 30
#define MAXDELIMETER 2
#define SERIALCOMMANDDEBUG 1
#undef SERIALCOMMANDDEBUG // Comment this out to run the library in debug mode (verbose messages)
class SerialCommand
{
public:
SerialCommand(); // Constructor
#ifndef SERIALCOMMAND_HARDWAREONLY
SerialCommand(SoftwareSerial &SoftSer); // Constructor for using SoftwareSerial objects
#endif
void clearBuffer(); // Sets the command buffer to all '\0' (nulls)
char *next(); // returns pointer to next token found in command buffer (for getting arguments to commands)
void readSerial(); // Main entry point.
void addCommand(const char *, void(*)()); // Add commands to processing dictionary
void addDefaultHandler(void (*function)()); // A handler to call when no valid command received.
private:
char inChar; // A character read from the serial stream
char buffer[SERIALCOMMANDBUFFER]; // Buffer of stored characters while waiting for terminator character
int bufPos; // Current position in the buffer
char delim[MAXDELIMETER]; // null-terminated list of character to be used as delimeters for tokenizing (default " ")
char term; // Character that signals end of command (default '\r')
char *token; // Returned token from the command buffer as returned by strtok_r
char *last; // State variable used by strtok_r during processing
typedef struct _callback {
char command[SERIALCOMMANDBUFFER];
void (*function)();
} SerialCommandCallback; // Data structure to hold Command/Handler function key-value pairs
int numCommand;
SerialCommandCallback CommandList[MAXSERIALCOMMANDS]; // Actual definition for command/handler array
void (*defaultHandler)(); // Pointer to the default handler function
int usingSoftwareSerial; // Used as boolean to see if we're using SoftwareSerial object or not
#ifndef SERIALCOMMAND_HARDWAREONLY
SoftwareSerial *SoftSerial; // Pointer to a user-created SoftwareSerial object
#endif
};
#endif //SerialCommand_h
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
// Dust measurement example:
// You need to include lib_dust.h
#include <lib_dust.h>
float dust=0;
float avgDust, medDust, stdevDust;
void setup(){
Serial.begin(9600);
initDust(); // Don't forget to call initDust() to set A0 pin as input pin
}
void loop(){
float myAvgDust, myMedDust, myStdevDust; // my own calirated values
dust = measureDust(avgDust, medDust, stdevDust); // Then, you just have to call measureDust() whenever you want, and get the dust level
Serial.print("Dust value averaged by the dust library: ");
Serial.println(dust);
// finer custom made calibration for the sensor
myAvgDust = ((avgDust*0.0049)-0.0256)*120000-38000;
myMedDust = ((medDust*0.0049)-0.0256)*120000-38000;
myStdevDust = stdevDust*588;
Serial.println("My own calibrated values: ");
Serial.println(myAvgDust);
Serial.println(myMedDust);
Serial.println(myStdevDust);
delay(2000);
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <lib_dust.h>
// GLOBALS
unsigned int dustPin=0;
unsigned int ledPower=2;
unsigned int delayTime=280;
unsigned int delayTime2=40;
float offTime=9680; // so that delayTime + delayTime2 + offTime = 10ms
unsigned int skip_measurements=50; // skip the first 50 mesurements of a series
unsigned int dustVal=0;
float voltage = 0;
float dustdensity = 0;
float ppmpercf = 0;
unsigned int dustValues[NB_MEAS]; // array storing all the measured values (10 bit)
// since we'll be doing an average over several values, we can increase the precision of each measurement to more bits
// with a simple bit shift without fearing an overflow
unsigned long sum; // to store the sum of measured dust values (4 bytes): NB_MEAS < 4194303 to avoid overflow => OK
// INITIALIZE DUST PIN
void initDust(void){
pinMode(ledPower,OUTPUT);
}
// MEASURE DUST
float measureDust(float &avgRetDust, float &medRetDust, float &stdevRetDust){
unsigned int i,j; // loop indexes
unsigned int temp; // temporary dust value
float medianDust, varDust, stdevDust, avgDust; // some statistical values
// skip initial measurements see dust_calib
for (i=0; i<skip_measurements; i++) {
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(delayTime);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(offTime);
}
// Let s do the real measurements
for (i=0; i<NB_MEAS; i++) {
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(delayTime);
dustValues[i]=analogRead(dustPin) << 6; // read the dust value and shift the 10bit ADC value by 6 bits
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(offTime);
}
#ifdef DEBUG
// display values in measurement order first
// because later the array is going to be sorted to find the median
Serial.println("all values:");
for (i=0; i<NB_MEAS; i++) {
Serial.print(i);
Serial.print(" ");
Serial.println(dustValues[i]);
}
#endif
// compute median values
for (i=0; i<NB_MEAS-1; i++) { // careful: stopping 1 index before the end
for(j=i+1; j<NB_MEAS; j++) {
if(dustValues[j] < dustValues[i]) {
// swap elements
temp = dustValues[i];
dustValues[i] = dustValues[j];
dustValues[j] = temp;
}
}
}
// compute avg
sum = 0;
for (i=0; i<NB_MEAS; i++) {
sum += dustValues[i];
}
avgDust = sum/NB_MEAS;
// compute variance
for (i=0; i<NB_MEAS; i++) {
varDust = (dustValues[i]-avgDust)*(dustValues[i]-avgDust);
}
varDust = varDust/NB_MEAS;
stdevDust = sqrt(varDust);
// now dustValues is sorted
if(NB_MEAS%2==0) {
// if there is an even number of elements, return mean of the two elements in the middle
medianDust = (dustValues[NB_MEAS/2] + dustValues[NB_MEAS/2 - 1]) / 2.0;
} else {
// else return the element in the middle
medianDust = dustValues[NB_MEAS/2];
}
#ifdef DEBUG
Serial.print("medianDust: ");
Serial.println(medianDust, 3);
Serial.print("stdevDust: ");
Serial.println(stdevDust,3);
Serial.print("avgDust: ");
Serial.println(avgDust,3);
#endif
// copy those in the results with no scaling
avgRetDust = avgDust;
medRetDust = medianDust;
stdevRetDust = stdevDust;
// default scaling for compatibility reasons...
voltage = avgDust*0.0049;
dustdensity = 0.17*voltage-0.1;
ppmpercf = (voltage-0.0256)*120000;
if (ppmpercf < 0)
ppmpercf = 0;
if (dustdensity < 0 )
dustdensity = 0;
if (dustdensity > 0.5)
dustdensity = 0.5;
return ppmpercf;
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <Arduino.h>
#define NB_MEAS 100 // Number of measurements to do: 1 every 10ms for 1 secs
void initDust(void); // Call this function to initialize the pin (A0) used to measure dust
float measureDust(float &avgRetDust, float &medRetDust, float &stdevRetDust); // Call this function will measure dust and return the value(s)
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
// Fan control and RPM measurement example:
// You need to include lib_fan.h
#include <lib_fan.h>
unsigned int duty_cycle = 0;
unsigned int speed = 0;
bool bSpeed = false;
void setup(){
Serial.begin(9600);
initFan(); // Don't forget to call initFan() to set PWM/Tachometer pins
}
void loop(){
setRPM(duty_cycle); // Call setRPM(value) to set the speed of the fan (value in percent)
delay(2000);
speed = getRPM(); // Call getRPM will return the instant RPM of the fan (or 0 if timeout)
Serial.println(speed);
if(duty_cycle<100 && bSpeed==false){
duty_cycle += 5;
}
else if(duty_cycle==100 && bSpeed==false){
bSpeed = true;
}
else if(duty_cycle>0 && bSpeed==true){
duty_cycle -= 5;
}
else if(duty_cycle==0 && bSpeed==true){
bSpeed = false;
}
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <lib_fan.h>
// GLOBALS
unsigned int RPM_Measure_Timeout = RPM_TIMEOUT; // Used to set a measure timeout
unsigned int i_Cnt; // Used to count interrupts (2 per revolution)
unsigned long s_Time, e_Time, d_Time; // Used to measure time per revolution: start, end, delta
bool b_Cnt = false; // Used to know whether the measure is finished
// INIT FAN PWM AND TACHOMETER
void initFan(void){
DDRB |= (1 << DDB6); // Set PB6 as an output (PWM output, pin 12)
DDRD &= ~(1 << DDD2); // Set PD2 as an input (Tachometer input, pin 19)
TCCR1A |= (1 << COM1B1); // Configures the Timer/Counter 1 for fast PWM
TCCR1A |= (1 << WGM11);
TCCR1A |= (1 << WGM10);
TCCR1B |= (1 << WGM13);
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS10);
OCR1A = 639; // Set the top value of PWM register to set frequency at 25kHz
OCR1B = 639/100*FAN_SPEED; // Set the default duty-cycle depending on #define FAN_SPEED (in %)
noInterrupts(); // Configures interruption for tachometer
EICRA |= (1 << ISC21); // Here, on falling edge
interrupts();
}
// GET THE RPM OF THE FAN
unsigned int getRPM(void){
unsigned int RPM_Measure = 0; // Will contain the value of instant RPMs
unsigned int i_Bcl = 0; // Used to measure the timeout
noInterrupts(); // Enable interruptions for tachometer
EIMSK |= (1 << INT2);
interrupts();
for(i_Bcl=0; i_Bcl<=RPM_Measure_Timeout; i_Bcl++){ // Watch dog for RPM measure Timeout
delay(1);
if(b_Cnt==true){ // If the measure is finished
d_Time = (e_Time-s_Time); // Then, compute the results to get duration of one revolution
RPM_Measure = (1000000/d_Time)*60; // Compute the duration to get instant RPMs
b_Cnt = false;
break;
}
}
if(i_Bcl>=RPM_Measure_Timeout){ // If there is a real timeout on the RPM measure (fan blocked)
noInterrupts(); // Disable interruptions
EIMSK &= ~(1 << INT2);
interrupts();
i_Cnt = 0; // Reset counting variable
RPM_Measure = 0; // Set RPMs to 0 (Timeout...)
}
return RPM_Measure;
}
// SET PWM DUTY CYCLE IN %
void setRPM(unsigned int pct){
unsigned int duty_cycle=0; // Temp variable
if(pct>=0 && pct<=100){ // If the value is between 0 and 100
duty_cycle = pct*639/100; // Convert the percentage to the corresponding value on 639
}
else{
duty_cycle =(639*FAN_SPEED)/100; // If the value isn't in the interval, set the default value
}
OCR1B = duty_cycle; // Affect the value on 639 to the compare register
}
// INTERRUPTION SUBROUTINE (used to count interrupts generated by the fan -> 2 per revolution)
ISR(INT2_vect, ISR_BLOCK){
i_Cnt++;
if(i_Cnt==2 && b_Cnt==false){ // If we are at the begginning of the revolution
s_Time = micros(); // Get the time
}
if(i_Cnt==4 && b_Cnt==false){ // If we are at the end of the revolution
e_Time = micros(); // Get the time
noInterrupts();
EIMSK &= ~(1 << INT2); // Stop interruptions
interrupts();
b_Cnt = true; // Set b_Cnt to true to tell the measure is finished
i_Cnt = 0; // Reset the counting variable
}
}
// SET A DIFFERENT TIMEOUT FOR RPM MEASURE (in ms)
void setRPMTimeout(unsigned int timeout){
if(timeout>=1 && timeout<=1000){
RPM_Measure_Timeout = timeout;
}
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <Arduino.h>
#define FAN_SPEED 25 // Duty-cycle of PWM in %
#define RPM_TIMEOUT 200 // RPM Measure Timeout in milliseconds
#define RPMMIN 700
#define RPMMAX 10000
void initFan(void); // Used to initialize PWM and Tachometer
unsigned int getRPM(void); // Used to get instant RPMs (returns the value)
void setRPM(unsigned int pct); // Used to set the fan speed (in percent)
void setRPMTimeout(unsigned int timeout); // Used to set an other RPM measure timeout
../I2C/I2C.cpp
\ No newline at end of file
../I2C/I2C.h
\ No newline at end of file
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
// Temperature/Humidity measurement with HIH-6120 example:
// You need to include lib_hih6120.h
#include <lib_hih6120.h>
float fT;
float fH;
unsigned long measTime=0;
int hih_state;
void setup(){
Serial.begin(9600);
initI2C(); // Don't forget to call initI2C() to be able to communicate with HIH-6120
}
void loop(){
updateTH(); // Call updateTH() when you want the HIH-6120 to perform measures
delay(50);
hih_state = getTH(&measTime); // Call getTH(unsigned int* pTime) to download HIH-6120 values in a buffer
// getTH() takes an unsigned int address (pointer) that will filled with the
// duration of the data transfert (in us) and returns the validity of the measure:
// 0: This is an unread value, 1: The value has already been read
// To be sure that the value is unread, let at least 40 ms between updateTH()
// and getTH()
fT = getTemp(); // Call getTemp() will return the value of the temperature (in *C) from the buffer
fH = getHumi(); // Call getHumi() will return the value of the humidity (in %) from the buffer
Serial.print("Temperature: ");
Serial.print(fT);
Serial.println("*C");
Serial.print("Humidity: ");
Serial.print(fH);
Serial.println("%");
Serial.print("Measure duration: ");
Serial.print(measTime);
Serial.println("us");
Serial.print("Measure validity: ");
Serial.println(hih_state);
Serial.println("");
delay(2000);
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <lib_hih6120.h>
uint8_t high_Temp, low_Temp, high_Humi, low_Humi; // 4 bytes for I2C readings
uint16_t tmp_Temp, tmp_Humi; // 2 bytes temporary variables
// INITIALIZE I2C COMMUNICATIONS FOR HIH-6120
void initI2C(void){
I2c.begin(); // Join i2c bus (address optional for master)
I2c.timeOut(200); // Set an I2C timeout of 100 ms
I2c.setSpeed(1); // Set high I2C speed (400 kHz)
I2c.pullup(0); // Disable internal pullup resistors
}
// MAKE HIH-6120 UPDATE TEMPERATURE/HUMIDITY
void updateTH(void){
I2c.write(0x27, 0x00, 0); // Make HIH-6120 updates its values.
}
// GET TEMPERATURE
float getTemp(void){
float temp = (((float)tmp_Temp/16382)*165)-40; // Calculating the value of temperature in celsius degrees
return temp;
}
// GET HUMIDITY
float getHumi(void){
float humi = ((float)tmp_Humi/16382)*100; // Calculating the value of humidity in percent
return humi;
}
// START TIMER
void startTimer(unsigned long* pTime){
*pTime = micros();
}
// END TIMER
unsigned long endTimer(unsigned long* pTime){
unsigned long end = micros();
unsigned long delta=0;
delta = end - *pTime; // calculate the time spent while acquiring data
return delta;
}
// GET TEMPERATURE/HUMIDITY
int getTH(unsigned long* pTime){
int HIH_state=1;
startTimer(pTime); // Fill pTime with the time in us
I2c.read(0x27, 4); // Request 4 bytes from HIH-6120 @ 0x27
if(I2c.available()==4){ // Get the 4 bytes containing:
high_Humi = I2c.receive(); // Humidity (on 14 bits) for the 2 first bytes
low_Humi = I2c.receive();
high_Temp = I2c.receive(); // Temperature (on 14 bits) for the 2 last bytes
low_Temp = I2c.receive();
}
*pTime = endTimer(pTime); // Returns the time difference between pTime value and now
HIH_state = (int)((high_Humi & 0xC0) >> 6); // Get the 2 status bits (00 -> Ok, 01 -> Stale values)
// Compute the values (humidity/temperature)
tmp_Temp = ((((uint16_t) high_Temp) << 8) | low_Temp) >> 2; // Assembly of 2 bytes of the temperature
tmp_Humi = (((uint16_t) (high_Humi & 0x3f)) << 8) | low_Humi; // Assembly of 2 bytes of the humidity
return HIH_state;
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <Arduino.h>
#include <stdlib.h>
#include "I2C.h"
// PROTOTYPES
void initI2C(void); // Initialize I2C communications with HIH-6120 (@0x27)
void updateTH(void); // Make HIH-6120 updates its values
float getTemp(void); // Get temperature
float getHumi(void); // Get humidity
void startTimer(unsigned long* pTime); // Fill pTime with micros()
unsigned long endTimer(unsigned long* pTime); // Returns delta time between *pTime and now
int getTH(unsigned long* pTime); // Updates temp/humi vars in the program
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <lib_leds.h>
void initLEDs(void){
DDRK |= (1 << DDK7);
DDRK |= (1 << DDK6);
PORTK &= ~(1 << DDK7);
PORTK &= ~(1 << DDK6);
}
void controlLED15(bool on){
if(on){
PORTK |= (1 << DDK7);
}
else{
PORTK &= ~(1 << DDK7);
}
}
void controlLED14(bool on){
if(on){
PORTK |= (1 << DDK6);
}
else{
PORTK &= ~(1 << DDK6);
}
}
void toggleLED15(bool tog){
bool b=((PINK & 0b10000000)>>7);
if(b && tog){
PORTK &= ~(1 << DDK7);
}
else if(~b && tog){
PORTK |= (1 << DDK7);
}
if(!tog){
PORTK &= ~(1 << DDK7);
}
}
void toggleLED14(bool tog){
bool b=((PINK & 0b01000000)>>6);
if(b && tog){
PORTK &= ~(1 << DDK6);
}
else if(~b && tog){
PORTK |= (1 << DDK6);
}
if(!tog){
PORTK &= ~(1 << DDK6);
}
}
/******************************************************************************
*
* This file is part of the DCES project.
* See http://www.ohwr.org/projects/dces-dtrhf-ser1ch-v1
*
* Copyright (C) 2016 CERN
* All rights not expressly granted are reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author DCES Dev team, dces-dev@cern.ch
*****************************************************************************/
#include <Arduino.h>
void initLEDs(void);
void controlLED14(bool on);
void controlLED15(bool on);
void toggleLED14(bool tog);
void toggleLED15(bool tog);
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment