error: (1098) conflicting declarations for variable "I2C1_Initialize()" in XC8 - mplab-x

void sensorConfig(void)
{
float buffer[SIZE];
char index = 0;
I2C1_Initialize();
I2C1_Open();
I2C1_MasterWrite(0xC7);
while(1)
{
for(index=0;index<SIZE;index++)
{
buffer[ index ] = I2C1_MasterRead(ACCEL_XOUT_H + index);
}
}
I2C1_Close();
}
void I2C1_Initialize()
{
SSP1STAT = 0x80;
SSP1CON1 = 0x08;
SSP1CON2 = 0x00;
SSP1ADD = 0x09;
SSP1CON1bits.SSPEN = 0;
}
error message:
main.c:118:: error: (1098) conflicting declarations for variable "_I2C1_Initialize" (mcc_generated_files/i2c1_master.c:167)
I am trying to establish a I2C connection between MPU6050 accelerometer and pic18f45k22

Related

Using RegisterHotKey with number pad values not working?

I have some constants:
constexpr int MonitorDisplay1 = 100;
constexpr int MonitorDisplay2 = 200;
constexpr int MonitorDisplay3 = 400;
constexpr int MonitorDisplay4 = 500;
constexpr int MonitorDisplay1KeyPad = 101;
constexpr int MonitorDisplay2KeyPad = 201;
constexpr int MonitorDisplay3KeyPad = 401;
constexpr int MonitorDisplay4KeyPad = 501;
I have an OnCreate where I setup the hot keys:
int CCenterCursorOnScreenDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (__super::OnCreate(lpCreateStruct) == -1)
return -1;
auto RegisterAppHotkey = [hAppWnd = GetSafeHwnd()](const int nHotKeyID, UINT vk)->bool
{
if (!::RegisterHotKey(hAppWnd, nHotKeyID, MOD_CONTROL | MOD_SHIFT, vk))
{
auto const ec = ::GetLastError();
auto const err_msg = std::format(L"RegisterHotKey failed (error: {})\n",
ec);
AfxMessageBox(err_msg.c_str());
return false;
}
return true;
};
if (m_monitors.rcMonitors.size() > 0)
{
if (!RegisterAppHotkey(MonitorDisplay1, '1'))
{
return -1;
}
if (!RegisterAppHotkey(MonitorDisplay1KeyPad, VK_NUMPAD1))
{
return -1;
}
}
if (m_monitors.rcMonitors.size() > 1)
{
if (!RegisterAppHotkey(MonitorDisplay2, '2'))
{
return -1;
}
if (!RegisterAppHotkey(MonitorDisplay2KeyPad, VK_NUMPAD2))
{
return -1;
}
}
if (m_monitors.rcMonitors.size() > 2)
{
if (!RegisterAppHotkey(MonitorDisplay3, '3'))
{
return -1;
}
if (!RegisterAppHotkey(MonitorDisplay3KeyPad, VK_NUMPAD3))
{
return -1;
}
}
if (m_monitors.rcMonitors.size() > 3)
{
if (!RegisterAppHotkey(MonitorDisplay4, '4'))
{
return -1;
}
if (!RegisterAppHotkey(MonitorDisplay4KeyPad, VK_NUMPAD4))
{
return -1;
}
}
return 0;
}
Previously I just had the 4 hotkeys for 1 / 2 / 3 and 4. They still work. I tried to add new hotkeys for for the number pad on the keyboard, but they are not working.
My OnHotKey handler:
void CCenterCursorOnScreenDlg::OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2)
{
if (nHotKeyId == MonitorDisplay1 || nHotKeyId == MonitorDisplay1KeyPad)
{
CenterCursorOnMonitor(0);
}
else if (nHotKeyId == MonitorDisplay2 || nHotKeyId == MonitorDisplay2KeyPad)
{
CenterCursorOnMonitor(1);
}
else if (nHotKeyId == MonitorDisplay3 || nHotKeyId == MonitorDisplay3KeyPad)
{
CenterCursorOnMonitor(2);
}
else if (nHotKeyId == MonitorDisplay4 || nHotKeyId == MonitorDisplay4KeyPad)
{
CenterCursorOnMonitor(3);
}
__super::OnHotKey(nHotKeyId, nKey1, nKey2);
}
But the number pad versions are not working. Why?
I am unregistering all 8 hotkeys, and num-lock is on. I get no warnings when registering.
This article explains List of Keys (Keyboard, Mouse and Joystick):
Because I was using CTRL + SHIFT, then the meaning of the 4 numeric keys was changing:
End
Down
Page Down
Left
It made sense to change my hotkeys to CTRL + ALT instead to avoid this issue.

