diff --git a/include/ir_feet_conf.h b/include/ir_feet_conf.h index 05893eb9857e8b3fa95e2e556c9332dd31bb992c..19987ad9450903473e55a34c0bbd61e83e3f665b 100644 --- a/include/ir_feet_conf.h +++ b/include/ir_feet_conf.h @@ -11,6 +11,7 @@ /* threshold registers */ #define EEPROM_THRESHOLDS_BASE_ADDRESS1 ((unsigned short int)0x0006) #define EEPROM_THRESHOLDS_BASE_ADDRESS2 ((unsigned short int)0x0011) +#define RAM_THRESHOLDS_BASE_ADDRESS ((unsigned short int)0x0038) #define EEPROM_NUM_VAR 32 diff --git a/include/thresholds_registers.h b/include/thresholds_registers.h index f5b042d0e59ce3446988bc5c07bd8e5d7e64f133..91dcc15a3408ca7ef4f0fdf9cc572da0fa8d003a 100644 --- a/include/thresholds_registers.h +++ b/include/thresholds_registers.h @@ -11,10 +11,16 @@ #define EEPROM_THRESHOLDS_BASE_ADDRESS2 ((unsigned short int)0x0000) #endif +#ifndef RAM_THRESHOLDS_BASE_ADDRESS + #define RAM_THRESHOLDS_BASE_ADDRESS ((unsigned short int)0x0000) +#endif + #define EEPROM_THRESHOLDS_LENGTH1 10 #define EEPROM_THRESHOLDS_LENGTH2 10 +#define RAM_THRESHOLDS_LENGTH 2 + #define DOWN_LEFT_MIDDLE_THRES EEPROM_THRESHOLDS_BASE_ADDRESS1 #define DOWN_LEFT_REAR_THRES (EEPROM_THRESHOLDS_BASE_ADDRESS1+2) #define DOWN_ANALOG_THRES (EEPROM_THRESHOLDS_BASE_ADDRESS1+4) @@ -26,6 +32,24 @@ #define FRONT_RIGHT_THRES (EEPROM_THRESHOLDS_BASE_ADDRESS2+6) #define FRONT_ANALOG_THRES (EEPROM_THRESHOLDS_BASE_ADDRESS2+8) +#define THRESHOLDS RAM_THRESHOLDS_BASE_ADDRESS + // bit 0 -> DOWN_LEFT_MIDDLE_THRES + // bit 1 -> DOWN_LEFT_REAR_THRES + // bit 2 -> DOWN_ANALOG_THRES + // bit 3 -> DOWN_LEFT_FRONT_THRES + // bit 4 -> DOWN_RIGHT_REAR_THRES + // bit 5 -> DOWN_RIGHT_MIDDLE_THRES + // bit 6 -> DOWN_RIGHT_FRONT_THRES + // bit 7 -> FRONT_LEFT_THRES + // bit 8 -> FRONT_RIGHT_THRES + // bit 9 -> FRONT_ANALOG_THRES + // bit 10 -> + // bit 11 -> + // bit 12 -> + // bit 13 -> + // bit 14 -> + // bit 15 -> + #ifndef DEFAULT_DOWN_LEFT_MIDDLE_THRES #define DEFAULT_DOWN_LEFT_MIDDLE_THRES 0x0000 #endif @@ -58,5 +82,16 @@ #define DEFAULT_FRONT_ANALOG_THRES 0x0000 #endif +#define DOWN_LEFT_MIDDLE_BIT 0x01 +#define DOWN_LEFT_REAR_BIT 0x02 +#define DOWN_ANALOG_BIT 0x04 +#define DOWN_LEFT_FRONT_BIT 0x08 +#define DOWN_RIGHT_REAR_BIT 0x10 +#define DOWN_RIGHT_MIDDLE_BIT 0x20 +#define DOWN_RIGHT_FRONT_BIT 0x40 +#define FRONT_LEFT_BIT 0x80 +#define FRONT_RIGHT_BIT 0x01 +#define FRONT_ANALOG_BIT 0x02 + #endif diff --git a/src/thresholds.c b/src/thresholds.c index de27f8db1113da78cf78c23dc3cc063d4c7bd69b..3e4c662e91b53cd12ed09c0247f4db859ffe5df8 100755 --- a/src/thresholds.c +++ b/src/thresholds.c @@ -193,6 +193,8 @@ uint8_t thres_init(TMemory *memory) return 0x00; if(!mem_module_add_eeprom_segment(&thres_mem_module,EEPROM_THRESHOLDS_BASE_ADDRESS2,EEPROM_THRESHOLDS_LENGTH2)) return 0x00; + if(!mem_module_add_ram_segment(&thres_mem_module,RAM_THRESHOLDS_BASE_ADDRESS,RAM_THRESHOLDS_LENGTH)) + return 0x00; if(!mem_add_module(memory,&thres_mem_module)) return 0x00; @@ -205,52 +207,112 @@ void thres_check(void) voltage=adc_get_voltage(DOWN_LEFT_MIDDLE_CH); if(voltage>thresholds[0]) + { gpio_set_led(DOWN_LEFT_MIDDLE); + ram_data[THRESHOLDS]|=DOWN_LEFT_MIDDLE_BIT; + } else + { gpio_clear_led(DOWN_LEFT_MIDDLE); + ram_data[THRESHOLDS]&=(~DOWN_LEFT_MIDDLE_BIT); + } voltage=adc_get_voltage(DOWN_LEFT_REAR_CH); if(voltage>thresholds[1]) + { gpio_set_led(DOWN_LEFT_REAR); + ram_data[THRESHOLDS]|=DOWN_LEFT_REAR_BIT; + } else + { gpio_clear_led(DOWN_LEFT_REAR); + ram_data[THRESHOLDS]&=(~DOWN_LEFT_REAR_BIT); + } voltage=adc_get_voltage(DOWN_ANALOG_CH); if(voltage>thresholds[2]) + { gpio_set_led(DOWN_ANALOG); + ram_data[THRESHOLDS]|=DOWN_ANALOG_BIT; + } else + { gpio_clear_led(DOWN_ANALOG); + ram_data[THRESHOLDS]&=(~DOWN_ANALOG_BIT); + } voltage=adc_get_voltage(DOWN_LEFT_FRONT_CH); if(voltage>thresholds[3]) + { gpio_set_led(DOWN_LEFT_FRONT); + ram_data[THRESHOLDS]|=DOWN_LEFT_FRONT_BIT; + } else + { gpio_clear_led(DOWN_LEFT_FRONT); + ram_data[THRESHOLDS]&=(~DOWN_LEFT_FRONT_BIT); + } voltage=adc_get_voltage(DOWN_RIGHT_REAR_CH); if(voltage>thresholds[4]) + { gpio_set_led(DOWN_RIGHT_REAR); + ram_data[THRESHOLDS]|=DOWN_RIGHT_REAR_BIT; + } else + { gpio_clear_led(DOWN_RIGHT_REAR); + ram_data[THRESHOLDS]&=(~DOWN_RIGHT_REAR_BIT); + } voltage=adc_get_voltage(DOWN_RIGHT_MIDDLE_CH); if(voltage>thresholds[5]) + { gpio_set_led(DOWN_RIGHT_MIDDLE); + ram_data[THRESHOLDS]|=DOWN_RIGHT_MIDDLE_BIT; + } else + { gpio_clear_led(DOWN_RIGHT_MIDDLE); + ram_data[THRESHOLDS]&=(~DOWN_RIGHT_MIDDLE_BIT); + } voltage=adc_get_voltage(DOWN_RIGHT_FRONT_CH); if(voltage>thresholds[6]) + { gpio_set_led(DOWN_RIGHT_FRONT); + ram_data[THRESHOLDS]|=DOWN_RIGHT_FRONT_BIT; + } else + { gpio_clear_led(DOWN_RIGHT_FRONT); + ram_data[THRESHOLDS]&=(~DOWN_RIGHT_FRONT_BIT); + } voltage=adc_get_voltage(FRONT_LEFT_CH); if(voltage>thresholds[7]) + { gpio_set_led(FRONT_LEFT); + ram_data[THRESHOLDS]|=FRONT_LEFT_BIT; + } else + { gpio_clear_led(FRONT_LEFT); + ram_data[THRESHOLDS]&=(~FRONT_LEFT_BIT); + } voltage=adc_get_voltage(FRONT_RIGHT_CH); if(voltage>thresholds[8]) + { gpio_set_led(FRONT_RIGHT); + ram_data[THRESHOLDS+1]|=FRONT_RIGHT_BIT; + } else + { gpio_clear_led(FRONT_RIGHT); + ram_data[THRESHOLDS+1]&=(~FRONT_RIGHT_BIT); + } voltage=adc_get_voltage(FRONT_ANALOG_CH); if(voltage>thresholds[9]) + { gpio_set_led(FRONT_ANALOG); + ram_data[THRESHOLDS+1]|=FRONT_ANALOG_BIT; + } else + { gpio_clear_led(FRONT_ANALOG); + ram_data[THRESHOLDS+1]&=(~FRONT_ANALOG_BIT); + } }