Controllare la batteria del proprio portatile con le funzioni esterne di SDL2
Da Gambas-it.org - Wikipedia.
Versione del 4 giu 2024 alle 08:47 di Vuott (Discussione | contributi)
Per controllare lo stato della batteria del proprio portatile con le funzioni esterne di SDL2, è necessario avere installata nel proprio sistema la libreria condivisa: "libSDL2-2.0.so.0.3000.3 ".
Si può adottare il seguente codice:
Library "libSDL2-2.0:0.3000.3" Private Enum SDL_POWERSTATE_UNKNOWN = 0, SDL_POWERSTATE_ON_BATTERY, SDL_POWERSTATE_NO_BATTERY, SDL_POWERSTATE_CHARGING, SDL_POWERSTATE_CHARGED ' int SDL_Init(Uint32 flags) ' Initializes the SDL library. Private Extern SDL_Init(flags As Integer) As Integer ' SDL_PowerState SDL_GetPowerInfo(int* secs, int* pct) ' Gets the current power supply details. Private Extern SDL_GetPowerInfo(secs As Pointer, pct As Pointer) As Integer ' void SDL_Quit(void) ' Clean up all initialized subsystems. Private Extern SDL_Quit() Public Sub Main() Dim seconds, percent, status As Integer Dim s As String SDL_Init(0) status = SDL_GetPowerInfo(VarPtr(seconds), VarPtr(percent)) Select Case status Case SDL_POWERSTATE_UNKNOWN s = "Sconosciuto" Case SDL_POWERSTATE_ON_BATTERY s = "presente" Case SDL_POWERSTATE_NO_BATTERY s = "Batteria inesistente" Case SDL_POWERSTATE_CHARGING s = "in carica" Case SDL_POWERSTATE_CHARGED s = "caricata" Case Else Error.Raise("Errore !") End Select Print "Stato della batteria: "; s If percent = -1 Then Print "Percentuale restante: sconosciuta" Else Print "Percentuale restante: "; percent; "%" Endif If seconds = -1 Then Print "Tempo rimanente: sconosciuto" Else Print "Tempo rimanente: "; CStr(Time(0, 0, 0, seconds * 1000)) Endif SDL_Quit() End