Skip to content

Commit 585bf5a

Browse files
committed
Dirty Fix for arduino builder bug
Had to flip whole structure upside down because this piece of ****: arduino/arduino-builder#68 arduino/arduino-builder#80 arduino/arduino-builder#85 and countless other issue tickets, arduino builder preprocessor fails to do prototype and can't reorder functions so everything must be just in the right order (and also breaks many libraries and other third party boards). Code may not compile properly as long as arduino developpers can't get their **** together. Wifi part won't work until underlying issue in arduino-builder gets fixed or old version of arduino ide is used or something is gludged to overcome these issues.
1 parent 39a53cc commit 585bf5a

File tree

2 files changed

+86
-86
lines changed

2 files changed

+86
-86
lines changed

Arduino source/hardware.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ const int rowAdrsPin[] = {0, 1, 2, 3}; //Row decoder pins, 0-11 dec values corre
3030

3131
#define ledColumns 128 //How many pixels in one row
3232
#define firstRowAdrs 1 //first row address, 1 for 10 row display, 0 for 12 row display
33-
#define lastRowArds 10 //last row address, 10 for 10 row display, 11 for 12 row display
33+
#define lastRowAdrs 10 //last row address, 10 for 10 row display, 11 for 12 row display
3434

Arduino source/main.cpp

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
Ketturi 2016
77
*/
88

9-
#include <pgmspace.h>
10-
#include <SPI.h>
119
#include "bitmap.h" //Image data from kukkaconvert.exe by wuffe goes here, put in PROGMEM to save ram
1210
#include "hardware.h" //Hardware definitions
11+
#include <pgmspace.h>
12+
#include <SPI.h>
1313

1414
//ESP8266 stuff
1515
#include <ESP8266WiFi.h>
@@ -28,47 +28,60 @@ byte pwm = 50; //sets initial brightness
2828
const unsigned int rowOnTime = 1000; //how long one row is lit, uS
2929
const unsigned int framerate = 5000; //milliseconds between frames, slows display down to readable speed
3030
unsigned long previousMillis = 0;
31-
int frame = 0;
31+
unsigned int frame = 0;
3232

