Commit d8f5eee72686b19c9d61f8d77b842581ac922e80
Committed by
GitHub
1 parent
ae5cef79
Delete Commissioning.ino
Showing
1 changed file
with
0 additions
and
201 deletions
Examples/Commissioning/Commissioning.ino deleted
| 1 | -/*########################################################################### | |
| 2 | -DALI Interface Demo | |
| 3 | - | |
| 4 | -Commissioning demo - assign short addresses to all LED Drivers on the DALI bus | |
| 5 | - | |
| 6 | -Works with Arduino ATMEGA328 + Mikroe DALI Click | |
| 7 | - | |
| 8 | ----------------------------------------------------------------------------- | |
| 9 | -Changelog: | |
| 10 | -2020-11-08 Created & tested on ATMega328 @ 8Mhz | |
| 11 | ----------------------------------------------------------------------------- | |
| 12 | - Commisioning.ino - copyright qqqlab.com / github.com/qqqlab | |
| 13 | - | |
| 14 | - This program is free software: you can redistribute it and/or modify | |
| 15 | - it under the terms of the GNU General Public License as published by | |
| 16 | - the Free Software Foundation, either version 3 of the License, or | |
| 17 | - (at your option) any later version. | |
| 18 | - | |
| 19 | - This program is distributed in the hope that it will be useful, | |
| 20 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 21 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 22 | - GNU General Public License for more details. | |
| 23 | - | |
| 24 | - You should have received a copy of the GNU General Public License | |
| 25 | - along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 26 | -###########################################################################*/ | |
| 27 | - | |
| 28 | -#define DALI_OUTPUT_PIN 3 | |
| 29 | -#define DALI_INPUT_PIN 4 | |
| 30 | - | |
| 31 | -#include "qqqDali_ATMega328.h" | |
| 32 | - | |
| 33 | -Dali_ATMega328 dali; | |
| 34 | - | |
| 35 | -void setup() { | |
| 36 | - Serial.begin(115200); | |
| 37 | - Serial.println("DALI Commisioning Demo"); | |
| 38 | - | |
| 39 | - //start the DALI interfaces | |
| 40 | - //arguments: tx_pin, rx_pin (negative values disable transmitter / receiver) | |
| 41 | - //Note: the receiver pins should be on different PCINT groups, e.g one | |
| 42 | - //receiver on pin0-7 (PCINT2) one on pin8-13 (PCINT0) and one on pin14-19 (PCINT1) | |
| 43 | - dali.begin(DALI_OUTPUT_PIN, DALI_INPUT_PIN); | |
| 44 | - | |
| 45 | - menu(); | |
| 46 | -} | |
| 47 | - | |
| 48 | - | |
| 49 | -void loop() { | |
| 50 | - while (Serial.available() > 0) { | |
| 51 | - int incomingByte = Serial.read(); | |
| 52 | - switch(incomingByte) { | |
| 53 | - case '1': menu_blink(); menu(); break; | |
| 54 | - case '2': menu_scan_short_addr(); menu(); break; | |
| 55 | - case '3': menu_commission(); menu(); break; | |
| 56 | - case '4': menu_commission_debug(); menu(); break; | |
| 57 | - case '5': menu_delete_short_addr(); menu(); break; | |
| 58 | - } | |
| 59 | - } | |
| 60 | -} | |
| 61 | - | |
| 62 | -void menu() { | |
| 63 | - Serial.println("----------------------------"); | |
| 64 | - Serial.println("1 Blink all lamps"); | |
| 65 | - Serial.println("2 Scan short addresses"); | |
| 66 | - Serial.println("3 Commission short addresses"); | |
| 67 | - Serial.println("4 Commission short addresses (VERBOSE)"); | |
| 68 | - Serial.println("5 Delete short addresses"); | |
| 69 | - Serial.println("----------------------------"); | |
| 70 | -} | |
| 71 | - | |
| 72 | - | |
| 73 | -void menu_blink() { | |
| 74 | - Serial.println("Running: Blinking all lamps"); | |
| 75 | - for(uint8_t i=0;i<5;i++) { | |
| 76 | - dali.set_level(254); | |
| 77 | - Serial.print("."); | |
| 78 | - delay(500); | |
| 79 | - dali.set_level(0); | |
| 80 | - Serial.print("."); | |
| 81 | - delay(500); | |
| 82 | - } | |
| 83 | - Serial.println(); | |
| 84 | -} | |
| 85 | - | |
| 86 | -void menu_scan_short_addr() { | |
| 87 | - Serial.println("Running: Scan all short addresses"); | |
| 88 | - uint8_t sa; | |
| 89 | - uint8_t cnt = 0; | |
| 90 | - for(sa = 0; sa<64; sa++) { | |
| 91 | - int16_t rv = dali.cmd(DALI_QUERY_STATUS,sa); | |
| 92 | - if(rv!=DALI_RESULT_NO_REPLY) { | |
| 93 | - cnt++; | |
| 94 | - Serial.print("short address="); | |
| 95 | - Serial.print(sa); | |
| 96 | - Serial.print(" status=0x"); | |
| 97 | - Serial.print(rv,HEX); | |
| 98 | - Serial.print(" minLevel="); | |
| 99 | - Serial.print(dali.cmd(DALI_QUERY_MIN_LEVEL,sa)); | |
| 100 | - Serial.print(" flashing"); | |
| 101 | - for(uint8_t i=0;i<5;i++) { | |
| 102 | - dali.set_level(254,sa); | |
| 103 | - Serial.print("."); | |
| 104 | - delay(500); | |
| 105 | - dali.set_level(0,sa); | |
| 106 | - Serial.print("."); | |
| 107 | - delay(500); | |
| 108 | - } | |
| 109 | - Serial.println(); | |
| 110 | - } | |
| 111 | -// }else{ | |
| 112 | -// //remove all short addres for this sa | |
| 113 | -// dali.cmd(DALI_DATA_TRANSFER_REGISTER0,0xFF); | |
| 114 | -// dali.cmd(DALI_SET_SHORT_ADDRESS, sa); | |
| 115 | -// } | |
| 116 | - } | |
| 117 | - Serial.print("DONE, found ");Serial.print(cnt);Serial.println(" short addresses"); | |
| 118 | -} | |
| 119 | - | |
| 120 | -//might need a couple of calls to find everything... | |
| 121 | -void menu_commission(){ | |
| 122 | - Serial.println("Running: Commission"); | |
| 123 | - Serial.println("Might need a couple of runs to find all lamps ..."); | |
| 124 | - Serial.println("Be patient, this takes a while ..."); | |
| 125 | - uint8_t cnt = dali.commission(0xff); //init_arg=0b11111111 : all without short address | |
| 126 | - Serial.print("DONE, assigned ");Serial.print(cnt);Serial.println(" new short addresses"); | |
| 127 | -} | |
| 128 | - | |
| 129 | -//might need a couple of calls to find everything... | |
| 130 | -void menu_commission_debug(){ | |
| 131 | - Serial.println("Running: Commission (VERBOSE)"); | |
| 132 | - Serial.println("Might need a couple of runs to find all lamps ..."); | |
| 133 | - Serial.println("Be patient, this takes a while ..."); | |
| 134 | - uint8_t cnt = debug_commission(0xff); //init_arg=0b11111111 : all without short address | |
| 135 | - Serial.print("DONE, assigned ");Serial.print(cnt);Serial.println(" new short addresses"); | |
| 136 | -} | |
| 137 | - | |
| 138 | -void menu_delete_short_addr() { | |
| 139 | - Serial.println("Running: Delete all short addresses"); | |
| 140 | - //remove all short addresses | |
| 141 | - dali.cmd(DALI_DATA_TRANSFER_REGISTER0,0xFF); | |
| 142 | - dali.cmd(DALI_SET_SHORT_ADDRESS, 0xFF); | |
| 143 | - Serial.println("DONE delete"); | |
| 144 | -} | |
| 145 | - | |
| 146 | -//init_arg=11111111 : all without short address | |
| 147 | -//init_arg=00000000 : all | |
| 148 | -//init_arg=0AAAAAA1 : only for this shortadr | |
| 149 | -//returns number of new short addresses assigned | |
| 150 | -uint8_t debug_commission(uint8_t init_arg) { | |
| 151 | - uint8_t cnt = 0; | |
| 152 | - uint8_t arr[64]; | |
| 153 | - uint8_t sa; | |
| 154 | - for(sa=0; sa<64; sa++) arr[sa]=0; | |
| 155 | - | |
| 156 | - dali.cmd(DALI_RESET,0x00); | |
| 157 | - dali.cmd(DALI_INITIALISE,init_arg); | |
| 158 | - dali.cmd(DALI_RANDOMISE,0x00); | |
| 159 | - | |
| 160 | - //find used short addresses (run always, seems to work better than without...) | |
| 161 | - Serial.println("Find existing short adr"); | |
| 162 | - for(sa = 0; sa<64; sa++) { | |
| 163 | - int16_t rv = dali.cmd(DALI_QUERY_STATUS,sa); | |
| 164 | - if(rv!=DALI_RESULT_NO_REPLY) { | |
| 165 | - if(init_arg!=0b00000000) arr[sa]=1; //remove address from list if not in "all" mode | |
| 166 | - Serial.print("sortadr="); | |
| 167 | - Serial.print(sa); | |
| 168 | - Serial.print(" status=0x"); | |
| 169 | - Serial.print(rv,HEX); | |
| 170 | - Serial.print(" minLevel="); | |
| 171 | - Serial.println(dali.cmd(DALI_QUERY_MIN_LEVEL,sa)); | |
| 172 | - } | |
| 173 | - } | |
| 174 | - | |
| 175 | - Serial.println("Find random adr"); | |
| 176 | - while(1) { | |
| 177 | - uint32_t adr = dali.find_addr(); | |
| 178 | - if(adr>0xffffff) break; | |
| 179 | - Serial.print("found="); | |
| 180 | - Serial.println(adr,HEX); | |
| 181 | - | |
| 182 | - //find available address | |
| 183 | - for(sa=0; sa<64; sa++) { | |
| 184 | - if(arr[sa]==0) break; | |
| 185 | - } | |
| 186 | - if(sa>=64) break; | |
| 187 | - arr[sa] = 1; | |
| 188 | - cnt++; | |
| 189 | - | |
| 190 | - Serial.print("program short adr="); | |
| 191 | - Serial.println(sa); | |
| 192 | - dali.program_short_address(sa); | |
| 193 | - Serial.print("read short adr="); | |
| 194 | - Serial.println(dali.query_short_address()); | |
| 195 | - | |
| 196 | - dali.cmd(DALI_WITHDRAW,0x00); | |
| 197 | - } | |
| 198 | - | |
| 199 | - dali.cmd(DALI_TERMINATE,0x00); | |
| 200 | - return cnt; | |
| 201 | -} |