How to send Dictionary datatype( a{ias} ) through gdbus?

I was trying to send different datatypes over dbus using gdbus. I am stuck at sending the following datatype : a{ias}. Does anyone send me a snippet or any ways to approach this problem?
I have got a snippet here,just replace the busname,path,interface,methodname in the below code.
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
GVariantBuilder* builder;
error = NULL;
**//Acquire bus connection**
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
NULL,
&error);
g_assert_no_error (error);
error = NULL;
**//Create proxy of remote object**
proxy= g_dbus_proxy_new_sync(connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo */
"org.busname", /* Services */
"/org/buspath", /* Path */
"org.interface", /* Interface */
NULL, /* GCancellable */
error);
GVariant *result;
GVariant *value;
GError *error;
error = NULL;
int i;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
**//Sending dictionary datatype start**
for (i = 0; i < 2; i++)
{
GVariantBuilder* builderAs = g_variant_builder_new(G_VARIANT_TYPE("as"));
for (int j = 0; j < 2; j++) {
g_variant_builder_add(builderAs, "s", "SomeString");
}
g_variant_builder_add(&builder, "{ias}",i,builderAs);
}
**//Sending dictionary end**
GVariant *v1 = g_variant_builder_end(&builder);
result = g_dbus_proxy_call_sync(proxy,
"MethodName",
g_variant_new_tuple(&v1, 1),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

arduino uno if string cotains a word

I very new to Arduino Uno and need some advice....so here we go.
I want to use my Arduino to:
1. read my serial data --received as plain text
2. look for a specific word within a line of data received
3. only transmit/print the complete string if it contains the specific "word"
I found this sketch and it works only if I'm looking for char
// Example 3 - Receive with start- and end-markers
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithStartEndMarkers();
showNewData();
}
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 showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
I think it is better to use String class methods.
you can get the Data using Serial.readString()
then use the String methods for looking for a specific word.
Here are some useful links
https://www.arduino.cc/en/Serial/ReadString
https://www.arduino.cc/en/Reference/StringObject

Arduino Error with Casting from string to float

In following code, I'm Trying to cast String value to float, but i get Following error."class String has no named toFloat".Error in following line " yaw = s.substring(5,s.indexOf(",",i)).toFloat();".
#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3);
String buff;
void setup() {
Serial.begin(115200);
softSerial.begin(19200);
}
void loop() {
if(softSerial.available()){
buff = "";
while(softSerial.available()){
char in = (char)softSerial.read();
buff += in;
}
Serial.println(buff);
parseData(buff);
}
if(Serial.available()){
while(Serial.available()){
softSerial.write(Serial.read());
}
}
}
void parseData(String s){
union byte2float{
byte bval[4];
float fval;
}
b2f;
float yaw;
float pitch;
float roll;
int i=0;
String temp;
//Check if ASCII or Binary (usually, binary output doesn't start with #)
if(s.substring(0,1)=="#"){
if(s.substring(1,4)=="YPR"){
Serial.println("Output is Text");
Serial.println(s.substring(5,s.indexOf(",",i)));
yaw = s.substring(5,s.indexOf(",",i)).toFloat();
i = 1 + s.indexOf(",",i) ;
Serial.println(s.substring(i,s.indexOf(",",i)));
pitch = s.substring(i,s.indexOf(",",i)).toFloat();
i = 1 + s.indexOf(",",i);
Serial.println(s.substring(i,s.indexOf(",",i)));
roll = s.substring(i,s.indexOf(",",i)).toFloat();
}
}
else{
// 1234 5678 9101112
Serial.println("Output is Binary: ");
byte b[13];
s.getBytes(b,13);
Serial.println("[#]\t[A]\t[B]\t[Ah]\t[Bh]");
for(int x=0;x<12;x++){
Serial.print("[");
Serial.print(x,DEC);
Serial.print("]\t");
Serial.print(s[x]);
Serial.print("\t");
Serial.print((char)b[x]);
Serial.print("\t");
Serial.print((byte)s[x],HEX);
Serial.print("\t");
Serial.println((byte)b[x],HEX);
}
b2f.bval[0] = b[0];
b2f.bval[1] = b[1];
b2f.bval[2] = b[2];
b2f.bval[3] = b[3];
yaw = b2f.fval;
b2f.bval[0] = b[4];
b2f.bval[1] = b[5];
b2f.bval[2] = b[6];
b2f.bval[3] = b[7];
pitch = b2f.fval;
b2f.bval[0] = b[8];
b2f.bval[1] = b[9];
b2f.bval[2] = b[10];
b2f.bval[3] = b[11];
roll = b2f.fval;
}
Serial.print("Yaw: ");
Serial.println(yaw);
Serial.print("Pitch: ");
Serial.println(pitch);
Serial.print("Roll: ");
Serial.println(roll);
}
Use for example
float(s.substring(5,s.indexOf(",",i)))
instead of
s.substring(5,s.indexOf(",",i)).toFloat()
The error message says, you were using the toFloat() method of a string, which does not exists. Instead, pass the string into the global function float(string).