33-
void setup() { //Set pins to outputs and inits other stuff
34-
pinMode(16, SPECIAL); //Set GPIO16 to default function, controls reset
35-
36-
//Important, do not remove these, or updating over wifi wont work!
37-
//*******************************
38-
setWiFi(); //Start WiFiManager
39-
otaUpdate(); //Enable ota updates
40-
//*******************************
33+
void selectRow(byte RowAdrs) { //Selects which row gets illuminated, 4Bit address
34+
for (int b = 0; b < 4; b++) {
35+
if ((0x01 & RowAdrs) < 0x01)
36+
digitalWrite(rowAdrsPin[b], LOW);
37+
else
38+
digitalWrite(rowAdrsPin[b], HIGH);
39+
RowAdrs >>= 1;
40+
}
41+
}
4142

42-
pinMode(0, FUNCTION_0);
43-
pinMode(1, FUNCTION_3);
44-
pinMode(2, FUNCTION_0);
45-
pinMode(3, FUNCTION_3);
46-
pinMode(4, FUNCTION_0);
47-
pinMode(5, FUNCTION_0);
48-
pinMode(13, FUNCTION_2);
49-
pinMode(14, FUNCTION_2);
50-
pinMode(15, FUNCTION_2);
43+
void shiftOut32(unsigned long input) { //32Bit shift out with HW SPI, sends data in 8bit pieces to shift register
44+
SPI.beginTransaction(SPISettings(SPISPEED, LSBFIRST, SPI_MODE0)); //25Mhz, LSBFIRST, clock polarity and phase
45+
SPI.transfer(input >> 0);
46+
SPI.transfer(input >> 8);
47+
SPI.transfer(input >> 16);
48+
SPI.transfer(input >> 24);
49+
SPI.endTransaction();
50+
}
5151

52-
pinMode(latchPin, OUTPUT);
53-
pinMode(enablePin, OUTPUT);
54-
digitalWrite(enablePin, HIGH);
52+
//getRowWord by wuffe, converts bitmap array to display lines
53+
const unsigned long getRowWord(const unsigned int x, unsigned const int y, const unsigned int width, const unsigned long* data) {
54+
// NB: x's remainders may be slow to calculate, if compiler can't deduce beforehand
55+
// what value "width" will get when function is called.
56+
const unsigned int xa = x % width;
57+
const unsigned int xb = (x + 32) % width;
58+
const unsigned int ya = y % 12;
59+
const unsigned int shift = xa % 32;
5560

56-
for (int i = 0; i < 4; i++) {
57-
pinMode(rowAdrsPin[i], OUTPUT);
58-
}
61+
const unsigned int aPtr = ya + (xa / 32) * 12;
62+
const unsigned int bPtr = ya + (xb / 32) * 12;
5963

60-
analogWrite(pwmPin, pwm); //Set initial brightness
61-
SPI.begin();
62-
Serial.setDebugOutput(false); //Stop all serial communication as serial pins are used for display
63-
Serial.end();
64+
//Conditional to prevent 32-bit variable being shifted with 32 (not defined, not in C anyhow).
65+
return shift == 0 ? data[aPtr] : ((data[aPtr] << shift) | (data[bPtr] >> (32 - shift)));
66+
//return shift == 0 ? pgm_read_dword(data + aPtr) : ((pgm_read_dword(data + aPtr) << shift) | (pgm_read_dword(data + bPtr) >> (bits - shift)));
6467
}
6568

66-
void loop() { //loops constantly
67-
ArduinoOTA.handle(); //Checks for incoming update, please don't remove!
68-
refreshDisplay();
69+
void sendColumn(int col, byte row) { //Toggles control lines and outputs display data.
70+
digitalWrite(latchPin, LOW);
71+
shiftOut32(getRowWord(col + 96, row, imageWidth, imageData)); //last panel
72+
shiftOut32(getRowWord(col + 64, row, imageWidth, imageData)); //third panel
73+
shiftOut32(getRowWord(col + 32, row, imageWidth, imageData)); //second panel
74+
shiftOut32(getRowWord(col , row, imageWidth, imageData)); //first panel
75+
digitalWrite(latchPin, HIGH);
76+
77+
digitalWrite(enablePin, LOW);
78+
/*Delay for leds being enabled, affects how bright display is.
79+
ESP8266 does WiFi and TCP/IP task during delays*/
80+
delayMicroseconds(rowOnTime);
81+
digitalWrite(enablePin, HIGH);
6982
}
7083

71-
void refreshDisplay() { //Updates whole display
84+
void refreshDisplay() {
7285
#if (ANIMATION) //shows single frames crating animation
7386
unsigned long currentMillis = millis();
7487
if (currentMillis - previousMillis >= framerate) { //crude timer for frame rate.
@@ -101,57 +114,6 @@ void refreshDisplay() { //Updates whole display
101114
#endif
102115
}
103116

104-
void sendColumn(int col, byte row) { //Toggles control lines and outputs display data.
105-
digitalWrite(latchPin, LOW);
106-
shiftOut32(getRowWord(col + 96, row, imageWidth, imageData)); //last panel
107-
shiftOut32(getRowWord(col + 64, row, imageWidth, imageData)); //third panel
108-
shiftOut32(getRowWord(col + 32, row, imageWidth, imageData)); //second panel
109-
shiftOut32(getRowWord(col , row, imageWidth, imageData)); //first panel
110-
digitalWrite(latchPin, HIGH);
111-
112-
digitalWrite(enablePin, LOW);
113-
/*Delay for leds being enabled, affects how bright display is.
114-
ESP8266 does WiFi and TCP/IP task during delays*/
115-
delayMicroseconds(rowOnTime);
116-
digitalWrite(enablePin, HIGH);
117-
}
118-
119-
void selectRow(byte RowAdrs) { //Selects which row gets illuminated, 4Bit address
120-
for (int b = 0; b < 4; b++) {
121-
if ((0x01 & RowAdrs) < 0x01)
122-
digitalWrite(rowAdrsPin[b], LOW);
123-
else
124-
digitalWrite(rowAdrsPin[b], HIGH);
125-
multiRow >>= 1;
126-
}
127-
}
128-
129-
void shiftOut32(unsigned long input) { //32Bit shift out with HW SPI, sends data in 8bit pieces to shift register
130-
SPI.beginTransaction(SPISettings(SPISPEED, LSBFIRST, SPI_MODE0)); //25Mhz, LSBFIRST, clock polarity and phase
131-
SPI.transfer(input >> 0);
132-
SPI.transfer(input >> 8);
133-
SPI.transfer(input >> 16);
134-
SPI.transfer(input >> 24);
135-
SPI.endTransaction();
136-
}
137-
138-
//getRowWord by wuffe, converts bitmap array to display lines
139-
const unsigned long getRowWord(const unsigned int x, unsigned const int y, const unsigned int width, const unsigned long* data) {
140-
// NB: x's remainders may be slow to calculate, if compiler can't deduce beforehand
141-
// what value "width" will get when function is called.
142-
const unsigned int xa = x % width;
143-
const unsigned int xb = (x + 32) % width;
144-
const unsigned int ya = y % 12;
145-
const unsigned int shift = xa % 32;
146-
147-
const unsigned int aPtr = ya + (xa / 32) * 12;
148-
const unsigned int bPtr = ya + (xb / 32) * 12;
149-
150-
//Conditional to prevent 32-bit variable being shifted with 32 (not defined, not in C anyhow).
151-
return shift == 0 ? data[aPtr] : ((data[aPtr] << shift) | (data[bPtr] >> (32 - shift)));
152-
//return shift == 0 ? pgm_read_dword(data + aPtr) : ((pgm_read_dword(data + aPtr) << shift) | (pgm_read_dword(data + bPtr) >> (bits - shift)));
153-
}
154-
155117
void otaUpdate() { //Handless over the air updating from Arduino IDE
156118
WiFi.mode(WIFI_STA);
157119
WiFi.begin();
@@ -164,4 +126,42 @@ void setWiFi() { //If no wifi AP is found, create one, and serve user a config p
164126
WiFiManager wifiManager;
165127
wifiManager.setTimeout(180); //In 3 minutes continue normaly even if no wlan detected.
166128
wifiManager.autoConnect("FoxMatrix"); //Start WiFiManager with spesified AP name.
129+
}
130+
131+
void setup() { //Set pins to outputs and inits other stuff
132+
pinMode(16, SPECIAL); //Set GPIO16 to default function, controls reset
133+
134+
//Important, do not remove these, or updating over wifi wont work!
135+
//*******************************
136+
setWiFi(); //Start WiFiManager
137+
otaUpdate(); //Enable ota updates
138+
//*******************************
139+
140+
pinMode(0, FUNCTION_0);
141+
pinMode(1, FUNCTION_3);
142+
pinMode(2, FUNCTION_0);
143+
pinMode(3, FUNCTION_3);
144+
pinMode(4, FUNCTION_0);
145+
pinMode(5, FUNCTION_0);
146+
pinMode(13, FUNCTION_2);
147+
pinMode(14, FUNCTION_2);
148+
pinMode(15, FUNCTION_2);
149+
150+
pinMode(latchPin, OUTPUT);
151+
pinMode(enablePin, OUTPUT);
152+
digitalWrite(enablePin, HIGH);
153+
154+
for (int i = 0; i < 4; i++) {
155+
pinMode(rowAdrsPin[i], OUTPUT);
156+
}
157+
158+
analogWrite(pwmPin, pwm); //Set initial brightness
159+
SPI.begin();
160+
Serial.setDebugOutput(false); //Stop all serial communication as serial pins are used for display
161+
Serial.end();
162+
}
163+
164+
void loop() { //loops constantly
165+
ArduinoOTA.handle(); //Checks for incoming update, please don't remove!
166+
refreshDisplay();
167167
}

0 commit comments

Comments
 (0)