Skip to content

Commit

Permalink
Add a e2p config block to e2p layout. Use temperature and brightness …
Browse files Browse the repository at this point in the history
…sensor settings for configuration of connected sensor type. Implement using the new values to avoid that the firmware hangs (waits forever) when no SHT15 is connected.
  • Loading branch information
breaker27 committed Oct 5, 2013
1 parent b663f3e commit bd3d701
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
29 changes: 28 additions & 1 deletion firmware/shc_tempsensor/e2p_layout_temperature_sensor.h
Expand Up @@ -76,5 +76,32 @@ typedef enum {
#define EEPROM_AESKEY_BIT 0
#define EEPROM_AESKEY_LENGTH_BYTES 32

// overall length: 512 bits

// ---------- TemperatureSensorConfig ----------

// EnumValue TemperatureSensorType

typedef enum {
TEMPERATURESENSORTYPE_NOSENSOR = 0,
TEMPERATURESENSORTYPE_SHT15 = 1
} TemperatureSensorTypeEnum;

#define EEPROM_TEMPERATURESENSORTYPE_BYTE 64
#define EEPROM_TEMPERATURESENSORTYPE_BIT 0
#define EEPROM_TEMPERATURESENSORTYPE_LENGTH_BITS 8

// EnumValue BrightnessSensorType

typedef enum {
BRIGHTNESSSENSORTYPE_NOSENSOR = 0,
BRIGHTNESSSENSORTYPE_PHOTOCELL = 1
} BrightnessSensorTypeEnum;

#define EEPROM_BRIGHTNESSSENSORTYPE_BYTE 65
#define EEPROM_BRIGHTNESSSENSORTYPE_BIT 0
#define EEPROM_BRIGHTNESSSENSORTYPE_LENGTH_BITS 8

// Reserved area with 3568 bits

// overall length: 4096 bits

32 changes: 25 additions & 7 deletions firmware/shc_tempsensor/shc_tempsensor.c
Expand Up @@ -26,6 +26,7 @@

#include "rfm12.h"
#include "uart.h"
#include "e2p_layout_temperature_sensor.h"

// switch on debugging by UART
//#define UART_DEBUG
Expand Down Expand Up @@ -59,6 +60,8 @@
#define PACKET_COUNTER_WRITE_CYCLE 100

uint32_t packetcounter = 0;
uint8_t temperature_sensor_type = 0;
uint8_t brightness_sensor_type = 0;

void printbytearray(uint8_t * b, uint8_t len)
{
Expand Down Expand Up @@ -107,6 +110,10 @@ int main ( void )
packetcounter = eeprom_read_dword((uint32_t*)EEPROM_POS_PACKET_COUNTER) + PACKET_COUNTER_WRITE_CYCLE;
eeprom_write_dword((uint32_t*)0, packetcounter);

// read device specific config
temperature_sensor_type = eeprom_read_byte((uint8_t*)EEPROM_TEMPERATURESENSORTYPE_BYTE);
brightness_sensor_type = eeprom_read_byte((uint8_t*)EEPROM_BRIGHTNESSSENSORTYPE_BYTE);

// read device id and write to send buffer
device_id = eeprom_read_byte((uint8_t*)EEPROM_POS_DEVICE_ID);

Expand All @@ -118,6 +125,8 @@ int main ( void )
UART_PUTS ("smarthomatic Tempsensor V1.0 (c) 2013 Uwe Freese, www.smarthomatic.org\r\n");
UART_PUTF ("Device ID: %u\r\n", device_id);
UART_PUTF ("Packet counter: %u\r\n", packetcounter);
UART_PUTF ("Temperature Sensor Type: %u\r\n", temperature_sensor_type);
UART_PUTF ("Brightness Sensor Type: %u\r\n", brightness_sensor_type);
#endif

// init AES key
Expand All @@ -128,7 +137,10 @@ int main ( void )
#endif

#ifdef TEMP_SENS
sht11_init();
if (temperature_sensor_type == TEMPERATURESENSORTYPE_SHT15)
{
sht11_init();
}
#endif

rfm12_init();
Expand Down Expand Up @@ -160,12 +172,15 @@ int main ( void )
#endif

#ifdef TEMP_SENS
sht11_start_measure();
_delay_ms(500);
while (!sht11_measure_finish());
if (temperature_sensor_type == TEMPERATURESENSORTYPE_SHT15)
{
sht11_start_measure();
_delay_ms(500);
while (!sht11_measure_finish());

temp += sht11_get_tmp();
hum += sht11_get_hum();
temp += sht11_get_tmp();
hum += sht11_get_hum();
}
#endif

avg++;
Expand Down Expand Up @@ -204,7 +219,10 @@ int main ( void )

// update brightness
#ifdef LIGHT_SENS
bufx[11] = 100 - (int)((long)vlight * 100 / 1024);
if (brightness_sensor_type == BRIGHTNESSSENSORTYPE_PHOTOCELL)
{
bufx[11] = 100 - (int)((long)vlight * 100 / 1024);
}
#endif
uint32_t crc = crc32(bufx, 12);
UART_PUTF("CRC32 is %lx (added as last 4 bytes)\r\n", crc);
Expand Down
2 changes: 1 addition & 1 deletion firmware/shc_tempsensor/shc_tempsensor.pnproj
@@ -1 +1 @@
<Project name="shc_tempsensor"><File path="Makefile"></File><File path="shc_tempsensor.c"></File><File path="rfm12_config.h"></File><File path="sht11.c"></File><File path="sht11.h"></File><File path="config.h"></File><File path="fuses.c"></File></Project>
<Project name="shc_tempsensor"><File path="Makefile"></File><File path="shc_tempsensor.c"></File><File path="rfm12_config.h"></File><File path="sht11.c"></File><File path="sht11.h"></File><File path="config.h"></File><File path="fuses.c"></File><File path="e2p_layout_temperature_sensor.h"></File></Project>
37 changes: 37 additions & 0 deletions tools/shc_e2p_editor/e2p_layout.xml
Expand Up @@ -64,6 +64,43 @@
<Bytes>32</Bytes>
</ByteArray>
</Block>
<Block>
<Name>TemperatureSensorConfig</Name>
<Description>This block contains the specific configuration data that only Temperature Sensor devices need.</Description>
<Restriction>
<RefID>DeviceType</RefID>
<Value>20</Value>
</Restriction>
<EnumValue>
<ID>TemperatureSensorType</ID>
<Description>You can choose one of the supported temperature / humidity sensors. If set to 0, no sensor is used, but the device sends out packets for testing purposes.</Description>
<Bits>8</Bits>
<Element>
<Value>0</Value>
<Name>NoSensor</Name>
</Element>
<Element>
<Value>1</Value>
<Name>SHT15</Name>
</Element>
</EnumValue>
<EnumValue>
<ID>BrightnessSensorType</ID>
<Description>You can choose one of the supported light sensors. If set to 0, no sensor is used, but the device sends out packets for testing purposes.</Description>
<Bits>8</Bits>
<Element>
<Value>0</Value>
<Name>NoSensor</Name>
</Element>
<Element>
<Value>1</Value>
<Name>Photocell</Name>
</Element>
</EnumValue>
<Reserved>
<Bits>3568</Bits>
</Reserved>
</Block>
<Block>
<Name>DimmerConfig</Name>
<Description>This block contains the specific configuration data that only Dimmer devices need.</Description>
Expand Down

0 comments on commit bd3d701

Please sign in to comment.