WinCE: How can I determine the module that contains a code address?

I wrote a solution that involved OpenProcess, EnumProcessModules, GetModuleInformation and GetModuleBaseName, but apparently EnumProcessModules and GetModuleBaseName do not exist in Windows CE! What alternative is there?
I found a way to do this with CreateToolhelp32Snapshot, Module32First, Module32Next, Process32First and Process32Next. First you have to get a list of modules, then search through the list of modules to find the desired address.
#include <Tlhelp32.h>
struct MyModuleInfo
{
BYTE* Base;
HMODULE Handle;
DWORD Size;
enum { MaxNameLen = 36 };
TCHAR Name[MaxNameLen];
};
bool GetModuleList(vector<MyModuleInfo>& moduleList)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPMODULE | TH32CS_GETALLMODS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return false;
MODULEENTRY32 moduleInfo;
moduleInfo.dwSize = sizeof(moduleInfo);
if (Module32First(hSnapshot, &moduleInfo)) do {
MyModuleInfo myInfo;
myInfo.Handle = moduleInfo.hModule;
myInfo.Base = moduleInfo.modBaseAddr;
myInfo.Size = moduleInfo.modBaseSize;
memcpy(myInfo.Name, moduleInfo.szModule, min(sizeof(myInfo.Name), sizeof(moduleInfo.szModule)));
myInfo.Name[myInfo.MaxNameLen-1] = '\0';
moduleList.push_back(myInfo);
} while (Module32Next(hSnapshot, &moduleInfo));
// The module list obtained above only contains DLLs! To get the EXE files
// also, we must call Process32First and Process32Next in a loop.
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
if (Process32First(hSnapshot, &processInfo)) do {
MyModuleInfo myInfo;
myInfo.Handle = NULL; // No handle given
myInfo.Base = (BYTE*)processInfo.th32MemoryBase;
myInfo.Size = 0x800000; // No size provided! Allow max 8 MB
memcpy(myInfo.Name, processInfo.szExeFile, min(sizeof(myInfo.Name), sizeof(processInfo.szExeFile)));
myInfo.Name[myInfo.MaxNameLen-1] = '\0';
moduleList.push_back(myInfo);
} while(Process32Next(hSnapshot, &processInfo));
// Debug output
for (int i = 0; i < (int)moduleList.size(); i++) {
MyModuleInfo& m = moduleList[i];
TRACE(_T("%-30s: 0x%08x - 0x%08x\n"), m.Name, (DWORD)m.Base, (DWORD)m.Base + m.Size);
}
CloseToolhelp32Snapshot(hSnapshot);
return true;
}
const MyModuleInfo* GetModuleForAddress(vector<MyModuleInfo>& moduleList, void* address)
{
for (int m = 0; m < (int)moduleList.size(); m++) {
const MyModuleInfo& mInfo = moduleList[m];
if (address >= mInfo.Base && address < mInfo.Base + mInfo.Size)
return &mInfo;
}
return NULL;
}

Resources