Merge I2C command handler into main #18
@ -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;
|
||||
@ -132,27 +132,29 @@ void parse_command(uint8_t command[], uint8_t command_len) {
|
||||
}
|
||||
|
||||
uint8_t route_command(int pos) {
|
||||
switch (context.command) {
|
||||
WRITE_CONFIG:
|
||||
return WRITE_CONFIG;
|
||||
break;
|
||||
READ_CONFIG:
|
||||
return READ_CONFIG;
|
||||
break;
|
||||
READ_VOLTAGE:
|
||||
return READ_VOLTAGE;
|
||||
break;
|
||||
READ_TERMPERATURE:
|
||||
return READ_TERMPERATURE;
|
||||
break;
|
||||
READ_FAN_SPEED:
|
||||
return READ_FAN_SPEED;
|
||||
break;
|
||||
CLEAR_BULK_FAN_SPEED:
|
||||
return CLEAR_BULK_FAN_SPEED;
|
||||
break;
|
||||
UNKNOWN_COMMAND:
|
||||
return 0xFF;
|
||||
break;
|
||||
switch (context.command) {
|
||||
case WRITE_CONFIG:
|
||||
return WRITE_CONFIG;
|
||||
case READ_CONFIG:
|
||||
return READ_CONFIG;
|
||||
case READ_VOLTAGE:
|
||||
return READ_VOLTAGE;
|
||||
case READ_TERMPERATURE:
|
||||
return READ_TERMPERATURE;
|
||||
case 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;
|
||||
}
|
||||
}
|
||||
case UNKNOWN_COMMAND:
|
||||
default:
|
||||
return 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
sebgab marked this conversation as resolved
Outdated
|
||||
current_address_fan1++;
|
||||
|
sebgab marked this conversation as resolved
Outdated
Athamantis
commented
either fix or delete either fix or delete
sebgab
commented
Deleted in Deleted in d31f03b6c76023518a2565d4114bb2e61ae0914e
|
||||
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);
|
||||
|
sebgab marked this conversation as resolved
Outdated
Athamantis
commented
start address, pos? start address, pos?
sebgab
commented
Deleted in Deleted in d31f03b6c76023518a2565d4114bb2e61ae0914e
|
||||
} else if (fan_num == 2){
|
||||
check_eeprom_is_ready();
|
||||
return eeprom_read_byte(start_address_fan2 + pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
sebgab marked this conversation as resolved
Outdated
Athamantis
commented
what is pos??? what is pos???
sebgab
commented
pos is data position, aka how many bytes into the readable area you want to read. pos is data position, aka how many bytes into the readable area you want to read.
sebgab
commented
Deleted in Deleted in d31f03b6c76023518a2565d4114bb2e61ae0914e
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -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);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user
why write at a point? use current fan address so it can update the posision
Deleted in
d31f03b6c7