Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2105 - 1
#include "main.h"
2
#include "file.h"
3
 
4
int MaxAxisValue;
5
u8 GamepadLayout[30];
6
u8 FileExists;
7
 
8
const char* LablesOfAxis[NUMBER_OF_AXES_USED] =
9
{
10
    "camNick:",     //  GamepadLayout Position [0]      Nick-Axis of Camera-Gimbal
11
    "camRoll:",     //  GamepadLayout Position [1]      Roll-Axis of Camera-Gimbal
12
    "camGier:",     //  GamepadLayout Positoin [2]      Yaw (Gier)-Axis of MikroKopter (for Camera Control)
13
    "camZoom:",     //  GamepadLayout Position [3]      Camera-Zoom
14
    //"extNick:",     //  GamepadLayout Position [4]      Nick-Axis of MikroKopter          //Comment out for Cam Control only
15
    //"extRoll:",     //  GamepadLayout Position [5]      Roll-Axis of MikroKopter
16
    //"extGier:",     //  GamepadLayout Position [6]      Yaw(Gier)-Axis of MikroKopter
17
    //"extGas:"       //  GamepadLayout Position [7]      Gas of MikroKopter
18
};
19
const char* LablesOfButtons[NUMBER_OF_BUTTONS_USED] =
20
{
21
    "startRecord:", //  GamepadLayout Position [8]      Start Recording Camcorder
22
    "stopRecord:",  //  GamepadLayout Position [9]      Stop Recording Camcorder
23
    "trigger:",     //  GamepadLayout Position [10]      Trigger a Camera
24
    //"programOne:",  //  GamepadLayout Position [11]     Program 1: Remote Control Camera      //Comment out for Cam Control only
25
    //"programTwo:",  //  GamepadLayout Position [12]     Program 2: Remote Control MikroKopter
26
    //"motorStart:",  //  GamepadLayout Position [13]     Start Motors
27
    //"motorStop:",   //  GamepadLayout Position [14]     Stop Motors
28
    //"sensPlus:",    //  GamepadLayout Position [15]     Increase sensitivity of the controls
29
    //"sensMinus:",   //  GamepadLayout Position [16]     Decrease sensitivity of the controls
30
    //"activate:"     //  GamepadLayout Position [17]     Activate the controls
31
};
32
 
33
//>> Reading or creating configuration file
34
//------------------------------------------------------------------------------------------------------
35
int file_init(){
36
    char line[50];
37
    FILE *fp = fopen("/home/pi/PiMoteSwitch/configf.txt","r");
38
    if(fp)
39
    {
40
        while( fgets(line,50,fp) ) {
41
                for (int i = 0; i < NUMBER_OF_AXES_USED; i++)
42
                {
43
                        if(strstr(line, LablesOfAxis[i]) != NULL){
44
                                char *token = strtok(line, " ");
45
                                token = strtok(NULL, " ");
46
                                GamepadLayout[i] = token[0] - '0';
47
                        }
48
                }
49
                for (int i = 0; i < NUMBER_OF_BUTTONS_USED; i++)
50
                {
51
                        if(strstr(line, LablesOfButtons[i]) != NULL){
52
                                char *token = strtok(line, " ");
53
                                token = strtok(NULL, " ");
54
                                GamepadLayout[i + NUMBER_OF_AXES_USED] = token[0] - '0';
55
                        }
56
                }
57
            if(strstr(line, "MaxAxisValue") != NULL){
58
                char *token = strtok(line, " ");
59
                token = strtok(NULL, " ");
60
                MaxAxisValue = strtol(token, (char **)NULL, 10);
61
            }
62
                memset(line, 0, 49);
63
        }
64
        fclose(fp);
65
        return(1);
66
    }
67
    return(0);
68
}
69
 
70
//>> Write new configuration to file
71
//------------------------------------------------------------------------------------------------------
72
void write_file(void){
73
    FILE *fp = fopen("/home/pi/PiMoteSwitch/configf.txt","w+");
74
    fprintf(fp, "#Gamepad Configuration File\r\n\n");
75
    fprintf(fp, "#layout\r\n\n");
76
    for (int i = 0; i < NUMBER_OF_AXES_USED; i++){fprintf(fp, "%s %d\r\n", LablesOfAxis[i], GamepadLayout[i]);}
77
    for (int i = 0; i < NUMBER_OF_BUTTONS_USED; i++){fprintf(fp, "%s %d\r\n", LablesOfButtons[i], GamepadLayout[i + NUMBER_OF_AXES_USED]);}
78
    fprintf(fp, "\n#Max value of axis\r\n\nMaxAxisValue: ");
79
    fprintf(fp, "%d", MaxAxisValue);
80
    fclose(fp);
81
}