aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/common/eeconfig.c
blob: 140d2b85bb9f2857af85bd57731459506e8dc0c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdint.h>
#include <stdbool.h>
#include "eeprom.h"
#include "eeconfig.h"

void eeconfig_init(void)
{
    eeprom_update_word(EECONFIG_MAGIC,          EECONFIG_MAGIC_NUMBER);
    eeprom_update_byte(EECONFIG_DEBUG,          0);
    eeprom_update_byte(EECONFIG_DEFAULT_LAYER,  0);
    eeprom_update_byte(EECONFIG_KEYMAP,         0);
    eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
#ifdef BACKLIGHT_ENABLE
    eeprom_update_byte(EECONFIG_BACKLIGHT,      0);
#endif
#ifdef AUDIO_ENABLE
    eeprom_update_byte(EECONFIG_AUDIO,             0xFF); // On by default
#endif
#ifdef RGBLIGHT_ENABLE
    eeprom_update_dword(EECONFIG_RGBLIGHT,      0);
#endif
}

void eeconfig_enable(void)
{
    eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
}

void eeconfig_disable(void)
{
    eeprom_update_word(EECONFIG_MAGIC, 0xFFFF);
}

bool eeconfig_is_enabled(void)
{
    return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
}

uint8_t eeconfig_read_debug(void)      { return eeprom_read_byte(EECONFIG_DEBUG); }
void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }

uint8_t eeconfig_read_default_layer(void)      { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }

uint8_t eeconfig_read_keymap(void)      { return eeprom_read_byte(EECONFIG_KEYMAP); }
void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }

#ifdef BACKLIGHT_ENABLE
uint8_t eeconfig_read_backlight(void)      { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
#endif

#ifdef AUDIO_ENABLE
uint8_t eeconfig_read_audio(void)      { return eeprom_read_byte(EECONFIG_AUDIO); }
void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
#endif
/span> - fclose(stdin); - } -#endif - // initialize client(s) - if ( ext_gSettings->mThreadMode == kMode_Client ) { - client_init( ext_gSettings ); - } - -#ifdef HAVE_THREAD - // start up the reporter and client(s) or listener - { - thread_Settings *into = NULL; - // Create the settings structure for the reporter thread - Settings_Copy( ext_gSettings, &into ); - into->mThreadMode = kMode_Reporter; - - // Have the reporter launch the client or listener - into->runNow = ext_gSettings; - - // Start all the threads that are ready to go - thread_start( into ); - } -#else - // No need to make a reporter thread because we don't have threads - thread_start( ext_gSettings ); -#endif - } else { + if ((ext_gSettings->mThreadMode != kMode_Client) && (ext_gSettings->mThreadMode != kMode_Listener)) { // neither server nor client mode was specified // print usage and exit @@ -236,20 +176,75 @@ int main( int argc, char **argv ) { // Starting in 2.0 to restart a previously defined service // you must call iperf with "iperf -D" or using the environment variable SERVICE_TABLE_ENTRY dispatchTable[] = - { - { (LPSTR)TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main}, - { NULL, NULL} - }; + { + { (LPSTR)TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main}, + { NULL, NULL} + }; // starting the service by SCM, there is no arguments will be passed in. // the arguments will pass into Service_Main entry. if (!StartServiceCtrlDispatcher(dispatchTable) ) // If the service failed to start then print usage #endif - fprintf( stderr, usage_short, argv[0], argv[0] ); + fprintf( stderr, usage_short, argv[0], argv[0] ); + return 0; + } + + + switch (ext_gSettings->mThreadMode) { + case kMode_Client : + if ( isDaemon( ext_gSettings ) ) { + fprintf(stderr, "Iperf client cannot be run as a daemon\n"); + return 0; + } + // initialize client(s) + client_init( ext_gSettings ); + break; + case kMode_Listener : + if ( isDaemon( ext_gSettings ) ) { + fprintf( stderr, "Running Iperf Server as a daemon\n"); + // Start the server as a daemon +#ifdef WIN32 + CmdInstallService(argc, argv); + // Remove the Windows service if requested + if ( isRemoveService( ext_gSettings ) ) { + // remove the service + if ( CmdRemoveService() ) { + fprintf(stderr, "IPerf Service is removed.\n"); + return 0; + } + } +#else + fflush(stderr); + // redirect stdin, stdout and sterr to /dev/null (see dameon and no close flag) + if (daemon(1, 0) < 0) { + perror("daemon"); + } + } +#endif + break; + default : + fprintf( stderr, "unknown mode"); + break; + } +#ifdef HAVE_THREAD + // start up the reporter and client(s) or listener + { + thread_Settings *into = NULL; + // Create the settings structure for the reporter thread + Settings_Copy( ext_gSettings, &into ); + into->mThreadMode = kMode_Reporter; + + // Have the reporter launch the client or listener + into->runNow = ext_gSettings; - return 0; + // Start all the threads that are ready to go + thread_start( into ); } +#else + // No need to make a reporter thread because we don't have threads + thread_start( ext_gSettings ); +#endif // wait for other (client, server) threads to complete thread_joinall();