Browse Source

Revert "new node and FastLED"

This reverts commit 4730087f9e.
led
wiebel 7 years ago
parent
commit
c7e9d40c91
  1. 104
      src/CANNode.cpp
  2. 3
      src/CANNode.h
  3. 26
      src/Node_2_def.h
  4. 1
      src/Node_3_def.h

104
src/CANNode.cpp

@ -10,12 +10,11 @@
#include <Metro.h>
#include <FlexCAN.h>
#include <OneWire.h>
#include <FastLED.h>
#include "CANNode.h"
// For Node definition:
#include "Node_2_def.h"
#include "Node_3_def.h"
// Metro ticks in ms
#define METRO_CAN_tick 1
@ -53,12 +52,9 @@
uint8_t led = ONBOARD_LED;
uint8_t led = LED;
uint8_t state;
uint8_t pin_state;
uint8_t led_current_value;
uint8_t led_last_value;
int serial_in;
bool action[2];
// Metro
Metro METRO_CAN = Metro(METRO_CAN_tick);
@ -75,8 +71,6 @@ OneWire OW_1(OW_pin);
telegram_comp_t mesg_comp;
// event info = { 1, 0x03, 0x01, OFF, 0x01};
static CAN_message_t txmsg,rxmsg;
static uint8_t hex[17] = "0123456789abcdef";
@ -84,9 +78,6 @@ int txCount,rxCount;
unsigned int txTimer,rxTimer;
CRGB leds[NUM_LEDS];
// Functions ------------------------------^-------------------------
void PrintBytes(uint8_t* addr, uint8_t count, bool newline=0) {
for (uint8_t i = 0; i < count; i++) {
@ -133,7 +124,7 @@ uint8_t toggle_Pin(uint8_t pin){
}
uint32_t forgeid(event_t event){
return (event.prio<<26)+(event.dst<<18)+(NODE_ID<<8)+event.cmd;
return (event.prio<<26)+(event.dst<<16)+(NODE_ID<<8)+event.cmd;
}
telegram_comp_t parse_CAN(CAN_message_t mesg){
@ -165,94 +156,35 @@ void send_event (uint8_t trig_event){
txmsg.len = 0;
}
}
void switch_leds (uint8_t value) {
led_last_value = led_current_value;
// FastLED.setTemperature( TEMP );
// FastLED.setBrightness( BRIGHTNESS );
memset8( leds, value, NUM_LEDS * sizeof(CRGB));
led_current_value = value;
FastLED.show();
}
void toggle_leds ( void ) {
if ( led_current_value != 0) {
switch_leds(0);
} else {
if ( led_current_value == led_last_value){
switch_leds(255);
} else {
switch_leds(led_last_value);
}
}
}
void take_action (action_type type, uint8_t tag ){
for (uint8_t i = 0; action_map[i].tag != 0 ; i++) {
if ( action_map[i].tag == tag ) {
switch ( type ) {
case OFF:
switch ( outputs[action_map[i].outputs_idx].type ){
case GPIO:
digitalWrite(outputs[action_map[i].outputs_idx].address,LOW ^ outputs[action_map[i].outputs_idx].invert);
break;
case LED:
switch_leds(0);
break;
}
Serial.print(F("Switching OFF Output: "));
Serial.println(action_map[i].outputs_idx);
break;
case ON:
switch ( outputs[action_map[i].outputs_idx].type ){
case GPIO:
digitalWrite(outputs[action_map[i].outputs_idx].address,HIGH ^ outputs[action_map[i].outputs_idx].invert);
break;
case LED:
switch_leds(255);
break;
}
digitalWrite(outputs[action_map[i].outputs_idx].address, HIGH ^ outputs[action_map[i].outputs_idx].invert);
Serial.print(F("Switching ON Output: "));
Serial.println(action_map[i].outputs_idx);
break;
case TOGGLE:
pin_state = toggle_Pin(outputs[action_map[i].outputs_idx].address);
Serial.print(F("Toggeling Output: "));
Serial.print(action_map[i].outputs_idx);
Serial.print(F(" to new state: "));
switch ( outputs[action_map[i].outputs_idx].type ){
case GPIO:
pin_state = toggle_Pin(outputs[action_map[i].outputs_idx].address);
Serial.println(pin_state ^ outputs[action_map[i].outputs_idx].invert);
break;
case LED:
toggle_leds();
Serial.println(led_current_value);
break;
}
break;
case VALUE:
switch ( outputs[action_map[i].outputs_idx].type ){
case GPIO:
if (VALUE == 0) {
digitalWrite(outputs[action_map[i].outputs_idx].address,LOW ^ outputs[action_map[i].outputs_idx].invert);
} else {
digitalWrite(outputs[action_map[i].outputs_idx].address, HIGH ^ outputs[action_map[i].outputs_idx].invert);
}
break;
case LED:
switch_leds(VALUE);
break;
}
Serial.print(F("Setting Output: "));
Serial.print(action_map[i].outputs_idx);
Serial.print(F(" to value: "));
Serial.println(VALUE);
Serial.println(F("TBD"));
break;
}
}
}
}
// -------------------------------------------------------------
void setup(void)
{
@ -268,11 +200,6 @@ void setup(void)
CANbus.begin();
txmsg.ext = 1;
txmsg.timeout = 100;
// FastLED
//delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
FastLED.setTemperature( TEMP );
// outputs
for (size_t i = 0; outputs[i].type != NOP; i++) {
@ -441,24 +368,5 @@ void loop(void)
txmsg.buf[0]++;
txmsg.len = 0;
}
if (Serial.available() > 0) {
// read the incoming byte:
serial_in = Serial.read();
switch (serial_in) {
case 0x31 : take_action(TOGGLE, 1); break;
case 0x32 : take_action(TOGGLE, 2); break;
case 0x33 : take_action(TOGGLE, 3); break;
case 0x34 : take_action(TOGGLE, 4); break;
case 0x35 : take_action(TOGGLE, 5); break;
case 0x36 : take_action(TOGGLE, 6); break;
case 0x37 : take_action(TOGGLE, 7); break;
case 0x38 : take_action(TOGGLE, 8); break;
case 0x39 : take_action(TOGGLE, 10); break;
// case 0x38 : digitalWrite(13, 1); break;
// case 0x39 : digitalWrite(13, 0); break;
}
// say what you got:
Serial.print("I received: ");
Serial.println(serial_in, HEX);
}
}

3
src/CANNode.h

@ -1,14 +1,13 @@
#include <Arduino.h>
#ifndef CANNODE_TYPES
#define CANNODE_TYPES
enum out_type { GPIO, PWM, OW, I2C, SPI, LED, DMX, NOP };
enum out_type { GPIO, PWM, OW, I2C, SPI, WS2811, DMX, NOP };
enum event_type { LOCAL, SEND};
enum action_type { OFF, ON, VALUE, TOGGLE };
enum telegram_type { ALERT, EVENT, NOTIFY, INFO };
typedef struct CAN_telegram_t {
// 3bit prio -
uint32_t id;
uint8_t length;
uint8_t buf[8];

26
src/Node_2_def.h

@ -10,16 +10,16 @@
#define N_ACTIONS 64
#define DEBUG 0 // 1 for noisy serial
#define ONBOARD_LED 13
#define LED 13
#define LED_PIN 20
#define COLOR_ORDER GRB
#define CHIPSET WS2812
#define NUM_LEDS 4
#define BRIGHTNESS 255
//#define TEMP Tungsten100W
#define TEMP Candle
#define RELAY1 0
#define RELAY2 1
#define RELAY3 23
#define RELAY4 22
#define RELAY5 17
#define RELAY6 16
#define RELAY7 9
#define RELAY8 10
// OneWire
#define OW_pin 14
@ -45,10 +45,9 @@ static outputs_t outputs[N_OUTPUTS] PROGMEM={
{ GPIO, 22, 0, true }, // 3
{ GPIO, 17, 0, true }, // 4
{ GPIO, 16, 0, true }, // 5
{ GPIO, 19, 255, true }, // 6
{ GPIO, 18, 0, true }, // 7
{ LED, 21, 0, false }, // 8
{ NOP, 0xFF, 0, 0 },
{ GPIO, 9, 255, true }, // 6
{ GPIO, 10, 0, true }, // 7
{ NOP, 0xFF, 0, 0 }
};
static uint8_t outputs_state[N_OUTPUTS];
// ID:
@ -100,7 +99,6 @@ static action_t action_map[N_ACTIONS] PROGMEM={
{7, 6},
{8, 7},
{9, 0},{9, 1},{9, 2},{9, 3},{9, 4},{9, 5},{9, 6},{9, 7},
{10, 8},
{210, 210},
{211, 211},
{220, 220},

1
src/Node_3_def.h

@ -1,3 +1,4 @@
#include "CANNode.h"
// Configuration
#define NODE_ID 0x03

Loading…
Cancel
Save