Compare commits
No commits in common. "b858d29ce8e0b90edc451d5d22c81feadc055c1f" and "275c40498fb026a7dace972b099616b1b30dd927" have entirely different histories.
b858d29ce8
...
275c40498f
@ -1,5 +1,4 @@
|
|||||||
#include "command-handler.h"
|
#include "command-handler.h"
|
||||||
#include "fan_speeeed.h"
|
|
||||||
|
|
||||||
// Initialize empty, global command context
|
// Initialize empty, global command context
|
||||||
volatile command_context_t context = {UNKNOWN_COMMAND, SRC_NONE, FAN_NONE,
|
volatile command_context_t context = {UNKNOWN_COMMAND, SRC_NONE, FAN_NONE,
|
||||||
@ -236,32 +235,18 @@ uint8_t route_command(int pos) {
|
|||||||
break;
|
break;
|
||||||
case READ_FAN_SPEED:
|
case READ_FAN_SPEED:
|
||||||
if (context.fan == FAN1) {
|
if (context.fan == FAN1) {
|
||||||
return fan1_history[fan1_history_index];
|
return fan1_history[0];
|
||||||
} else if (context.fan == FAN2) {
|
} else if (context.fan == FAN2) {
|
||||||
return fan2_history[fan2_history_index];
|
return fan2_history[0];
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case READ_BULK_FAN_SPEED:
|
case READ_BULK_FAN_SPEED:
|
||||||
if (context.fan == FAN1) {
|
if (context.fan == FAN1) {
|
||||||
// Validate that pos is valid, if not return 0
|
return fan1_history[pos];
|
||||||
if (pos >= 512) { return 0; }
|
|
||||||
|
|
||||||
// Calculate the index position
|
|
||||||
int16_t index = fan1_history_index - pos;
|
|
||||||
if (index < 0) { index = 511-pos; }
|
|
||||||
|
|
||||||
return fan1_history[index];
|
|
||||||
} else if (context.fan == FAN2) {
|
} else if (context.fan == FAN2) {
|
||||||
// Validate that pos is valid, if not return 0
|
return fan2_history[pos];
|
||||||
if (pos >= 512) { return 0; }
|
|
||||||
|
|
||||||
// Calculate the index position
|
|
||||||
int16_t index = fan2_history_index - pos;
|
|
||||||
if (index < 0) { index = 511-pos; }
|
|
||||||
|
|
||||||
return fan2_history[index];
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,9 +66,6 @@ typedef struct {
|
|||||||
// Fan history variables
|
// Fan history variables
|
||||||
extern volatile uint16_t fan1_history[512];
|
extern volatile uint16_t fan1_history[512];
|
||||||
extern volatile uint16_t fan2_history[512];
|
extern volatile uint16_t fan2_history[512];
|
||||||
// Fan history index variable
|
|
||||||
volatile uint16_t fan1_history_index = 0;
|
|
||||||
volatile uint16_t fan2_history_index = 0;
|
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
extern volatile config_t config;
|
extern volatile config_t config;
|
||||||
|
|||||||
@ -98,25 +98,8 @@ ISR(AC1_AC_vect){ // AC1 vec flag
|
|||||||
// TIMER INTERUPT
|
// TIMER INTERUPT
|
||||||
ISR (TCA0_OVF_vect) {
|
ISR (TCA0_OVF_vect) {
|
||||||
cli();
|
cli();
|
||||||
|
RPM_calculation(fan1_edge_counter,timer_period_ms);
|
||||||
// Increment the index, or reset if it is at the top
|
RPM_calculation(fan2_edge_counter,timer_period_ms);
|
||||||
if (fan1_history_index < 512) {
|
|
||||||
fan1_history_index++;
|
|
||||||
} else {
|
|
||||||
fan1_history_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fan2_history_index < 512) {
|
|
||||||
fan2_history_index++;
|
|
||||||
} else {
|
|
||||||
fan2_history_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the fanspeed
|
|
||||||
fan1_history[fan1_history_index] = RPM_calculation(fan1_edge_counter,timer_period_ms);
|
|
||||||
fan2_history[fan2_history_index] = RPM_calculation(fan2_edge_counter,timer_period_ms);
|
|
||||||
|
|
||||||
// Reset the edge counter
|
|
||||||
fan1_edge_counter = 0;
|
fan1_edge_counter = 0;
|
||||||
fan2_edge_counter = 0;
|
fan2_edge_counter = 0;
|
||||||
TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm ;
|
TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm ;
|
||||||
|
|||||||
@ -29,12 +29,6 @@ extern "C" {
|
|||||||
* and inspiration form practice 6 for TCA0 setup
|
* and inspiration form practice 6 for TCA0 setup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Fan history variables
|
|
||||||
extern volatile uint16_t fan1_history[512];
|
|
||||||
extern volatile uint16_t fan2_history[512];
|
|
||||||
// Fan history index variable
|
|
||||||
volatile uint16_t fan1_history_index = 0;
|
|
||||||
volatile uint16_t fan2_history_index = 0;
|
|
||||||
|
|
||||||
// INITALICE TIMER COUNTER
|
// INITALICE TIMER COUNTER
|
||||||
void init_TCA0();
|
void init_TCA0();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user