Add firmware

parent f71b83f0
Pipeline #567 skipped with stage
#!/bin/bash
cd "$( dirname "${BASH_SOURCE[0]}" )"
pwd
cd ../..
pwd
GIT="git"
XVFB="xvfb-run -a "
function check {
echo checking $1
status=$($GIT status --porcelain | awk '/^M/' | grep $1)
[ "$status" ]
return $?
}
function brd {
if check $1
then
$XVFB eagle -C "edit .brd;
set confirm yes;
display None;
display Top Bottom Pads Vias Unrouted Dimension tPlace bPlace tName bNames Measures Document tDocu bDocu;
ratsnest;
export image $1.png 300;
set confirm no;
quit;" $1
$GIT add $1.png
fi
}
function sch {
if check $1
then
$XVFB eagle -C "edit .sch;
set confirm yes;
export image $1.png 300;
set confirm no;
quit;" $1
$GIT add $1.png
# eagle -C "set confirm yes;
# print -1 -mirror -caption -rotate -upsidedown landscape paper A4 file $1-%N.pdf;
# set confirm no;
# quit;" $1
# $GIT add $1-*.pdf
fi
}
#export DISPLAY=:1
#export TMUX=
#tmux new-session -d -s xvfb "Xvfb :1 -screen 0 1024x768x16"
brd "HW/DevBoard/DevBoard.brd"
sch "HW/DevBoard/DevBoard.sch"
#tmux kill-session -t xvfb
#killall Xvfb
.vscode
rajsat.hex
\ No newline at end of file
DPART=ATmega3288
PROJECT=rajsat
PARALELPORT=/dev/parport0
BUILDER=/opt/$(shell ls -1 /opt | grep arduino | head -n 1)#/opt/arduino-1.6.12
all:
mkdir -p /tmp/arduino
$(BUILDER)/arduino-builder \
-hardware $(BUILDER)/hardware \
-tools $(BUILDER)/hardware/tools/avr \
-tools $(BUILDER)/tools-builder \
-libraries $(BUILDER)/libraries \
-libraries ./lib \
-fqbn arduino:avr:mega:cpu=atmega2560 \
-build-path /tmp/arduino \
./src/main.cpp
cp /tmp/arduino/main.cpp.hex ./$(PROJECT).hex
load:
sleep .2
#cp /tmp/build*.tmp/upravena_RAJ4_14Mhz_power_save.cpp.hex ./upravena_RAJ4_14Mhz_power_save.hex
avrdude -v -patmega2560 -c wiring -U flash:w:$(PROJECT).hex -P /dev/$$(ls -1 /dev/ | grep ttyUSB | head -n 1) -b115200 -D
#uisp -dlpt=$(PARALELPORT) -dprog=dapa -dpart=$(DPART) --erase --upload --verify if=$(PROJECT).hex -v=3 --hash=192 -dt_sck=2
#avrdude -c dapa -p t85 -U flash:w:$(PROJECT).hex -i 100
wfb:
#avrdude -c avrispmkII -p m328p -u -U lfuse:w:0xcc:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
avrdude -c dapa -p m2560 -u -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xfd:m -i 10
#uisp -dlpt=$(PARALELPORT) -dprog=dapa --wr_fuse_l=E2 --wr_fuse_h=DB -dt_sck=200
clean:
rm -f *.o *.map *.out
read:
uisp -dlpt=$(PARALELPORT) -dprog=dapa --rd_fuses -dt_sck=300
/*
* Barometer.cpp
* A library for barometer
*
* Copyright (c) 2012 seeed technology inc.
* Website : www.seeed.cc
* Author : LG
* Create Time:
* Change Log :
*
* loovee 9-24-2014
* Change all int to short, all unsigned int to unsigned short to fit some 32bit system
* The MIT License (MIT)
*
* 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.
*/
#include "Barometer.h"
#include <Wire.h>
#include <Arduino.h>
void Barometer::init(void)
{
Wire.begin();
// Serial.print("Temperaturet: ");
ac1 = bmp085ReadInt(0xAA);
ac2 = bmp085ReadInt(0xAC);
ac3 = bmp085ReadInt(0xAE);
ac4 = bmp085ReadInt(0xB0);
ac5 = bmp085ReadInt(0xB2);
ac6 = bmp085ReadInt(0xB4);
b1 = bmp085ReadInt(0xB6);
b2 = bmp085ReadInt(0xB8);
mb = bmp085ReadInt(0xBA);
mc = bmp085ReadInt(0xBC);
md = bmp085ReadInt(0xBE);
// Serial.print("Temperaturet2: ");
}
// Read 1 byte from the BMP085 at 'address'
// Return: the read byte;
char Barometer::bmp085Read(unsigned char address)
{
//Wire.begin();
unsigned char data;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 1);
while(!Wire.available());
return Wire.read();
}
// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
short Barometer::bmp085ReadInt(unsigned char address)
{
unsigned char msb, lsb;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 2);
while(Wire.available()<2);
msb = Wire.read();
lsb = Wire.read();
return (short) msb<<8 | lsb;
}
// Read the uncompensated temperature value
unsigned short Barometer::bmp085ReadUT()
{
unsigned short ut;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x2E);
Wire.endTransmission();
delay(5);
ut = bmp085ReadInt(0xF6);
return ut;
}
// Read the uncompensated pressure value
unsigned long Barometer::bmp085ReadUP()
{
unsigned char msb, lsb, xlsb;
unsigned long up = 0;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x34 + (OSS<<6));
Wire.endTransmission();
delay(2 + (3<<OSS));
// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
msb = bmp085Read(0xF6);
lsb = bmp085Read(0xF7);
xlsb = bmp085Read(0xF8);
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
return up;
}
void Barometer::writeRegister(short deviceAddress, byte address, byte val)
{
Wire.beginTransmission(deviceAddress); // start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); // end transmission
}
short Barometer::readRegister(short deviceAddress, byte address)
{
short v;
Wire.beginTransmission(deviceAddress);
Wire.write(address); // register to read
Wire.endTransmission();
Wire.requestFrom(deviceAddress, 1); // read a byte
while(!Wire.available()) {
// waiting
}
v = Wire.read();
return v;
}
float Barometer::calcAltitude(float pressure)
{
float A = pressure/101325;
float B = 1/5.25588;
float C = pow(A,B);
C = 1 - C;
C = C /0.0000225577;
return C;
}
float Barometer::bmp085GetTemperature(unsigned short ut)
{
long x1, x2;
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
x2 = ((long)mc << 11)/(x1 + md);
PressureCompensate = x1 + x2;
float temp = ((PressureCompensate + 8)>>4);
temp = temp /10;
return temp;
}
long Barometer::bmp085GetPressure(unsigned long up)
{
long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;
b6 = PressureCompensate - 4000;
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
// Calculate B4
x1 = (ac3 * b6)>>13;
x2 = (b1 * ((b6 * b6)>>12))>>16;
x3 = ((x1 + x2) + 2)>>2;
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
b7 = ((unsigned long)(up - b3) * (50000>>OSS));
if (b7 < 0x80000000)
p = (b7<<1)/b4;
else
p = (b7/b4)<<1;
x1 = (p>>8) * (p>>8);
x1 = (x1 * 3038)>>16;
x2 = (-7357 * p)>>16;
p += (x1 + x2 + 3791)>>4;
long temp = p;
return temp;
}
/*
* Barometer.h
* A library for barometer
*
* Copyright (c) 2012 seeed technology inc.
* Website : www.seeed.cc
* Author : LG
* Create Time:
* Change Log :
*
* loovee 9-24-2014
* Change all int to short, all unsigned int to unsigned short to fit some 32bit system
*
* The MIT License (MIT)
*
*
* 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.
*/
#ifndef __BAROMETER_H__
#define __BAROMETER_H__
#include <Arduino.h>
#include <Wire.h>
const unsigned char OSS = 0;
#define BMP085_ADDRESS 0x77
class Barometer
{
public:
void init(void);
long PressureCompensate;
float bmp085GetTemperature(unsigned short ut);
long bmp085GetPressure(unsigned long up);
float calcAltitude(float pressure);
unsigned short bmp085ReadUT(void);
unsigned long bmp085ReadUP(void);
// private:
short ac1;
short ac2;
short ac3;
unsigned short ac4;
unsigned short ac5;
unsigned short ac6;
short b1;
short b2;
short mb;
short mc;
short md;
private:
char bmp085Read(unsigned char address);
short bmp085ReadInt(unsigned char address);
void writeRegister(short deviceAddress, byte address, byte val);
short readRegister(short deviceAddress, byte address);
};
#endif
License Information
-------------------
The hardware is released under [Creative Commons Share-alike 3.0](http://creativecommons.org/licenses/by-sa/3.0/).
All other code is open source so please feel free to do anything you want with it; you buy me a beer if you use this and we meet someday ([Beerware license](http://en.wikipedia.org/wiki/Beerware)).
SparkFun BMP180_Breakout Arduino Library
========================================
![BMP180 Breakout](https://dlnmh9ip6v2uc.cloudfront.net/images/products/1/1/8/2/4/11824-01.jpg)
[*SEN-11824*](https://www.sparkfun.com/products/11824)
This archive contains an Arduino library and example sketch showing how to use this sensor. The library must be installed onto your computer in order for the example code to work correctly.
Repository Contents
-------------------
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
* **/src** - Source files for the library (.cpp, .h).
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
* **library.properties** - General library properties for the Arduino package manager.
Documentation
--------------
* **[*Installing an Arduino Library* Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
* **[Product Repository](https://github.com/sparkfun/BMP180_Breakout)** - Main repository (including hardware files) for the BMP180 Breakout.
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup)** - Basic hookup guide for the BMP180 Breakout.
Products that use this Library
---------------------------------
* [SEN-11824](https://www.sparkfun.com/products/11824) - BMP180 Barometric Pressure Sensor Breakout
Version History
---------------
* [V_1.1.2](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/tree/V_1.1.2) - Small patch on integers, cleaning up library files.
* [V_1.1.1](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/tree/V_1.1.1) - Updated library.properties file
* [V_1.1.0](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/tree/V_1.1.0) - Updated to new library structure
* V_1.0.0 - Untracked version
License Information
-------------------
This product is _**open source**_!
The **code** is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license.
Distributed as-is; no warranty is given.
\- Your friends at SparkFun.
#######################################
# Syntax Coloring Map for SFE_BMP180
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
SFE_BMP180 KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
startTemperature KEYWORD2
getTemperature KEYWORD2
startPressure KEYWORD2
getPressure KEYWORD2
sealevel KEYWORD2
altitude KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
BMP180_ADDR LITERAL1
\ No newline at end of file
name=Sparkfun BMP180
version=1.1.2
author=SparkFun Electronics
maintainer=SparkFun Electronics
sentence=Sparkfun examples for the Bosch BMP180 barometric pressure sensor
paragraph=Example code for the Sparkfun Bosch BMP180 barometric pressure sensor breakout board.
category=Signal Input/Output
url=https://github.com/sparkfun/BMP180_Breakout
architectures=*
#include "HIH61XX.h"
HIH61XX::HIH61XX(uint8_t address, uint8_t powerPin)
: a(address), p(powerPin), f(0), h(0), t(0)
{
if(p < 255) {
digitalWrite(p, LOW);
pinMode(p, OUTPUT);
}
}
uint8_t HIH61XX::start()
{
if(p < 255) {
digitalWrite(p, HIGH);
}
f |= RunningFlag;
return setError(0);
}
uint8_t HIH61XX::stop()
{
if(p < 255) {
digitalWrite(p, LOW);
}
f &= ~RunningFlag;
return setError(0);
}
uint8_t HIH61XX::update()
{
if(!isRunning()) {
return setError(NotRunningError);
}
uint8_t x, y, s;
Wire.beginTransmission(a);
int azer = Wire.endTransmission();
if(azer == 0) {
while(true) {
delay(10);
Wire.requestFrom(a, (uint8_t) 4);
if(Wire.available()) {
x = Wire.read();
y = Wire.read();
s = x >> 6;
switch(s) {
case 0:
h = (((uint16_t) (x & 0x3f)) << 8) | y;
x = Wire.read();
y = Wire.read();
t = ((((uint16_t) x) << 8) | y) >> 2;
Wire.endTransmission();
return setError(0);
case 1:
Wire.endTransmission();
break;
case 2:
Wire.endTransmission();
return setError(CommandModeError);
}
}
else {
return setError(CommunicationError);
}
}
}
else {
Serial.print("...");
Serial.println(azer);
return setError(ConnectionError);
}
}
uint8_t HIH61XX::commandRequest(Stream& stream)
{
if(stream.available()) {
return commandProcess(stream, stream.read());
}
return commandReply(stream, 255);
}
uint8_t HIH61XX::commandProcess(Stream& stream, uint8_t command)
{
switch(command) {
// get humidity
case 'h':
return commandReply(stream, 0, humidity());
// get temperature
case 't':
return commandReply(stream, 0, temperature());
// get i2c address
case 'a':
return commandReply(stream, 0, address());
// get power pin
case 'p':
return commandReply(stream, 0, powerPin());
// update
case 'u':
return commandReply(stream, update());
// start
case '1':
return commandReply(stream, start());
// stop
case '0':
return commandReply(stream, stop());
}
return commandReply(stream, 254);
}
#ifndef HONEYWELL_HIH61XX_H
#define HONEYWELL_HIH61XX_H
// author: Tomas Van Verrewegen <tomasvanverrewegen@telenet.be>
// version: 0.2
#include <Arduino.h>
#include <Wire.h>
class HIH61XX
{
public:
enum Error
{
NoError = 0,
ConnectionError = 1,
CommunicationError = 2,
NotRunningError = 3,
CommandModeError = 4,
ErrorMask = 15
};
enum Flag
{
RunningFlag = 128,
CommandModeFlag = 64,
FlagsMask = ~ErrorMask
};
HIH61XX(uint8_t address, uint8_t powerPin = 255);
virtual ~HIH61XX() { }
uint8_t address() const { return a; }
uint8_t powerPin() const { return p; }
uint8_t error() const { return f & ErrorMask; }
bool isRunning() const { return f & RunningFlag; }
uint8_t flags() const { return f & FlagsMask; }
//bool isRunning() const { return f & RunningFlag; }
// return humidity / temperature
float humidity() const { return rawToHumidity(h); }
float temperature() const { return rawToTemperature(t); }
uint16_t humidity_Raw() const { return h; }
uint16_t temperature_Raw() const { return t; }
// start /stop the device
virtual uint8_t start();
virtual uint8_t stop();
// update humidity / temperature
uint8_t update();
// convert humidity / temperature
static float rawToHumidity(uint16_t raw) { return (float(raw) / 16382) * 100; }
static float rawToTemperature(uint16_t raw) { return (float(raw) / 16382) * 165 - 40; }
// use a stream to control the sensor
uint8_t commandRequest(Stream& stream);
protected:
uint8_t setError(uint8_t error) { f = (f & ~ErrorMask) | error; return error; }
virtual uint8_t commandProcess(Stream& stream, uint8_t command);
uint8_t commandReply(Stream& stream, uint8_t result) { stream.println(result); return result; }
template<typename T> uint8_t commandReply(Stream& stream, uint8_t result, const T& data) { stream.println(data); return result; }
uint8_t a;
uint8_t p;
uint8_t f;
uint16_t h;
uint16_t t;
};
#endif
#include <L3G.h>
#include <Wire.h>
#include <math.h>
// Defines ////////////////////////////////////////////////////////////////
// The Arduino two-wire interface uses a 7-bit number for the address,
// and sets the last bit correctly based on reads and writes
#define D20_SA0_HIGH_ADDRESS 0b1101011 // also applies to D20H
#define D20_SA0_LOW_ADDRESS 0b1101010 // also applies to D20H
#define L3G4200D_SA0_HIGH_ADDRESS 0b1101001
#define L3G4200D_SA0_LOW_ADDRESS 0b1101000
#define TEST_REG_ERROR -1
#define D20H_WHO_ID 0xD7
#define D20_WHO_ID 0xD4
#define L3G4200D_WHO_ID 0xD3
// Constructors ////////////////////////////////////////////////////////////////
L3G::L3G(void)
{
_device = device_auto;
io_timeout = 0; // 0 = no timeout
did_timeout = false;
}
// Public Methods //////////////////////////////////////////////////////////////
// Did a timeout occur in read() since the last call to timeoutOccurred()?
bool L3G::timeoutOccurred()
{
bool tmp = did_timeout;
did_timeout = false;
return tmp;