-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd847f6
commit 1712844
Showing
16 changed files
with
1,462 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,78 @@ | ||
/* | ||
/* | ||
* Project myProject | ||
* Author: Your Name | ||
* Date: | ||
* Date: | ||
* For comprehensive documentation and examples, please visit: | ||
* https://docs.particle.io/firmware/best-practices/firmware-template/ | ||
*/ | ||
|
||
// Include Particle Device OS APIs | ||
#include "Particle.h" | ||
// #include "application.h" | ||
#include "Constants.h" | ||
#include "CubeController.h" | ||
#include "constants.h" | ||
#include "cube_controller.h" | ||
#include "dogica.h" | ||
#include "font.h" | ||
|
||
// Let Device OS manage the connection to the Particle Cloud | ||
SYSTEM_MODE(AUTOMATIC); | ||
|
||
// Run the application and system concurrently in separate threads | ||
SYSTEM_THREAD(ENABLED); | ||
|
||
LEDCUBE_NAMESPACE_BEGIN | ||
|
||
// Show system, cloud connectivity, and application logs over USB | ||
// View logs with CLI using 'particle serial monitor --follow' | ||
SerialLogHandler logHandler(LOG_LEVEL_INFO); | ||
|
||
CubeController * cube_controller; | ||
CubeController *cube_controller; | ||
|
||
system_tick_t last_tick; | ||
|
||
// setup() runs once, when the device is first turned on | ||
void setup() { | ||
|
||
Serial.begin(9600); | ||
|
||
pinMode(LED_DATA_PIN, OUTPUT); | ||
pinMode(LED_DATA_PIN, OUTPUT); | ||
pinMode(LED_CLOCK_PIN, OUTPUT); | ||
pinMode(LED_LATCH_PIN, OUTPUT); | ||
|
||
cube_controller = new CubeController(); | ||
cube_controller->update({0b01010101, ALL_BITS, ALL_BITS}, CLEAR); | ||
|
||
delay(5900); | ||
|
||
delay(500); | ||
font_glyph_dsc_t glyph = {}; | ||
draw_buf_t buffer = {}; | ||
font_get_glyph_dsc(&dogica, &glyph, 0x0047); | ||
font_get_glyph_bitmap(&glyph, &buffer); | ||
|
||
Serial.printlnf("Found letter width %d", buffer.size); | ||
for (int i = 0; i < 8; i++) { | ||
Serial.print("//"); | ||
for (int j = 0; j < buffer.size; j++) { | ||
if (bit_check(buffer.bitmap[j], i)) { | ||
Serial.print(" #"); | ||
} else { | ||
Serial.print(" ."); | ||
} | ||
} | ||
Serial.println(""); | ||
} | ||
} | ||
|
||
// loop() runs over and over again, as quickly as it can execute. | ||
void loop() { | ||
|
||
cube_controller->refresh(); | ||
|
||
system_tick_t now = millis(); | ||
|
||
if (now - last_tick > 500) { | ||
last_tick = now; | ||
cube_controller->update(ALL_CUBE, TOGGLE); | ||
} | ||
} | ||
|
||
LEDCUBE_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "abstract_program.h" | ||
|
||
LEDCUBE_NAMESPACE_BEGIN | ||
|
||
void AbstractProgram::init(CubeController *cube_controller_p) { | ||
cube_controller_p = cube_controller_p; | ||
} | ||
|
||
void AbstractProgram::loop() { | ||
system_tick_t now = millis(); | ||
if (now - last_tick > 500) { | ||
last_tick = now; | ||
tick(); | ||
} | ||
} | ||
|
||
LEDCUBE_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef AbstractProgram_H | ||
#define AbstractProgram_H | ||
|
||
#include "cube_controller.h" | ||
|
||
LEDCUBE_NAMESPACE_BEGIN | ||
|
||
class AbstractProgram { | ||
public: | ||
void init(CubeController *cube_controller_p); | ||
void loop(); | ||
virtual void tick(); | ||
|
||
protected: | ||
CubeController *cube_controller_p; | ||
system_tick_t last_tick; | ||
}; | ||
|
||
LEDCUBE_NAMESPACE_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef Constants_H | ||
#define Constants_H | ||
|
||
#ifndef LEDCUBE_NAMESPACE_BEGIN | ||
#define LEDCUBE_NAMESPACE_BEGIN //namespace LedCube { | ||
#define LEDCUBE_NAMESPACE_END //} | ||
#endif | ||
|
||
LEDCUBE_NAMESPACE_BEGIN | ||
|
||
#define LED_CLOCK_PIN TX | ||
#define LED_DATA_PIN RX | ||
#define LED_LATCH_PIN A7 | ||
|
||
#define LED_CUBE_SIZE 8 | ||
#define REFRESH_RATE 1000 | ||
|
||
enum class LedCubeOperation { set, clear, toggle }; | ||
|
||
#define SET LedCubeOperation::set | ||
#define TOGGLE LedCubeOperation::toggle | ||
#define CLEAR LedCubeOperation::clear | ||
|
||
#define ALL_BITS 0xFF | ||
#define ALL_CUBE \ | ||
{ ALL_BITS, ALL_BITS, ALL_BITS } | ||
|
||
/* | ||
* Bit operations | ||
*/ | ||
#define bit_set(byte, nbit) ((byte) |= (1 << (nbit))) | ||
#define bit_clear(byte, nbit) ((byte) &= ~(1 << (nbit))) | ||
#define bit_flip(byte, nbit) ((byte) ^= (1 << (nbit))) | ||
#define bit_check(byte, nbit) ((byte) & (1 << (nbit))) | ||
|
||
#define idx_to_bit(idx) (uint8_t)(0x01 << idx) | ||
|
||
#define write_to_register(out) \ | ||
shiftOut(LED_DATA_PIN, LED_CLOCK_PIN, MSBFIRST, out); | ||
|
||
LEDCUBE_NAMESPACE_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "cube_controller.h" | ||
|
||
LEDCUBE_NAMESPACE_BEGIN | ||
|
||
CubeController::CubeController() { | ||
active_layer = -1; | ||
update(ALL_CUBE, CLEAR); | ||
} | ||
|
||
void CubeController::refresh() { | ||
unsigned long now = micros(); | ||
if (now - last_refresh < REFRESH_RATE) { | ||
return; | ||
} | ||
|
||
last_refresh = now; | ||
active_layer = (active_layer + 1) % LED_CUBE_SIZE; | ||
|
||
digitalWrite(LED_LATCH_PIN, LOW); | ||
|
||
// We need to write all 9 regissters in reverse order, starting with the layer register | ||
write_to_register(idx_to_bit(active_layer)) | ||
|
||
// Then the 8 rows, in reverse order | ||
for (int row = LED_CUBE_SIZE; row > 0; row--) { | ||
write_to_register(led_cube[row - 1][active_layer]); | ||
} | ||
|
||
digitalWrite(LED_LATCH_PIN, HIGH); | ||
} | ||
|
||
bool CubeController::led(uint8_t x, uint8_t y, uint8_t z) { | ||
byte row = led_cube[y][z]; | ||
return bit_check(row, x); | ||
} | ||
|
||
void CubeController::update(uint8_t x, uint8_t y, uint8_t z, LedCubeOperation operation) { | ||
update({ idx_to_bit(x), idx_to_bit(y), idx_to_bit(z) }, operation); | ||
} | ||
|
||
void CubeController::update(CubeAddress address, LedCubeOperation operation) { | ||
for (int z = 0; z < LED_CUBE_SIZE; z++) { | ||
if (bit_check(address.z, z)) { | ||
for (int y = 0; y < LED_CUBE_SIZE; y++) { | ||
if (bit_check(address.y, y)) { | ||
switch (operation) { | ||
case LedCubeOperation::set: | ||
led_cube[y][z] |= address.x; | ||
break; | ||
case LedCubeOperation::toggle: | ||
led_cube[y][z] ^= address.x; | ||
break; | ||
case LedCubeOperation::clear: | ||
led_cube[y][z] &= ~address.x; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
LEDCUBE_NAMESPACE_END |
Oops, something went wrong.