PaulS:
static inline void BicycleComputer::trigger_hallsensor()
{
count++;
distance += ((double)BC_TIRE_CIRC)/1000000.0;
}
Why are you trying to inline this?
You need to post ALL of your code. I'm suspecting that you are calling a function that isn't really a function. It's a macro whose expansion is wreaking havoc on your code.
Yeah sorry about that it was originally only count++;
I changed parts of the code, here is all of my updated code:
Test_nextion.h:
#include "DF_Player.h"
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
boolean newData = false;
//============
void setup() {
Serial.begin(9600);
delay(30);
Serial.print("baud=19200");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.flush(); // wait for last transmitted data to be sent
Serial.begin(19200);
while(Serial.available()) {Serial.read();}
}
//============
void loop() {
recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData(tempChars);
newData = false;
}
}
//============
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
//============
void parseData(char * temp_string) {
if(temp_string[0] == 'S')
{
switch(temp_string[1])
{
case 1:
DF_playfile(1,2);
break;
case 2:
DF_playfile(1,3);
break;
case 3:
DF_playfile(1,4);
break;
}
// char * strtokIndx; // this is used by strtok() as an index
// strtokIndx = strtok(strtokIndx, ""); // this continues where the previous call left off
// integerFromPC = atoi(strtokIndx); // convert this part to an integer
// //strtokIndx = strtok(NULL, "Y");
// strtokIndx = strtok(NULL,"");
// floatFromPC = atoi(strtokIndx); // convert this part to a float
}
}
DF_player.h:
#ifndef DF_PLAYER_H
#define DF_PLAYER_H
#define DF_startup_volume 15
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
#define c_play_file 0x0F
#define c_set_volume 0x06
#define c_stop_track 0x16
#define c_play 0x0D
#define c_pause 0x0E
#define c_setvolume 0x06
#define c_initialize 0x3F
#define c_repeat_track 0x08
#define c_stop 0x16
#define c_equalizer 0x07
void setup_DF();
void DF_initialize();
void DF_playfile(byte folder_num, byte file_num);
void DF_repeat(byte track_number);
void DF_pause();
void DF_stop();
void DF_play();
void DF_setVolume(int vol);
void DF_execute_CMD(byte CMD, byte Par1, byte Par2);
#endif
DF_player.cpp:
#include <Arduino.h>
#include "DF_Player.h"
void setup_DF()
{
Serial.begin(9600);
DF_initialize();
DF_setVolume(DF_startup_volume);
DF_playfile(1,1);
}
void DF_initialize()
{
DF_execute_CMD(c_initialize, 0, 0);
delay(30);
}
void DF_playfile(byte folder_num, byte file_num)
{
DF_execute_CMD(c_play_file,folder_num,file_num);
delay(30);
}
void DF_repeat(byte track_number)
{
DF_execute_CMD(c_repeat_track,0,track_number);
}
void DF_pause()
{
DF_execute_CMD(c_pause,0,0);
delay(30);
}
void DF_stop()
{
DF_execute_CMD(c_stop,0,0);
}
void DF_play()
{
DF_execute_CMD(c_play,0,1);
delay(30);
}
void DF_setVolume(int vol)
{
DF_execute_CMD(c_setvolume, 0, vol); // Set the volume (0x00~0x30)
delay(30);
}
void DF_execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
Serial.write(Command_line[k]);
}
}
Timing.h
#ifndef TIMING_H
#define TIMING_H
#include <Arduino.h>
bool wait(unsigned long& prev_time, unsigned long const interval);
#endif
Timing.cpp
#include "Timing.h"
bool wait(unsigned long& prev_time, unsigned long const interval) {
unsigned long now = millis();
if(now - prev_time >= interval) {
prev_time = now;
return true;
}
return false;
}
setup_Pins.h
#ifndef SETUP_PINS_H
#define SETUP_PINS_H
#include <Arduino.h>
#define HallSensorPin 2
void setup_pins()
#endif
setup_Pins.cpp
#include "setup_Pins.h"
#include "Bicycle_Computer.h"
void setup_pins()
{
attachInterrupt(digitalPinToInterrupt(HallSensorPin), BicycleComputer::trigger_hallsensor, FALLING);
}
Bicycle_Computer.h
#ifndef BICYCLE_COMPUTER_H
#define BICYCLE_COMPUTER_H
#include "Timing.h"
#include <Arduino.h>
//#define BC_TIRE_CIRC 2110
#define BC_MEASURE_INTERVAL 3000
#define BC_RESET_COUNT_INTERVAL 1000
class BicycleComputer
{
static byte count;
unsigned int tire_circ;
static double tire_circ_km;
public:
static double speed;
static double distance;
static void trigger_hallsensor();
bool reset_count();
void measure_speed();
void set_tire_circ(unsigned int tire_circum);
};
#endif
Bicycle_Computer.cpp
#include "Bicycle_Computer.h"
#include "Timing.h"
static void BicycleComputer::trigger_hallsensor()
{
count++;
distance += tire_circ_km;
}
bool BicycleComputer::reset_count()
{
static unsigned long prev_time = millis();
if(wait(prev_time, BC_RESET_COUNT_INTERVAL) and count>0)
{
count--;
}
}
void BicycleComputer::measure_speed()
{
static unsigned long prev_time = millis();
unsigned long now = millis();
unsigned long delta_time = now - prev_time;
if(delta_time >= BC_MEASURE_INTERVAL)
{
prev_time = now;
speed = double(tire_circ) / double(delta_time) * 3.6 * double(count);
}
}
void BicycleComputer::set_tire_circ(unsigned int tire_circum)
{
tire_circ = tire_circum;
tire_circ_km = double(tire_circum)/1000000.0;
}
New error message:
In file included from /tmp/483754499/build/sketch/Bicycle_Computer.h:4:0,
from /tmp/483754499/build/sketch/setup_Pins.cpp:2:
/tmp/483754499/build/sketch/Timing.h:6:1: error: expected initializer before 'bool'
bool wait(unsigned long& prev_time, unsigned long const interval);
^
exit status 1
christop:
How is BC_RESET_COUNT_INTERVAL
defined?
Yeah sorry my bad, I defined it in my updated code above.