Compare commits

...

2 Commits

Author SHA1 Message Date
Sebastian H. Gabrielli
d964ebea37 Handle read single fan speed 2024-04-23 15:45:41 +02:00
Sebastian H. Gabrielli
bf3753a012 I2C bulk fan read works 2024-04-23 15:31:32 +02:00
6 changed files with 72 additions and 39 deletions

View File

@ -38,7 +38,7 @@ void parse_command(uint8_t command[], uint8_t command_len) {
context.command = WRITE_CONFIG;
break;
case 0x22: // Clear stored fan speed data
context.command = CLEAR_BULK_FAN_SPEED;
context.command = READ_BULK_FAN_SPEED;
break;
default: // Unrecognized command
context.command = UNKNOWN_COMMAND;
@ -133,26 +133,34 @@ void parse_command(uint8_t command[], uint8_t command_len) {
uint8_t route_command(int pos) {
switch (context.command) {
WRITE_CONFIG:
case WRITE_CONFIG:
return WRITE_CONFIG;
break;
READ_CONFIG:
case READ_CONFIG:
return READ_CONFIG;
break;
READ_VOLTAGE:
case READ_VOLTAGE:
return READ_VOLTAGE;
break;
READ_TERMPERATURE:
case READ_TERMPERATURE:
return READ_TERMPERATURE;
case READ_FAN_SPEED:
if (context.fan == FAN1) {
return fan1_history[0];
} else if (context.fan == FAN2) {
return fan2_history[0];
} else {
return 0;
}
break;
READ_FAN_SPEED:
return READ_FAN_SPEED;
case READ_BULK_FAN_SPEED:
if (context.fan == FAN1) {
return fan1_history[pos];
} else if (context.fan == FAN2) {
return fan2_history[pos];
} else {
return 0;
}
break;
CLEAR_BULK_FAN_SPEED:
return CLEAR_BULK_FAN_SPEED;
break;
UNKNOWN_COMMAND:
case UNKNOWN_COMMAND:
default:
return 0xFF;
break;
}
}

View File

@ -12,6 +12,7 @@
extern "C" {
#endif
#include "eeprom.h"
#include <avr/io.h>
#include <stdint.h>
#include <string.h>
@ -45,8 +46,8 @@ typedef enum {
// Enum of all valid fans
// TODO: Consider moving into it's own fan page
typedef enum {
FAN1, // The first fan
FAN2, // The second fan
FAN1 = 1, // The first fan
FAN2 = 2, // The second fan
FAN_NONE // No fan
} fans_t;
@ -59,6 +60,10 @@ typedef struct {
// TODO: Add config value field for writing
} command_context_t;
// Fan history variables
extern volatile uint16_t fan1_history[512];
extern volatile uint16_t fan2_history[512];
// Parses the input string and outputs one of the valid commands
void parse_command(uint8_t *command, uint8_t command_len);

View File

@ -1,15 +1,15 @@
#include "eeprom.h"
// The start address for the controller data
uint8_t EEMEM start_address_controller = 0x00;
uint16_t EEMEM start_address_controller = 0x1400;
// Where the writing of the fans points start
uint8_t EEMEM start_address_fan1 = 0x30;
uint8_t EEMEM start_address_fan2 = 0x60;
uint16_t EEMEM start_address_fan1 = 0x1400 + 0x30;
uint16_t EEMEM start_address_fan2 = 0x1400 + 0x60;
// The placement for the next datapoint form the fans.
uint8_t EEMEM current_address_fan1 = 0x30;
uint8_t EEMEM current_address_fan2 = 0x60;
uint16_t EEMEM current_address_fan1 = 0x1400 + 0x30;
uint16_t EEMEM current_address_fan2 = 0x1400 + 0x60;
// Checks if the EEPROM memory is ready to be written in.
void check_eeprom_is_ready(){
@ -58,7 +58,7 @@ int write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num){
check_eeprom_is_ready();
if (fan_num == 1){
eeprom_update_byte(current_address_fan1, byte);
eeprom_write_byte(0x30, byte);
current_address_fan1++;
return 1;
} else if (fan_num == 2){
@ -97,3 +97,17 @@ uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array){
}
return sizeof(array);
}
// Reads all the datapoints to the choosen data.
// it writes the data points in the USART stream.
uint8_t read_single_data_point_speed_info(uint8_t fan_num, uint8_t pos){
uint8_t byte = 0;
if (fan_num == 1){
check_eeprom_is_ready();
return eeprom_read_byte(0x30 + pos);
} else if (fan_num == 2){
check_eeprom_is_ready();
return eeprom_read_byte(start_address_fan2 + pos);
}
}

View File

@ -36,11 +36,13 @@ void write_struct_from_EEPROM(config_t write_struct);
config_t read_struct_from_EEPROM();
// Writes a datapoint in EEPROM
int write_data_point_from_EEPROM(uint8_t byte, uint8_t fan_num);
int write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num);
// Reads all the dataPoints form EEPROM
uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array);
uint8_t read_single_data_point_speed_info(uint8_t fan_num, uint8_t pos);
#ifdef __cplusplus
}

View File

@ -4,24 +4,28 @@
*
* Created on March 6, 2024, 12:34 PM
*/
#include <stdbool.h>
#include "uart.h"
#include "voltage.h"
#define RTC_PERIOD (511)
#define DELAY_TIME 1000
#include "eeprom.h"
#include <avr/interrupt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define F_CPU 4E6
#include "command-handler.h"
#include "i2c.h"
#include "themistor-temp.h"
#include "uart.h"
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
#include "themistor-temp.h"
#include <util/delay.h>
// Fan history variables
volatile uint16_t fan1_history[512] = {1, 2, 3, 4};
volatile uint16_t fan2_history[512] = {2, 3, 4, 5};
int main() {
init_uart((uint16_t)9600);
@ -33,8 +37,6 @@ int main() {
sei();
while (1) {
// uint16_t adcVal = ADC0_read();
// printf("The values: \n%u , %u\n",VREF_REFSEL_VDD_gc , adcVal);
;
}
}

View File

@ -27,6 +27,8 @@
<itemPath>uart.c</itemPath>
<itemPath>eeprom.c</itemPath>
<itemPath>voltage.c</itemPath>
<itemPath>i2c.c</itemPath>
<itemPath>command-handler.c</itemPath>
</logicalFolder>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>