I am trying to declare an object of the class DdfsTone. I am trying to do this in my function matrix_core.cpp. Here is the code for matrix_core.cpp:
#include "matrix_core.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/* (x,y)
* (0,0) (1,0) (2,0)
* (0,1) (1,1) (2,1) . . .
* (0,2) (1,2) (2,2)
* .
* .
* .
*/
Ws2812Core light_grid(get_slot_addr(BRIDGE_BASE, S14_WS2812), 2, 2);
DdfsTone twelve_channel(get_slot_addr(BRIDGE_BASE, S12_DDFS));
MatrixCore::MatrixCore(uint32_t core_base_addr) {
base_addr = core_base_addr;
matrix0 = 0x00000000;
matrix1 = 0x00000000;
matrix2 = 0x00000000;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 12; j++) {
Board[i][j].state = 0; // set states to off
Board[i][j].released = 1; // The button is released
Board[i][j].color = 0x000000; // set colors to off
Board[i][j].x = i; // define location
Board[i][j].y = j; // define location
switch (j) { // initialize notes to concert scale (top row starts at C, goes down to B (higher note)
case 0: Board[i][j].note = CONCERT_C; break;
case 1: Board[i][j].note = CONCERT_Cs; break;
case 2: Board[i][j].note = CONCERT_D; break;
case 3: Board[i][j].note = CONCERT_Ds; break;
case 4: Board[i][j].note = CONCERT_E; break;
case 5: Board[i][j].note = CONCERT_F; break;
case 6: Board[i][j].note = CONCERT_Fs; break;
case 7: Board[i][j].note = CONCERT_G; break;
case 8: Board[i][j].note = CONCERT_Gs; break;
case 9: Board[i][j].note = CONCERT_A; break;
case 10: Board[i][j].note = CONCERT_As; break;
case 11: Board[i][j].note = CONCERT_B; break;
}
}
}
}
MatrixCore::MatrixCore() {
base_addr = get_slot_addr(BRIDGE_BASE, S4_USER);
matrix0 = 0x00000000;
matrix1 = 0x00000000;
matrix2 = 0x00000000;
} // not used
void MatrixCore::scan() {
uint32_t key;
uint32_t mask = 0x00000001;
uint32_t status;
int count = 0;
matrix0 = io_read(base_addr, 1);
matrix1 = io_read(base_addr, 2);
matrix2 = io_read(base_addr, 3);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 12; j++) {
if (count < 32) {
key = matrix0 >> (count % 32);
status = key & mask;
toggle(i, j, status);
} else if ((count >= 32) && (count < 64)) {
key = matrix1 >> (count % 32);
status = key & mask;
toggle(i, j, status);
} else if (count >= 64) {
key = matrix2 >> (count % 32);
status = key & mask;
toggle(i, j, status);
}
count++;
}
}
}
void MatrixCore::toggle(int i, int j, uint32_t currentScan) {
if (Board[i][j].state) { // tile is currently on
if (currentScan && Board[i][j].released) { // scanned on, needs to turn off
Board[i][j].state = 0;
Board[i][j].released = 0;
bluetooth_send_tile_state(i, j);
} else if (!currentScan && !Board[i][j].released) {
Board[i][j].released = 1;
}
} else if (!Board[i][j].state) { // tile is currently off
if (currentScan && Board[i][j].released) { // scanned on, needs to turn on
Board[i][j].state = 1;
Board[i][j].released = 0;
bluetooth_send_tile_state(i, j);
} else if (!currentScan && !Board[i][j].released) {
Board[i][j].released = 1;
}
}
}
void MatrixCore::setPauseTime(int new_time) {
pauseTime = new_time;
}
void MatrixCore::setPlayTime(int new_time) {
playTime = new_time;
}
void MatrixCore::set_color(int x, int y, uint32_t color) {
Board[x][y].color = color;
light_grid.wr_pix(y, x, color);
}
void MatrixCore::pauseWhileScanning(int pause_ms) { // give a ms value and will scan every us while waiting
for (double i = 0; i < pause_ms * 1000; i++) {
scan();
sleep_us(1);
}
}
void MatrixCore::play_column(int x) {
uint16_t note = 0;
for (int i = 0; i < 12; i++){
if (Board[x][i].state == 1) {
note = Board[x][i].note;
twelve_channel.play(i,note, 1);
}
}
sleep_ms(TEMPO); // check up on this
for (int i = 0; i <12; i++){
twelve_channel.turn_off(i);
}
}
// sends specified tile state to app
void MatrixCore::bluetooth_send_tile_state(int x, int y) {
char state_buffer[120] = "";
int write_count;
// set up our json string which sends the state information
write_count = sprintf(
state_buffer,
"{'row': %d, 'col': %d, 'color': %06x, 'state': %d}\n",
y, x,
Board[x][y].color,
Board[x][y].state
);
uart.disp(state_buffer);
}
// sends the state for each tile in the whole board
void MatrixCore::bluetooth_send_board_state() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 12; j++) {
bluetooth_send_tile_state(i, j);
}
}
}
// checks for a message string in the uart buffer
// this string tells us which button to toggle
void MatrixCore::bluetooth_scan() {
// use this to build our whole message we receive
char message[5] = "";
// keep track of how far in the message we are
int message_index = 0;
// are we currently reading a message
int reading = 0;
while (1) {
// read byte
char rdata = uart.rx_byte();
// a byte is available
if (rdata != -1) {
// for whatever reason data will not read properly if
// we do not wait for a second
usleep(750);
// start of message
if (rdata == 'S') {
reading = 1;
// end of message
} else if (rdata == 'E') {
reading = 0;
message[4] = '\n';
char str_x[] = {message[0], message[1], '\n'};
char str_y[] = {message[2], message[3], '\n'};
int x = 0;
int y = 0;
x = atoi(str_x);
y = atoi(str_y);
Board[x][y].state = !Board[x][y].state;
Board[x][y].color = 0x00FF00;
bluetooth_send_tile_state(x, y);
// clear message so the next will be clean
memset(message, 0, sizeof(message)/sizeof(message[0]));
message_index = 0;
// TODO: maybe call toggle here so we can handle multiple changes in a single call?
break;
// application just connected, send entire state of the board
} else if (rdata == 'L') {
bluetooth_send_board_state();
// potential message data, append if we are reading
} else {
// build the string
if (reading) {
message[message_index] = rdata;
message_index++;
}
}
// break out of the loop when there is nothing left
} else {
break;
}
}
}
The issue is, in the second line of the code, it is throwing an error saying that DdfsTone does not name a type. I am not sure how to fix this error. I have read that it could be a problem with a forward declaration, but I don't see how that could apply here. There is also the question of a circular dependency. That could be possible, but I don't quite understand what that means. For that reason, I am going to include the code for ddfs_tone.h. This is the file that declares the DdfsTone class.
/*
* ddfs_tone.h
*
* Created on: Nov 12, 2018
* Author: theod
*/
#ifndef APP_DRV_DDFS_TONE_H_
#define APP_DRV_DDFS_TONE_H_
#include "chu_init.h"
class DdfsTone {
public:
enum {
FCW_REG_CHANNEL1 = 0,
FCW_REG_CHANNEL2 = 1,
FCW_REG_CHANNEL3 = 2,
FCW_REG_CHANNEL4 = 3,
FCW_REG_CHANNEL5 = 4,
FCW_REG_CHANNEL6 = 5,
FCW_REG_CHANNEL7 = 6,
FCW_REG_CHANNEL8 = 7,
FCW_REG_CHANNEL9 = 8,
FCW_REG_CHANNEL10 = 9,
FCW_REG_CHANNEL11 = 10,
FCW_REG_CHANNEL12 = 11,
AMP_REG_CHANNEL1 = 0+12,
AMP_REG_CHANNEL2 = 1+12,
AMP_REG_CHANNEL3 = 2+12,
AMP_REG_CHANNEL4 = 3+12,
AMP_REG_CHANNEL5 = 4+12,
AMP_REG_CHANNEL6 = 5+12,
AMP_REG_CHANNEL7 = 6+12,
AMP_REG_CHANNEL8 = 7+12,
AMP_REG_CHANNEL9 = 8+12,
AMP_REG_CHANNEL10 = 9+12,
AMP_REG_CHANNEL11 = 10+12,
AMP_REG_CHANNEL12 = 11+12,
PHA_WIDTH = 30 /**< bits in ddfs phase register */
};
DdfsTone(uint32_t core_base_addr);
//~DdfsTone();
void init();
void play(int channel, uint32_t pitch, uint16_t velocity);
void turn_off(int channel);
int pitchtoM(uint8_t pitch);
uint32_t velocitytoAMP(uint16_t velocity);
void set_env(int ch,float env);
int getChannel(uint8_t cmd);
int getCommand(uint8_t cmd);
private:
uint32_t base_addr;
};
#endif /* APP_DRV_DDFS_TONE_H_ */
If you need more information, please comment and tell me what I should edit in. The main error is that, again, 'DdfsTone' does not name a type. Is there an error in my code for DdfsTone? Thanks in advance I love you.
User contributions licensed under CC BY-SA 3.0