Added new telstick windows drivers
Former-commit-id: 797b455c0a2b358e691a198017acea4eb5c02f73
This commit is contained in:
parent
36d0826a33
commit
af01fb9ae9
22 changed files with 2886 additions and 13 deletions
80
arduino/PowerTransmitter/BH1750FVI.cpp
Executable file
80
arduino/PowerTransmitter/BH1750FVI.cpp
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
#include "BH1750FVI.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
BH1750FVI::BH1750FVI(){
|
||||
|
||||
}
|
||||
|
||||
void BH1750FVI::begin(void){
|
||||
Wire.begin();
|
||||
I2CWriteTo(Power_On ); //Turn it On
|
||||
pinMode(AddrPin,OUTPUT);
|
||||
digitalWrite(AddrPin,HIGH);
|
||||
|
||||
}
|
||||
void BH1750FVI::Sleep(void){
|
||||
I2CWriteTo(Power_Down ); //Turn it off , Reset operator won't work in this mode
|
||||
}
|
||||
void BH1750FVI::Reset(void){
|
||||
I2CWriteTo(Power_On ); //Turn it on again
|
||||
I2CWriteTo(reset ); //Reset
|
||||
|
||||
}
|
||||
void BH1750FVI::SetAddress(uint8_t add){
|
||||
switch (add){
|
||||
case Device_Address_L:
|
||||
address_value=Device_Address_L;
|
||||
digitalWrite(AddrPin,LOW);
|
||||
state=false;
|
||||
break;
|
||||
case Device_Address_H:
|
||||
address_value=Device_Address_H;
|
||||
digitalWrite(AddrPin,HIGH);
|
||||
state=true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
void BH1750FVI::SetMode(uint8_t MODE){
|
||||
switch(MODE){
|
||||
case Continuous_H_resolution_Mode:
|
||||
break;
|
||||
case Continuous_H_resolution_Mode2:
|
||||
break;
|
||||
case Continuous_L_resolution_Mode:
|
||||
break;
|
||||
case OneTime_H_resolution_Mode:
|
||||
break;
|
||||
case OneTime_H_resolution_Mode2:
|
||||
break;
|
||||
case OneTime_L_resolution_Mode:
|
||||
break;
|
||||
}
|
||||
delay(10);
|
||||
I2CWriteTo(MODE);
|
||||
}
|
||||
|
||||
uint16_t BH1750FVI::GetLightIntensity(void){
|
||||
uint16_t Intensity_value;
|
||||
if(state ==true){
|
||||
Wire.beginTransmission(Device_Address_H);
|
||||
Wire.requestFrom(Device_Address_H, 2);
|
||||
}
|
||||
if(state ==false){
|
||||
Wire.beginTransmission(Device_Address_L);
|
||||
Wire.requestFrom(Device_Address_L, 2);
|
||||
}
|
||||
Intensity_value = Wire.read();
|
||||
Intensity_value <<= 8;
|
||||
Intensity_value |= Wire.read();
|
||||
Wire.endTransmission();
|
||||
Intensity_value=Intensity_value/1.2;
|
||||
return Intensity_value;
|
||||
|
||||
}
|
||||
|
||||
void BH1750FVI::I2CWriteTo(uint8_t DataToSend){
|
||||
Wire.beginTransmission(address_value);
|
||||
Wire.write(DataToSend);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
68
arduino/PowerTransmitter/BH1750FVI.h
Executable file
68
arduino/PowerTransmitter/BH1750FVI.h
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
|
||||
/* This library for Digital Light sensor BH1750FVI
|
||||
|
||||
use I2C Communication protocal , SDA,SCL Are required
|
||||
|
||||
to interface with this sensor
|
||||
|
||||
pin configuration :
|
||||
|
||||
VCC >>> 3.3V
|
||||
SDA >>> A4
|
||||
SCL >>> A5
|
||||
ADDR >> A3 "Optional"
|
||||
GND >>> gnd
|
||||
|
||||
written By : Mohannad Rawashdeh
|
||||
www.genotronex.com
|
||||
*/
|
||||
|
||||
#ifndef BH1750FVI_h
|
||||
#define BH1750FVI_h
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
#define Device_Address_L 0x23 // Device address when address pin LOW
|
||||
#define Device_Address_H 0x5C // Device address when address pin LOW
|
||||
//all command here taken from Data sheet OPECODE Table page 5
|
||||
#define Power_Down 0x00
|
||||
|
||||
#define Power_On 0x01
|
||||
|
||||
#define reset 0x07
|
||||
|
||||
#define Continuous_H_resolution_Mode 0x10
|
||||
|
||||
#define Continuous_H_resolution_Mode2 0x11
|
||||
|
||||
#define Continuous_L_resolution_Mode 0x13
|
||||
|
||||
#define OneTime_H_resolution_Mode 0x20
|
||||
|
||||
#define OneTime_H_resolution_Mode2 0x21
|
||||
|
||||
#define OneTime_L_resolution_Mode 0x23//As well as address value
|
||||
|
||||
#define AddrPin 17 // Address pin enable
|
||||
class BH1750FVI {
|
||||
public:
|
||||
BH1750FVI();
|
||||
void begin(void);
|
||||
void Sleep(void);
|
||||
void SetMode(uint8_t MODE);
|
||||
void Reset(void);
|
||||
void SetAddress(uint8_t add);
|
||||
uint16_t GetLightIntensity(void);
|
||||
|
||||
private:
|
||||
void I2CWriteTo(uint8_t DataToSend);
|
||||
byte address_value;
|
||||
boolean state;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
294
arduino/PowerTransmitter/PowerTransmitter.ino
Executable file
294
arduino/PowerTransmitter/PowerTransmitter.ino
Executable file
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* Protocol: Oregon V2.1
|
||||
* Emulating sensor: THGR2228N
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "BH1750FVI.h"
|
||||
|
||||
BH1750FVI LightSensor;
|
||||
const byte TX_PIN = 10;
|
||||
const byte LED_PIN = 13;
|
||||
const unsigned long TIME = 512;
|
||||
const unsigned long TWOTIME = TIME*2;
|
||||
#define SEND_HIGH() digitalWrite(TX_PIN, HIGH)
|
||||
#define SEND_LOW() digitalWrite(TX_PIN, LOW)
|
||||
byte OregonMessageBuffer[9];
|
||||
unsigned long previousTime = 0;
|
||||
unsigned long currentTime = millis();
|
||||
int impulseCount = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
pinMode(TX_PIN, OUTPUT);
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
SEND_LOW();
|
||||
byte ID[] = { 0x1A,0x2D }; //temperature/humidity sensor (THGR2228N)
|
||||
setType(OregonMessageBuffer, ID);
|
||||
setChannel(OregonMessageBuffer, 0x20);
|
||||
|
||||
LightSensor.begin();
|
||||
LightSensor.SetAddress(Device_Address_H);
|
||||
LightSensor.SetMode(Continuous_H_resolution_Mode);
|
||||
Serial.print("Started");
|
||||
}
|
||||
|
||||
|
||||
boolean light = false;
|
||||
void loop()
|
||||
{
|
||||
currentTime = millis();
|
||||
uint16_t lux = LightSensor.GetLightIntensity();
|
||||
if(lux > 100 && !light){
|
||||
light = true;
|
||||
impulseCount++;
|
||||
}else if(lux < 100){
|
||||
light = false;
|
||||
}
|
||||
if(currentTime - previousTime > 5000) {
|
||||
previousTime = currentTime;
|
||||
Serial.print("total impulses = ");
|
||||
Serial.println(impulseCount);
|
||||
send433(impulseCount,0,0xBA);
|
||||
impulseCount = 0;
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void send433(float temperature, byte humidity, byte Identitet)
|
||||
{
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
setId(OregonMessageBuffer, Identitet); //set id of the sensor, BB=187
|
||||
setBatteryLevel(OregonMessageBuffer, 1); // 0 : low, 1 : high
|
||||
setTemperature(OregonMessageBuffer, temperature); //org setTemperature(OregonMessageBuffer, 55.5);
|
||||
setHumidity(OregonMessageBuffer, humidity);
|
||||
calculateAndSetChecksum(OregonMessageBuffer);
|
||||
|
||||
// Show the Oregon Message
|
||||
for (byte i = 0; i < sizeof(OregonMessageBuffer); ++i) {
|
||||
Serial.print(OregonMessageBuffer[i] >> 4, HEX);
|
||||
Serial.print(OregonMessageBuffer[i] & 0x0F, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Send the Message over RF
|
||||
sendOregon(OregonMessageBuffer, sizeof(OregonMessageBuffer));
|
||||
// Send a "pause"
|
||||
SEND_LOW();
|
||||
delayMicroseconds(TWOTIME*8);
|
||||
// Send a copie of the first message. The v2.1 protocol send the message two time
|
||||
sendOregon(OregonMessageBuffer, sizeof(OregonMessageBuffer));
|
||||
SEND_LOW();
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
|
||||
inline void setId(byte *data, byte ID)
|
||||
{
|
||||
data[3] = ID;
|
||||
}
|
||||
|
||||
void setBatteryLevel(byte *data, byte level)
|
||||
{
|
||||
if(!level) data[4] = 0x0C;
|
||||
else data[4] = 0x00;
|
||||
}
|
||||
|
||||
void setTemperature(byte *data, float temp)
|
||||
{
|
||||
// Set temperature sign
|
||||
if(temp < 0)
|
||||
{
|
||||
data[6] = 0x08;
|
||||
temp *= -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
data[6] = 0x00;
|
||||
}
|
||||
|
||||
// Determine decimal and float part
|
||||
int tempInt = (int)temp;
|
||||
int td = (int)(tempInt / 10);
|
||||
int tf = (int)round((float)((float)tempInt/10 - (float)td) * 10);
|
||||
|
||||
int tempFloat = (int)round((float)(temp - (float)tempInt) * 10);
|
||||
|
||||
// Set temperature decimal part
|
||||
data[5] = (td << 4);
|
||||
data[5] |= tf;
|
||||
|
||||
// Set temperature float part
|
||||
data[4] |= (tempFloat << 4);
|
||||
}
|
||||
|
||||
void setHumidity(byte* data, byte hum)
|
||||
{
|
||||
data[7] = (hum/10);
|
||||
data[6] |= (hum - data[7]*10) << 4;
|
||||
}
|
||||
|
||||
void calculateAndSetChecksum(byte* data)
|
||||
{
|
||||
int sum = 0;
|
||||
for(byte i = 0; i<8;i++)
|
||||
{
|
||||
sum += (data[i]&0xF0) >> 4;
|
||||
sum += (data[i]&0xF);
|
||||
}
|
||||
data[8] = ((sum - 0xa) & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//*********************************************************************************************************
|
||||
|
||||
|
||||
/**
|
||||
* \brief Send logical "0" over RF
|
||||
* \details azero bit be represented by an off-to-on transition
|
||||
* \ of the RF signal at the middle of a clock period.
|
||||
* \ Remenber, the Oregon v2.1 protocol add an inverted bit first
|
||||
*/
|
||||
inline void sendZero(void)
|
||||
{
|
||||
SEND_HIGH();
|
||||
delayMicroseconds(TIME);
|
||||
SEND_LOW();
|
||||
delayMicroseconds(TWOTIME);
|
||||
SEND_HIGH();
|
||||
delayMicroseconds(TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send logical "1" over RF
|
||||
* \details a one bit be represented by an on-to-off transition
|
||||
* \ of the RF signal at the middle of a clock period.
|
||||
* \ Remenber, the Oregon v2.1 protocol add an inverted bit first
|
||||
*/
|
||||
inline void sendOne(void)
|
||||
{
|
||||
SEND_LOW();
|
||||
delayMicroseconds(TIME);
|
||||
SEND_HIGH();
|
||||
delayMicroseconds(TWOTIME);
|
||||
SEND_LOW();
|
||||
delayMicroseconds(TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send a bits quarter (4 bits = MSB from 8 bits value) over RF
|
||||
* \param data Data to send
|
||||
*/
|
||||
inline void sendQuarterMSB(const byte data)
|
||||
{
|
||||
(bitRead(data, 4)) ? sendOne() : sendZero();
|
||||
(bitRead(data, 5)) ? sendOne() : sendZero();
|
||||
(bitRead(data, 6)) ? sendOne() : sendZero();
|
||||
(bitRead(data, 7)) ? sendOne() : sendZero();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send a bits quarter (4 bits = LSB from 8 bits value) over RF
|
||||
* \param data Data to send
|
||||
*/
|
||||
inline void sendQuarterLSB(const byte data)
|
||||
{
|
||||
(bitRead(data, 0)) ? sendOne() : sendZero();
|
||||
(bitRead(data, 1)) ? sendOne() : sendZero();
|
||||
(bitRead(data, 2)) ? sendOne() : sendZero();
|
||||
(bitRead(data, 3)) ? sendOne() : sendZero();
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* \brief Send a buffer over RF
|
||||
* \param data Data to send
|
||||
* \param size size of data to send
|
||||
*/
|
||||
void sendData(byte *data, byte size)
|
||||
{
|
||||
for(byte i = 0; i < size; ++i)
|
||||
{
|
||||
sendQuarterLSB(data[i]);
|
||||
sendQuarterMSB(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send an Oregon message
|
||||
* \param data The Oregon message
|
||||
*/
|
||||
void sendOregon(byte *data, byte size)
|
||||
{
|
||||
sendPreamble();
|
||||
//sendSync();
|
||||
sendData(data, size);
|
||||
sendPostamble();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send preamble
|
||||
* \details The preamble consists of 16 "1" bits
|
||||
*/
|
||||
inline void sendPreamble(void)
|
||||
{
|
||||
byte PREAMBLE[]={
|
||||
0xFF,0xFF };
|
||||
sendData(PREAMBLE, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send postamble
|
||||
* \details The postamble consists of 8 "0" bits
|
||||
*/
|
||||
inline void sendPostamble(void)
|
||||
{
|
||||
byte POSTAMBLE[]={
|
||||
0x00 };
|
||||
sendData(POSTAMBLE, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Send sync nibble
|
||||
* \details The sync is 0xA. It is not use in this version since the sync nibble
|
||||
* \ is include in the Oregon message to send.
|
||||
*/
|
||||
inline void sendSync(void)
|
||||
{
|
||||
sendQuarterLSB(0xA);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* \brief Set the sensor type
|
||||
* \param data Oregon message
|
||||
* \param type Sensor type
|
||||
*/
|
||||
inline void setType(byte *data, byte* type)
|
||||
{
|
||||
data[0] = type[0];
|
||||
data[1] = type[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set the sensor channel
|
||||
* \param data Oregon message
|
||||
* \param channel Sensor channel (0x10, 0x20, 0x30)
|
||||
*/
|
||||
inline void setChannel(byte *data, byte channel)
|
||||
{
|
||||
data[2] = channel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue